Hello,
I added some function parameters to this EFS and would like to be able to use high + low + (2*close)/4 as one of the sources for the CCI, if not the only choice, but I don't seem to be able to get it to work, it comes up blank.
Also when I try to add direction color to the line it goes blank as well.
Any help would be greatly appreciated.
I added some function parameters to this EFS and would like to be able to use high + low + (2*close)/4 as one of the sources for the CCI, if not the only choice, but I don't seem to be able to get it to work, it comes up blank.
Also when I try to add direction color to the line it goes blank as well.
Any help would be greatly appreciated.
PHP Code:
/*********************************************************
By Alexis C. Montenegro December 2004
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("CCI adj");
setCursorLabelName("CCI adj", 0);
setDefaultBarFgColor(Color.yellow, 0);
setPlotType(PLOTTYPE_LINE,0);
setDefaultBarThickness(1,0);
setStudyMin(-220);
setStudyMax(220);
addBand(200, PS_DOT, 2, Color.grey,"200");
addBand(100, PS_DOT, 2, Color.green,"100");
addBand(0, PS_DASH, 2, Color.grey,"zero");
addBand(-100, PS_DOT, 2, Color.green,"-100");
addBand(-200, PS_DOT, 2, Color.grey,"-200");
askForInput();
var x=0;
fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(20);
}
fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("open");
addOption("high");
addOption("low");
addOption("close");
addOption("hl2");
addOption("hlc3");
addOption("ohlc4");
//Is there any way to add HLCC option here ?
//addOption("hlcc4");
setDefault("hlc3");
}
fpArray[x] = new FunctionParameter("Type", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("sma");
addOption("ema");
addOption("wma");
addOption("vwma");
setDefault("sma");
}
fpArray[x] = new FunctionParameter("Multiplier", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(0.001);
setDefault(0.015);
}
}
var bInit = false;
var xPrice = null;
var xAvgPrice = null;
var xMulti = null;
var xCCI = null;
//var xHLCC = null;
function main(Length, Source, Type, Multiplier){
if(bInit == false){
//Tried to add new source here
//xHLCC = (high(0)+low(0)+(2*close(0)))/4;
//xPrice = xHLCC;
xPrice = eval(Source)();
xAvgPrice = eval(Type)(Length,xPrice);
xMulti = Multiplier;
bInit = true;
}
if(xPrice.getValue(-Length)==null||xAvgPrice.getValue(-Length)==null) return;
var Sum = 0;
for (var i=0; i<Length; i++){
Sum += Math.abs(xPrice.getValue(-i)-xAvgPrice.getValue(0));
}
var MeanDevPrice = Sum/Length;
var xCCI = (xPrice.getValue(0)-xAvgPrice.getValue(0))/(MeanDevPrice*xMulti);
//CCI color change with direction change
/*if(xCCI.getValue(0) > xCCI.getValue(-1)) {
setBarFgColor(Color.green,0);
} else setBarFgColor (Color.red,0);*/
return xCCI;
}
Comment