Код: Выделить всё
function Initialize()
{
  IndicatorName = "CCI Histogram";
  PriceStudy = false;
  AddInput("Input", Inputs.Candle);         
  AddParameter("Period", 20, 1.2);                   
  AddSeries("CCI", DrawAs.Custom, Color.Green, AxisType.ZeroBased);   
  AddLevel(100, Color.Black, "CCI"); 
  AddLevel(-100, Color.Black, "CCI"); 
}
function Evaluate()
{
// AlfaDirect. 2014. OX 
// CCI Histogram (COMMODITY CHANNEL INDEX) – ИНДЕКС ТОВАРНОГО КАНАЛА  
if ( CurrentIndex < Period)
{
     CCI = 0.0;
}
else
{
      var TP = LIB.TP(Input); 
      var sma = SMA(TP, Period)[0]; 
     // Mean Deviation
     var sigma = 0.0;
     for (int i = 0; i < Period; i++ )
          sigma = sigma + Math.Abs(TP[-i] - sma);
     sigma = (sigma/Period);
     // CCI
     CCI = (TP[0] - sma) / (0.015 * sigma);
     
     if (CCI >0 )
       CCI.DrawHistogram(Color.Green);
    else 
       CCI.DrawHistogram(Color.DarkRed);
        
}
}
На мой взгляд - так более наглядно.