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

Re: [amibroker] Want CCI to range from 0 to 100



PureBytes Links

Trading Reference Links



_SECTION_BEGIN("CCIvariable");

function MeanDev( array, mean, range )
{
  result = 0;

   for( i = LastValue( 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 ] AND ( i - j ) >= 0 AND ( i - j ) < BarCount; j++ )
      {
        result[ i ] = result[ i ] + abs( array[ i - j ] - tm );
      }
    
    result[ i ] = result[ i ]/range[ i ];
  }
  
  return result;
}

function VarCCI( array, period )
{

 SMATP = MA(array,period );//1,2

 MD = MeanDev( array, SMATP, period  );

 CCIx = (Avg - SMATP) / (0.015 * MD);

 return CCIx;

}

n = 20 + 4 * sin( Cum(1) ); // variable period
CCIv= VarCCI(Avg,n);

CCIvar= 100 * (CCIv  -  LLV(CCIv,200))/(HHV(CCIv,200)  -  LLV(CCIv,200));
CCIstd= 100 * (CCI(20)  -  LLV(CCI(20),200))/(HHV(CCI(20),200)  -  LLV(CCI(20),200));

Plot(CCIvar,"CCIvar",colorGreen,styleLine);

Plot(CCIstd,"CCIstd",colorRed,styleLine); 

PlotGrid(50,55);

_SECTION_END();