Problem with MQL5 indicator coding.

 

Dear Guys.

I am facing some problem with MQL5 indicator code. Problem is that. i am draw line base on RSI Period = 14. So i want my indicator not draw last previous 14 candle.  But when i code, my not draw from first. I think am doing something wrong. then code is below.

 


void OnInit()
  {

   min_rates_total=int(RSI_Period)+1;
   
   Rsi_Handle_Close=iRSI(NULL,0,RSI_Period,PRICE_CLOSE);
   if(Rsi_Handle_Close==INVALID_HANDLE) Print(" Failed to get the indicator handle!");

   SetIndexBuffer(0,Candle1Buffer1,INDICATOR_DATA);
   ArraySetAsSeries(Candle1Buffer1,true);
   

   //Define the number of color indexes, used for a graphic plot
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);

//Set color for each index
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Blue);   //Zeroth index -> Blue
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Red); //First index  -> Orande

  }


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[])
  {
  
  if(rates_total<min_rates_total) return(RESET);
  
  double RSI_Open[], RSI_High[],RSI_Low[], RSI_Close[];
  int limit, bar, to_copy;
 
  
  if(prev_calculated>rates_total || prev_calculated<=0)
  {
      limit=rates_total-min_rates_total-1; 
  }
  else
  {
      limit=rates_total-prev_calculated; 
  }

   to_copy = limit+2;
   
   if(CopyBuffer(Rsi_Handle_Close,0,0,to_copy,RSI_Close)<=0) return(RESET);
   if(CopyBuffer(Rsi_Handle_Open,0,0,to_copy,RSI_Open)<=0) return(RESET);
   if(CopyBuffer(Rsi_Handle_High,0,0,to_copy,RSI_High)<=0) return(RESET);
   if(CopyBuffer(Rsi_Handle_Low,0,0,to_copy,RSI_Low)<=0) return(RESET);

   ArraySetAsSeries(RSI_Open,true);
   ArraySetAsSeries(RSI_High,true);
   ArraySetAsSeries(RSI_Low,true);
   ArraySetAsSeries(RSI_Close,true);

   for(bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      Candle1Buffer1[bar]=RSI_Open[bar];
      Candle1Buffer4[bar]=RSI_Close[bar];
      
      if(RSI_Open[bar] > RSI_Close[bar]){
                buffer_color_line[bar]=0;
                Candle1Buffer2[bar]=RSI_High[bar];
                      Candle1Buffer3[bar]=RSI_Low[bar];
      } else {          
                     buffer_color_line[bar]=1;
                     Candle1Buffer2[bar]=RSI_Low[bar];
                     Candle1Buffer3[bar]=RSI_High[bar];
      }
     }
 
   return(rates_total);
  }
  
  
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties - Documentation on MQL5
Reason: