Код: Выделить всё
   IndicatorName = "Cyber_Cycle_Period_OlNi";    
   PriceStudy =false;    
   AddInput("Input", Inputs.Candle);    
   AddParameter("alfa",0.07);
    AddSeries("Period", DrawAs.Line, Color.Green);   // Искомое значение периода для применения в адаптивных индикаторах 
    AddSeries("Price", DrawAs.Line, Color.Red,false);
    AddSeries("Cycle", DrawAs.Line, Color.Red);
    AddSeries("Smootch", DrawAs.Line, Color.Gray,false); 
    AddSeries("Q1", DrawAs.Line, Color.Blue);
    AddSeries("I1", DrawAs.Line, Color.Gray);
    AddSeries("DeltaPhase", DrawAs.Line, Color.Black);
    AddSeries("DC", DrawAs.Line, Color.Red , true);
    AddSeries("Median", DrawAs.Line, Color.Brown);
    AddSeries("InstPeriod", DrawAs.Line, Color.Violet);
    
    AddGlobalVariable("Buf", Types.DoubleList);     
}
function Evaluate()
          
{
  Price=(Input.High[0]+Input.Low[0])/2;   
  InstPeriod = 0.0;
  Smootch=(Price[0]+2*Price[1]+2*Price[2]+Price[3])/6; // Применение Элерсом фильтра НЧ(КИХ) для устранения шумов
  
  if (CurrentIndex <7)
  
      Cycle=(1-0.5*alfa)*(1-0.5*alfa)*(Smootch[0]-2*Smootch[1]+Smootch[2])+2*(1-alfa)*Cycle[1]-(1-alfa)*(1-alfa)*Cycle[2]; 
  
  else
  
      Cycle=(Price[0]-2*Price[1]+Price[2])/4;
      
  Q1 = (0.0962*Cycle[0] + 0.5769*Cycle[2] - 0.5769*Cycle[4]-0.0962*Cycle[6])*(0.5+0.08*InstPeriod[1]); //Синус фазового вектора c коррекцией
    
  I1 = Cycle[3]; //Косинус фазового вектоора
  
  if (Q1[0] != 0.0 && Q1[1] != 0.0)  DeltaPhase = (I1/Q1-I1[1]/Q1[1]) / (1 + I1*I1[1]/(Q1*Q1[1]));
  if (DeltaPhase < 0.1)              DeltaPhase = 0.1; 
  if (DeltaPhase > 1.1)              DeltaPhase = 1.1; 
     
 Buf.Add(DeltaPhase[0]);
 
  if (Buf.Count >5)  Buf.RemoveAt(0);
     
 var tmp = new List<double>(Buf); // Применение Медианного фильтра для сглаживания
 tmp.Sort();
 Median[0] = tmp[tmp.Count/2];
 
  if (Median[0] == 0.0)
     DC = 15;
  else
     DC = 6.28318 / Median[0] + 0.5;
  
 InstPeriod[0] =  0.33*DC + 0.67*InstPeriod[1];
 Period = 0.0;
 Period[0] =0.15*InstPeriod[0] + 0.85*Period[1];    
             
}
