mousa2727lotfi64: How can I correct this error?
double … HSaveP[], … HSaveD[]; int OnInit(){ for(int i=0; i<=200; i++){ HSaveP[i]=iHigh(Symbol(),Period(),0); HSaveD[i]=iTime(Symbol(),Period(),0);
- Stop exceeding the size of your array(s). Those two arrays have no size, yet you try to store 200 identical elements into them.
- Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
Your error message "array out of range in '1.mq5' (23,13)" means that the error occurs on line 23, at position 13. Place your cursor at that position and you'll see what is wrong.

Documentation on MQL5: MQL5 programs / Runtime Errors
- www.mql5.com
The executing subsystem of the client terminal has an opportunity to save the error code in case it occurs during a MQL5 program run. There is a predefined variable _LastError for each executable MQL5 program. Before starting the OnInit function, the _LastError variable is reset...
1. Please insert code correctly: when editing a post, click and paste your code in the popup window
2. You should not use the 'CopyLowXXXX' functions when working with the current timeframe - you should use arrays from OnCalculate:
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[])
Here is the code from which all garbage is thrown out:
//+------------------------------------------------------------------+ //| Temp Indicator.mq5 | //| Copyright 2022, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property version "1.00" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 //--- plot Label1 #property indicator_label1 "Label1" #property indicator_type1 DRAW_ARROW #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Label2 #property indicator_label2 "Label2" #property indicator_type2 DRAW_ARROW #property indicator_color2 clrBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- input parameters input double InpExponenta = 2; // Exponenta //--- indicator buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; //--- double m_offset=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ExtMapBuffer1,INDICATOR_DATA); SetIndexBuffer(1,ExtMapBuffer2,INDICATOR_DATA); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(0,PLOT_ARROW,234); PlotIndexSetInteger(1,PLOT_ARROW,233); //--- Set the vertical shift of arrows in pixels PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-5); PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,5); //--- Set as an empty value 0 PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); //--- 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[]) { if(rates_total<3) return(0); //--- int limit=prev_calculated-1; if(prev_calculated==0) { ExtMapBuffer1[0]=0.0; ExtMapBuffer2[0]=0.0; limit=1; } for(int i=limit; i<rates_total; i++) { ExtMapBuffer1[i]=0.0; ExtMapBuffer2[i]=0.0; //--- if(open[i]<close[i] && open[i-1]<close[i-1] && open[i-2]<close[i-2] && close[i-1]-open[i-1]>(close[i-2]-open[i-2])*InpExponenta) { ExtMapBuffer1[i]=high[i]; } if(open[i]>close[i] && open[i-1]>close[i-1] && open[i-2]>close[i-2] && open[i-1]-close[i-1]>(open[i-2]-close[i-2])*InpExponenta) { ExtMapBuffer2[i]=low[i]; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Result:
Files:
Temp_Indicator.mq5
4 kb
Vladimir Karputov #:
In the code I gave - only 65 lines:
Your error message refers to some line #82.
The download above has 96 lines see below
***
Files:
Temp_Indicator.mq5
4 kb

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
My code is the following ... and I'm getting an error saying that "array out of range in '1.mq5' (23,13)" , when use it.
How can I correct this error?
Thanks a lot.
#21/06/2020 2300