[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: TJ Help : AB Professional Upgrade



PureBytes Links

Trading Reference Links




CCI is 
a little tricky to code. The issue is that the mean 
deviation
<SPAN 
class=406034019-04012004> 
Here's 
the version I used in the auto-optimization framework, based on code Tomasz 
posted a while ago. Compared to the built-in version, it has the added advantage 
of allowing the period to be dynamic (an array rather than a single value), 
which is why I included it in the framework.
<SPAN 
class=406034019-04012004> 
<SPAN 
class=406034019-04012004>===========
<SPAN 
class=406034019-04012004> 
<SPAN 
class=406034019-04012004>function MeanDev(array, mean, range) { result 
= 0; for(i = LastValue(Highest(range)); i < BarCount; i++) 
{  result[i] = 0; // the mean is not 'moving' over the range 
(outside the loop)  tm = mean[i];   for(j = 0; j 
< range[i]; j++) {   result[i] = result[i] + abs(array[i - 
j] - tm);  }  result[i] = result[i] / range[i]; 
 } return result;}<SPAN 
class=406034019-04012004>
function CCIx(period) { // 
use in place of AB CCI function when period needs to be an array // CCI 
= (TypicalPrice - MA(TypicalPrice, 20)) / (.015 x MeanDeviation) SMATP 
= MA(Avg, period); MD = MeanDev(Avg, SMATP, period); result = 
(Avg - SMATP) / (0.015 * MD); return result;}
============
 
<FONT face=Arial color=#0000ff 
size=2>Dave
<BLOCKQUOTE 
>As 
  an exercise to get used to Amibroker's AFL language, I thought I would 
  take a description of how to calculated a CCI(20) and code it up myself to 
  compare against Amibroker's built-in CCI() indicator.  My results are 
  different than Amibroker's.  Could someone please take the following, 
  place it in an exploration and tweak it to get it to match Tomasz's  
  CCI?  Thanks!SteveP.S. I used the description 
  from stockcharts.com because Tomasz's description did not mention taking 
  an absolute value in one step and the mention of taking 0.015 as a 
  multiplier was mentioned twice which confused me.   Here is the 
  stockcharts.com link:<A 
  href="">http://www.stockcharts.com/education/IndicatorAnalysis/indic_CCI.html-------------------------------------------------Filter 
  = 1; /* all symbols and quotes accepted */ // Calculate the last 
  period's Typical Price // (TP) = (H+L+C)/3 where H = High, L = Low, AND C 
  = Close. // In Amibroker, the built-in symbol Avg is the same as 
  TP.TP = Avg;// Calculate the 20-period Simple Moving Average 
  of the // Typical Price (SMATP)SMATP = MA(TP, 20);// 
  Calculate the Mean Deviation. First, calculate the absolute value// of the 
  difference between the last period's SMATP AND the typical // price for 
  each of the past 20 periods. Add all of these absolute // values together 
  AND divide by 20 to find the Mean Deviation. MeanDiff = TP - 
  SMATP;MD = MA(abs(MeanDiff), 20);// The final step is to apply the 
  Typical Price (TP), the Simple // Moving Average of the Typical Price 
  (SMATP), the Mean Deviation // AND a Constant (.015) to the following 
  formula:////        CCI = (Typical 
  Price - SMATP) / (0.015 * Mean Deviation)//myCCI = MeanDiff / 
  (0.015 * 
  MD);AddColumn(High,"High",1.2);AddColumn(Low,"Low",1.2);AddColumn(Close,"Close",1.2);AddColumn(Avg, 
  "TP", 1.2);AddColumn(SMATP, "SMATP(20)", 1.2);AddColumn(MeanDiff, 
  "MeanDiff", 1.2);AddColumn(MyCCI, "MyCCI(20)", 1.2);AddColumn(CCI(20), 
  "CCI(20)", 1.2);


Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html





Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/ 
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.