#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1

#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue

input int RandomVariable = 1;

double Buffer1[];

int OnInit()
{
   SetIndexBuffer(0, Buffer1, INDICATOR_DATA);
   ArraySetAsSeries(Buffer1, true);
   MathSrand(RandomVariable);
   return(INIT_SUCCEEDED);
}


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
   static ulong count = 0;
   if(rates_total <= 0)
   {
      Print("rates_total");
      count = 0;
      return 0;
   }

   if(!prev_calculated)
   {
      Print("prev_calculated");
      count = 0;
      ArrayInitialize(Buffer1, EMPTY_VALUE);
   }
   
   Comment(count++, ":", MathRand() + MathRand());
   
   const int N = fmin(rates_total, TerminalInfoInteger(TERMINAL_MAXBARS));

   for(int i = fmax(0, prev_calculated - 1); i < N; i++)
   {
      int barIndex = N - 1 - i;
      Buffer1[barIndex] = iClose(_Symbol, _Period, barIndex);
   }

   return(rates_total);
}

void OnDeinit(const int)
{
   Comment("");
}
