Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
MACD calculator. Not a standalone Java program but some Java code as good as pseudocode.
import java.util.ArrayList;
public class MACDCalculator extends SimpleCalculator {
private float ema1alpha;
private float ema2alpha;
private float signalalpha;
private float[] pema1;
private float[] pema2;
private float[] psignal;
MACDCalculator(ArrayList<Float> args) {
this.ema1alpha = args.get(0);
this.ema2alpha = args.get(1);
this.signalalpha = args.get(2);
this.pema1 = null;
this.pema2 = null;
this.psignal = null;
}
@Override
public float[] calculate(float[] values) {
float[] res;
if (this.pema1 == null){
this.pema1 = values.clone();
this.pema2 = values.clone();
this.psignal = values.clone();
res = values.clone();
}
else{
res = new float[values.length];
for (int i = 0; i < values.length; i++){
this.pema1[i] = this.ema1alpha * values[i] + (1-this.ema1alpha) * this.pema1[i];
this.pema2[i] = this.ema2alpha * values[i] + (1-this.ema2alpha) * this.pema2[i];
this.psignal[i] = this.signalalpha * (this.pema1[i]-this.pema2[i]) + (1-this.signalalpha) * this.psignal[i];
res[i] = this.pema1[i] - this.pema2[i] - this.psignal[i];
}
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.