Return the value of the CCI technical indicator “Commodity Channel Index”.
Syntax:
1 2 3 |
CCI[N](price) or CCI[N] |
Calculation :
CCI calculates the distance between a price and its average over x days divided by 1.5% of the mean absolute deviation.
CCI = (Price – MM) / (0.015*D)
Where :
Price (Typical Price by default, but can be any Price type) = (H+L+C) / 3
MM = moving average on M with n days
D = standard deviation on the moving average
Interpretation :
CCI is a speedometer of the market which gives indications of an overbought condition (>100) or an oversold condition (<-100) as well as indications of divergence with prices.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
myCCI = CCI[20](close) SIGNAL = 0 IF myCCI < -100 THEN SIGNAL = -1 ENDIF IF myCCI > 100 THEN SIGNAL = 1 ENDIF RETURN SIGNAL |
tiny bug
read “…or an oversold condition (<-100) …"
Thank you! I corrected it.
Hi, I try to recalculate this indicator to fully understand it, and I don’t have the same result than the original one. Can someone tell me where my mistake is please ?
// periods = 20
sma = Average[periods](TypicalPrice)
deviation = ABS(TypicalPrice – sma)
meanAbsoluteDeviation = SUMMATION[periods](deviation) / periods
return (TypicalPrice – sma) / (0.015 * meanAbsoluteDeviation)
You are not using the “standard deviation” formula.
yes I tried, i don’t have the same results with it either:
// periods = 20
sma = Average[periods](TypicalPrice)
standardDeviation = STD[periods](TypicalPrice)
return (TypicalPrice – sma) / (0.015 * standardDeviation)
formula is here: https://www.prorealcode.com/topic/formulation-prt-cci/#post-98046
Thank you Nicolas ! The devil is in the details, I missed one 🙂