Hi,
I am looking to explore modifying the CCI indicator. Can someone help me with the actual code of the CCI.
Here is the actual formula but I don’t know how turn this into code.
CCI=.015×Mean DeviationTypical Price−MA
where:
Typical Price=∑i=1P((High+Low+Close)÷3)
P=Number of periods
MA=Moving AverageMoving Average=(∑i=1PTypical Price)÷P
Mean Deviation=(∑i=1P∣Typical Price−MA∣)÷P
Can anyone help me with this?
TIA
Hi, here you have the code:
// Calculation of Typical Price
// typicalPrice = (High + Low + Close) / 3
// Parameter for the number of periods
periods = 20 // You can change this value according to your needs
// Calculation of the Moving Average
MA = Average[periods](typicalPrice)
// Calculation of the Mean Deviation
sumDeviation = 0
FOR i = 0 TO periods - 1 DO
sumDeviation = sumDeviation + Abs(typicalPrice[i] - MA)
NEXT
meanDeviation = sumDeviation / periods
// Calculation of the CCI
myCCI = (typicalPrice - MA) / (0.015 * meanDeviation)
// Return the value of the CCI
RETURN myCCI AS "CCI"