Hi,
The following code doesn't work.
What I'm trying to do is build a CCI that is different then the standard one "CCI(14,hlc3())", As a first step I want to duplicate the standard one. So first I have a series for the SMA Typical Price (SMATP) using "high(0) + low(0) + close(0))/3" for the Typical Price (TP), which works fine.
Then I want to caculate the Moving Deviation (MD) which is the SMA of the absolute value of the difference of the last SMATP and past N (in this case 14) TPs. I used the code example for esfInternal which works fine using close() or hlc3() to build the MD, but it doesn't work. Maybe I should just code it up using arrays, but I wanted to try using series (would it be better to use arrays?).
Any help would be greatly appreciated.
Thanks Tom
The following code doesn't work.
What I'm trying to do is build a CCI that is different then the standard one "CCI(14,hlc3())", As a first step I want to duplicate the standard one. So first I have a series for the SMA Typical Price (SMATP) using "high(0) + low(0) + close(0))/3" for the Typical Price (TP), which works fine.
Then I want to caculate the Moving Deviation (MD) which is the SMA of the absolute value of the difference of the last SMATP and past N (in this case 14) TPs. I used the code example for esfInternal which works fine using close() or hlc3() to build the MD, but it doesn't work. Maybe I should just code it up using arrays, but I wanted to try using series (would it be better to use arrays?).
Any help would be greatly appreciated.
Thanks Tom
PHP Code:
function preMain() {
setPriceStudy(false);
setStudyTitle("CCI");
setCursorLabelName("CCI",0);
setDefaultBarFgColor(Color.blue,0);
setDefaultBarThickness(2,0);
}
// global vars for Series Objects
var tpSeries = null;
var MY_tpSMA = null;
var bInit = false; // initialization flag
function main() {
// initialize Series objects, occurs only once.
if (bInit == false) {
tpSeries = efsInternal("Typical_Price");
tpSMA = sma(14, tpSeries);
bInit = true;
}
// assign current value of Series to local vars for conditions
MY_tpSMA = tpSeries.getValue(0 );
myMD = sma(14,efsInternal("Moving_Deviation",tpSMA,1,tpSeries()));
return MY_tpSMA ;
}
function Typical_Price() {
return (high(0) + low(0) + close(0))/3;
}
function Moving_Deviation(tp,length,tpseries) {
MD = Math.abs(tp - tpseries.getvalue(-length));
return MD;
}
Comment