Hello,
I am trying to create the Chaikin Money Flow Percent Oscillator. It is not the Chaikin oscillator which is the MACD of Accumulation/Distribution indicator.
Below is the standard Accumulation/Distribution formula and I need help with the last line of code ( CMF = (90 day SUM OF dSum / 90 DAY SUM OF dvolume)
The CMF is a 90 sum of the Accumulation Distribution/ 90 day sum of the instruments volume.
Can some help?
function preMain() {
setStudyTitle("Accumulation/Distribution");
setCursorLabelName("AccDist");
}
// these variables stay "alive" between calls to main()
var dLastSum = 0.0;
var dSum = 0.0;
function main() {
var nBarState = getBarState();
if(nBarState == BARSTATE_ALLBARS) {
dLastSum = 0.0;
dSum = 0.0;
}
var dClose = close(0);
var dLow = low(0);
var dHigh = high(0);
var dVolume = volume(0);
if(dClose == null || dLow == null || dHigh == null || dVolume == null) {
return;
}
// if a new bar is about to be built, remember
// the last sum (OBV is an accumulative indicator)
if(nBarState == BARSTATE_NEWBAR) {
dLastSum = dSum;
}
// restore sum to previous value.
dSum = dLastSum;
if( (dClose == dLow && dClose == dHigh) || dHigh == dLow) {
// do nothing
} else {
dSum += (((dClose-dLow)-(dHigh-dClose))/(dHigh-dLow))*dVolume;
}
} else {
CMF = (90 day SUM OF dSum / 90 DAY SUM OF dvolume;
}
I am trying to create the Chaikin Money Flow Percent Oscillator. It is not the Chaikin oscillator which is the MACD of Accumulation/Distribution indicator.
Below is the standard Accumulation/Distribution formula and I need help with the last line of code ( CMF = (90 day SUM OF dSum / 90 DAY SUM OF dvolume)
The CMF is a 90 sum of the Accumulation Distribution/ 90 day sum of the instruments volume.
Can some help?
function preMain() {
setStudyTitle("Accumulation/Distribution");
setCursorLabelName("AccDist");
}
// these variables stay "alive" between calls to main()
var dLastSum = 0.0;
var dSum = 0.0;
function main() {
var nBarState = getBarState();
if(nBarState == BARSTATE_ALLBARS) {
dLastSum = 0.0;
dSum = 0.0;
}
var dClose = close(0);
var dLow = low(0);
var dHigh = high(0);
var dVolume = volume(0);
if(dClose == null || dLow == null || dHigh == null || dVolume == null) {
return;
}
// if a new bar is about to be built, remember
// the last sum (OBV is an accumulative indicator)
if(nBarState == BARSTATE_NEWBAR) {
dLastSum = dSum;
}
// restore sum to previous value.
dSum = dLastSum;
if( (dClose == dLow && dClose == dHigh) || dHigh == dLow) {
// do nothing
} else {
dSum += (((dClose-dLow)-(dHigh-dClose))/(dHigh-dLow))*dVolume;
}
} else {
CMF = (90 day SUM OF dSum / 90 DAY SUM OF dvolume;
}
Comment