I am trying to produce a smoothed CCI (called MACCI) which uses hlc3 as it's data instead of Close.
I have taken the CCI efs code from the Library and modified it, but the plot is clearly wrong when compared to the CCI it is smoothing, and it doesn't extend up to the current bar or plot the +/- 100 Bands.
(I also tried using the EFS Wizard. It generated code but wouldn't plot anything and anyway I assume it's based on Close rather than hlc3)
Basically it's a 9 Sma of a 20 CCI using hlc3.
Can anyone help to identify where I have gone wrong please ?
Here is the code:-
function preMain() {
setPriceStudy(false);
setStudyTitle("MACCI");
setCursorLabelName("MACCI", 0);
setDefaultBarFgColor(Color.blue, 0);
setPlotType(PLOTTYPE_LINE,0);
setDefaultBarThickness(1,0);
addBand(100, PS_SOLID, 1, Color.black,"Upper");
addBand(-100, PS_SOLID, 1, Color.black,"Lower");
}
var xPrice = null;
var xAvgPrice = null;
function main(Length){
if(Length==null) Length = 20;
if(xPrice==null) xPrice = hlc3();
if(xAvgPrice==null) xAvgPrice = sma(Length,xPrice);
if(xPrice.getValue(-Length)==null||xAvgPrice.getValue(-Length)==null) return;
var Sum = 0;
for (i=0; i<Length; i++){
Sum += Math.abs(xPrice.getValue(-i)-xAvgPrice.getValue(0));
}
var MeanDevPrice = Sum/Length;
var CCI = (xPrice.getValue(0)-xAvgPrice.getValue(0))/(MeanDevPrice*0.015);
var MACCI = sma(9,CCI);
return MACCI;
}
Thanks for any advice.
tgmjf
I have taken the CCI efs code from the Library and modified it, but the plot is clearly wrong when compared to the CCI it is smoothing, and it doesn't extend up to the current bar or plot the +/- 100 Bands.
(I also tried using the EFS Wizard. It generated code but wouldn't plot anything and anyway I assume it's based on Close rather than hlc3)
Basically it's a 9 Sma of a 20 CCI using hlc3.
Can anyone help to identify where I have gone wrong please ?
Here is the code:-
function preMain() {
setPriceStudy(false);
setStudyTitle("MACCI");
setCursorLabelName("MACCI", 0);
setDefaultBarFgColor(Color.blue, 0);
setPlotType(PLOTTYPE_LINE,0);
setDefaultBarThickness(1,0);
addBand(100, PS_SOLID, 1, Color.black,"Upper");
addBand(-100, PS_SOLID, 1, Color.black,"Lower");
}
var xPrice = null;
var xAvgPrice = null;
function main(Length){
if(Length==null) Length = 20;
if(xPrice==null) xPrice = hlc3();
if(xAvgPrice==null) xAvgPrice = sma(Length,xPrice);
if(xPrice.getValue(-Length)==null||xAvgPrice.getValue(-Length)==null) return;
var Sum = 0;
for (i=0; i<Length; i++){
Sum += Math.abs(xPrice.getValue(-i)-xAvgPrice.getValue(0));
}
var MeanDevPrice = Sum/Length;
var CCI = (xPrice.getValue(0)-xAvgPrice.getValue(0))/(MeanDevPrice*0.015);
var MACCI = sma(9,CCI);
return MACCI;
}
Thanks for any advice.
tgmjf
Comment