About "Array out of range " error

 

guys...

I have created Custom indicator by using "EA Builder" site. I choosed 5000 bars for look back and omit 50 bars for stop array out of range error. (img ) 

but when back testing, indicator is not show anything. journal says "Array out of range error"   


How can I solve this problem ?

 
Hapu Arachchilage Tharindu Lakmal:

guys...

I have created Custom indicator by using "EA Builder" site. I choosed 5000 bars for look back and omit 50 bars for stop array out of range error. (img ) 

but when back testing, indicator is not show anything. journal says "Array out of range error"   


How can I solve this problem ?

Use the debugger and control the indices of your arrays:

https://www.metatrader5.com/en/metaeditor/help/development/debug
https://www.mql5.com/en/articles/35 // scrol down to: "Launching and Debuggin"
https://www.mql5.com/en/articles/2041 // Error Handling and Logging in MQL5

Virtual hosting for MetaTrader 5
Virtual hosting for MetaTrader 5
  • www.mql5.com
The fastest VPS server for forex trading from the MetaTrader 4/5 terminal developers
 
Hapu Arachchilage Tharindu Lakmal:

guys...

I have created Custom indicator by using "EA Builder" site. I choosed 5000 bars for look back and omit 50 bars for stop array out of range error. (img ) 

but when back testing, indicator is not show anything. journal says "Array out of range error"   


How can I solve this problem ?


Don't take Screenshot, Paste your entire code. There is no code to call buffers in your Screenshot.
Btw you don't need to set ArraySetAsSeries each tick...
 
Hapu Arachchilage Tharindu Lakmal: I have created Custom indicator by using "EA Builder" site.

EA builder, EA Builder Pro, EATree, Etasoft forex generator, Forex Strategy Builder, ForexEAdvisor STRATEGY BUILDER, ForexRobotAcademy.com, FX EA Builder, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, Online Forex Expert Advisor Generator, Strategy Builder FX, Strategy Quant, Visual Trader Studio, MQL5 Wizard, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.

  1. Since you haven't learned MQL4/5, therefor there is no common language for us to communicate.
    If we tell you what you need, you can't code it.
    If we give you the code, you don't know how to integrate it into yours.
    We are willing to HELP you when you post your attempt (using Code button) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

  2. EA builder makes bad code counting up while closing multiple orders.
    EA builder makes bad code Bars is unreliable (Max bars in chart), volume is unreliable (miss ticks.) Always use time.
    EA builder makes bad code, not adjusting for 4/5 digit brokers, TP/SL and slippage.
    EA builder makes bad code, not adjusting for ECN brokers. pre-Build 500)
    EA builder makes bad code, not checking return codes.

  3. EATree uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)

  4. FX EA Builder makes bad code, not checking return codes.
    FX EA Builder makes bad code, loosing open tickets on terminal restart. No recovery (crash/power failure.)
    FX EA Builder makes bad code, not adjusting stops for the spread.
    FX EA Builder makes bad code, using OrdersTotal directly.

  5. FOREXEADVISOR STRATEGY BUILDER makes bad code, non-updateing global variables.
    FOREXEADVISOR STRATEGY BUILDER makes bad code, compilation errors.
    FOREXEADVISOR STRATEGY BUILDER makes bad code, not checking return codes.

Learn to code it, or pay someone (Freelance) someone to code it.
          Hiring to write script - General - MQL5 programming forum #1 (2019)

 
William Roeder #:

EA builder, EA Builder Pro, EATree, Etasoft forex generator, Forex Strategy Builder, ForexEAdvisor STRATEGY BUILDER, ForexRobotAcademy.com, FX EA Builder, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, Online Forex Expert Advisor Generator, Strategy Builder FX, Strategy Quant, Visual Trader Studio, MQL5 Wizard, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.

  1. Since you haven't learned MQL4/5, therefor there is no common language for us to communicate.
    If we tell you what you need, you can't code it.
    If we give you the code, you don't know how to integrate it into yours.
    We are willing to HELP you when you post your attempt (using Code button) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

  2. EA builder makes bad code counting up while closing multiple orders.
    EA builder makes bad code Bars is unreliable (Max bars in chart), volume is unreliable (miss ticks.) Always use time.
    EA builder makes bad code, not adjusting for 4/5 digit brokers, TP/SL and slippage.
    EA builder makes bad code, not adjusting for ECN brokers. pre-Build 500)
    EA builder makes bad code, not checking return codes.

  3. EATree uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)

  4. FX EA Builder makes bad code, not checking return codes.
    FX EA Builder makes bad code, loosing open tickets on terminal restart. No recovery (crash/power failure.)
    FX EA Builder makes bad code, not adjusting stops for the spread.
    FX EA Builder makes bad code, using OrdersTotal directly.

  5. FOREXEADVISOR STRATEGY BUILDER makes bad code, non-updateing global variables.
    FOREXEADVISOR STRATEGY BUILDER makes bad code, compilation errors.
    FOREXEADVISOR STRATEGY BUILDER makes bad code, not checking return codes.

Learn to code it, or pay someone (Freelance) someone to code it.
          Hiring to write script - General - MQL5 programming forum #1 (2019)

thank you so much for advice.. its worth. 

 
_MAHA_ #:

Don't take Screenshot, Paste your entire code. There is no code to call buffers in your Screenshot.
Btw you don't need to set ArraySetAsSeries each tick...
//+------------------------------------------------------------------+
//|                                 Indicator: RSI with shifr -3.mq4 |
//|                                       Created with EABuilder.com |
//|                                        https://www.eabuilder.com |
//+------------------------------------------------------------------+
#property copyright "Created with EABuilder.com"
#property link      "https://www.eabuilder.com"
#property version   "1.00"
#property description ""

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 0x6600FF
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 0xF2FF00
#property indicator_label2 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

extern int rsi = 8;
extern int arrows_shift = 2;
extern int rsi_shift = -3;
extern double RSI_ob = 80;
extern double RSI_OS = 20;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | RSI with shifr -3 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexArrow(0, 233);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexArrow(1, 234);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   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 limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
      ArrayInitialize(Buffer2, EMPTY_VALUE);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, rsi, PRICE_CLOSE, rsi_shift+i) < RSI_ob
      && iRSI(NULL, PERIOD_CURRENT, rsi, PRICE_CLOSE, rsi_shift+i+1) > RSI_ob //Relative Strength Index crosses below fixed value
      )
        {
         Buffer1[i] = Low[i] + arrows_shift * myPoint; //Set indicator value at Candlestick Low + fixed value
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 2
      if(iRSI(NULL, PERIOD_CURRENT, rsi, PRICE_CLOSE, rsi_shift+i) > RSI_OS
      && iRSI(NULL, PERIOD_CURRENT, rsi, PRICE_CLOSE, rsi_shift+i+1) < RSI_OS //Relative Strength Index crosses above fixed value
      )
        {
         Buffer2[i] = High[i] - arrows_shift * myPoint; //Set indicator value at Candlestick High - fixed value
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
Reason: