Can someone please point out what I'm doing wrong calculating CCI? This is CCI(15) I am trying.. 15 being 15 minutes.. The formula I have is: Code: CCI = (currTP - TPMA) / (.015 * (MD) Where... currTP = (High + Low + Close) / 3 TPMA is the SMA for the past 15 minutes but instead of using the lastprice, add (High+Low+Close)/3 and MD is the mean deviation.. as shown below in output as "MD" at the final MD (.0012) it is then divided by 15 (#of periods).. lastprice:1.2282,MD:1.0E-4 lastprice:1.2282,MD:1.0E-4 lastprice:1.2281,MD:2.0E-4 lastprice:1.2282,MD:3.0000000000000003E-4 lastprice:1.2283,MD:4.0E-4 lastprice:1.2285,MD:6.000000000000001E-4 lastprice:1.2286,MD:7.000000000000001E-4 lastprice:1.2285,MD:8.000000000000001E-4 lastprice:1.2286,MD:9.000000000000002E-4 lastprice:1.2286,MD:9.000000000000002E-4 lastprice:1.2285,MD:0.0010000000000000002 lastprice:1.2284,MD:0.0011000000000000003 lastprice:1.2284,MD:0.0011000000000000003 lastprice:1.2283,MD:0.0012000000000000003 2005-09-21 18:47:00,TP:1.2281,TPMA=1.2284,MD=1.0E-4 2005-09-21 18:47:00,CCI:-199.99999999997797 What am I doing wrong?? :<
TP = (HI + LO + CL) / 3 TP stands for Typical Price MATP = MA(TP, n) n = CCI Period MATP stands for Moving Average (Simple) of Typical Price where n = CCI Period MDTP stands for Mean Deviation of Typical Price CCI = (TP - MATP) / (MDTP * 0.015) http://www.linnsoft.com/tour/techind/cci.htm
and here is a snippet from working c code: Code: sg.SubGraphDataOut[6][pos] = (sg.BaseDataIn[1][pos]+sg.BaseDataIn[2][pos]+sg.BaseDataIn[3][pos])/3; if ( c>=ccilength) { double md1=0; sg.SubGraphDataOut[5][pos] = sum0; for (i=1; i<=ccilength; i++) { double ma=sg.SubGraphDataOut[5][pos]/ccilength; md1=md1+fabs(ma - sg.SubGraphDataOut[6][pos-i+1]); } md1=md1/ccilength; cci0=(sg.SubGraphDataOut[6][pos]-(sum0/ccilength))/(0.015*md1); sum0 = sum0 - sg.SubGraphDataOut[6][pos-ccilength+1]; }