hallo,
which formel does eSignal use to calculate MACD, and the MACD Signal line?
thanks,
alen
which formel does eSignal use to calculate MACD, and the MACD Signal line?
thanks,
alen
var MACD = null
var SIG = null;
function main(){
if(MACD==null) MACD = efsInternal("calcMACD",12,26,close());//creates a series of the MACD
if(SIG==null) SIG = efsInternal("calcEMA",9,MACD);//uses MACD series as input to calcEMA function
if(MACD.getValue(0)==null||SIG.getValue(0)==null) return;
return new Array (MACD.getValue(0),SIG.getValue(0));
}
var xAvg1 = null;
var xAvg2 = null;
//this section calculates the MACD (ie the difference between the exponential averages)
function calcMACD(Length1,Length2,Source) {
if(xAvg1 == null) xAvg1 = efsInternal("calcEMA",Length1,Source);
if(xAvg2 == null) xAvg2 = efsInternal("calcEMA",Length2,Source);
if(xAvg1.getValue(0)==null||xAvg2.getValue(0)==null) return;
var xMACD = xAvg1.getValue(0)-xAvg2.getValue(0)
return xMACD;
}
//this section calculates the exponential moving averages used by the MACD
//and Signal lines
var dThisMA = null;
var dLastMA = null;
var dPercent = 0.0;
var bPrimed = false;
function calcEMA(nInputlength,source) {
var nBarState = getBarState();
var dSum = 0.0;
if(nBarState == BARSTATE_ALLBARS) {
dPercent = (2.0/(nInputlength+1.0));
bPrimed = false;
}
if(nBarState == BARSTATE_NEWBAR) {
dLastMA = dThisMA;
}
if(bPrimed == false) {
for(var i=0; i<nInputlength; i++) {
if(getCurrentBarCount()<nInputlength) return;
dSum += source.getValue(-i);
}
bPrimed = true;
dThisMA = dSum/nInputlength;
} else {
dThisMA = ((source.getValue(0)-dLastMA)*dPercent)+dLastMA;
}
return dThisMA;
}
Comment