/********************************************************* Alexis C. Montenegro © January 2006 Use and/or modify this code freely. If you redistribute it please include this and/or any other comment blocks and a description of any changes you make. **********************************************************/ var fpArray = new Array(); function preMain() { setPriceStudy(false); setStudyTitle("Chaikin Money Flow"); setCursorLabelName("CMF"); setDefaultBarFgColor(Color.blue); setDefaultBarThickness(1); setPlotType(PLOTTYPE_LINE); var x=0; fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER); with(fpArray[x++]){ setLowerLimit(1); setDefault(21); } fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING); with(fpArray[x++]){ setDefault(); } fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING); with(fpArray[x++]){ setDefault(); } fpArray[x] = new FunctionParameter("Hist", FunctionParameter.BOOLEAN); with(fpArray[x++]){ setName("Plot as Histogram"); setDefault(false); } fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN); with(fpArray[x++]){ setName("Show Parameters"); setDefault(false); } } var bInit = false; var xCMF = null; function main(Length,Symbol,Interval,Hist,Params) { if(bInit == false){ if(Symbol == null) Symbol = getSymbol(); if(Interval == null) Interval = getInterval(); var vSymbol = Symbol+","+Interval; xCMF = getSeries(efsInternal("calcCMF",Length,(sym(vSymbol)))); if(Hist == true) setPlotType(PLOTTYPE_HISTOGRAM); addBand(0, PS_SOLID, 1, Color.black,"0"); setShowTitleParameters(eval(Params)); bInit = true; } return xCMF; } var xInit = false; var xClose = null; var xHigh = null; var xLow = null; var xVol = null; function calcCMF(length,source){ if(xInit == false){ xClose = close(); xHigh = high(); xLow = low(); xVol = volume(); xInit = true; } if(getCurrentBarCount() 0) { Sum += (((xClose.getValue(-i)-xLow.getValue(-i))-(xHigh.getValue(-i)-xClose.getValue(-i)))/(xHigh.getValue(-i)-xLow.getValue(-i)))*xVol.getValue(-i); } SumVol += xVol.getValue(-i); } if(SumVol==0) return; return (Sum/SumVol); }