//+------------------------------------------------------------------+
//|                                                Отношение пар.mq4 |
//|                                                            Лёлик |
//|                                                                  |
//+------------------------------------------------------------------+

#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Otnoshenie
#property indicator_label1  "Otnoshenie"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters

input string   rub="USDRUB";
//--- indicator buffers
double         OtnoshenieBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,OtnoshenieBuffer);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int poziciya,i,j;
   ArraySetAsSeries(OtnoshenieBuffer,false);
    ArraySetAsSeries(time,false);
   ArraySetAsSeries(close,false);
   poziciya=prev_calculated-1;
   if (poziciya<0)
   poziciya=0;
   //printf("до i = %i,  j = %i,  poziciya = %i, time[i] = %f, rates_total =  %i", i,j,poziciya, time[i], rates_total);
   for(i=poziciya; i<rates_total; i++)
     {
      j=iBarShift(rub,0,time[i],false);
      OtnoshenieBuffer[i]= close[i]*iClose(rub,0,j);
     //printf("в цикле i = %i,  j = %i,  poziciya = %i, time[i] = %f, rates_total =  %i", i,j,poziciya, time[i], rates_total);
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
