|
Lakeville
Posts: 11 since Dec 2017
Thanks Given: 3
Thanks Received: 1
|
Evening All.
First and foremost, I appreciate all that look and provide their thoughts/opinions.
I'm trying to convert the Easylanguage Commodity Channel Index (CCI) to be used with a Price Series Provider. I've read a handful of articles on how it's actually calculated:
below is from tradingview . com / wiki / Commodity_Channel_Index_(CCI)
"There are several steps involved in calculating the Commodity Channel Index.
The following example is for a typical 20 Period CCI:
CCI = (Typical Price - 20 Period SMA of TP) / (.015 x Mean Deviation)
Typical Price (TP) = (High + Low + Close)/3
Constant = .015
The Constant is set at .015 for scaling purposes.
By including the constant, the majority of CCI values will fall within the 100 to -100 range.
There are three steps to calculating the Mean Deviation.
1. Subtract the most recent 20 Period Simple Moving from each typical price (TP) for the Period.
2. Sum these numbers strictly using absolute values.
3. Divide the value generated in step 3 by the total number of Periods (20 in this case).
Where i'm currently at is here:
variables:
TP (0),
AvgFC( 0 ),
CCIValue( 0 ) ;
TP = (PSP.Low[0] + PSP.High[0] + PSP.Close[0])/3;
TPlast = TP;
AvgFC = AverageFC( psp.close, 14 );
CCIValue = (TP - AvgFC) / (.015 * 14) ;
When plotting the CCIValue that i have created, it mirrors exactly, the line part only, of the standard CCI on all time frames. what differs is the actual values. for example, the standard CCI would show a value of say -174.99 while my CCIValue would show -3.89 at the 13:00 time in the attachment.
Where i'm stuck (meaning i don't understand how to write it) is on Steps 1 & 2 from what I listed above:
1. Subtract the most recent 20 Period Simple Moving from each typical price (TP) for the Period.
2. Sum these numbers strictly using absolute values.
Would someone mind assisting me in filling in my shortcomings here?
Thank you.
DG
|