Hi guys!
I am working on an EA with simple entry criteria, however, I am getting the " array out of range " error at row 104.
Does anyone know how to solve this?
Thanks,
Martin
If there is an indicator buffer, then you need to assign an array to the indicator buffer.
Example:
//+------------------------------------------------------------------+ //| Accelerator.mq5 | //| Copyright 2009-2020, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2009-2020, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property description "Accelerator/Decelerator" //--- indicator settings #property indicator_separate_window #property indicator_buffers 6 #property indicator_plots 1 #property indicator_type1 DRAW_COLOR_HISTOGRAM #property indicator_color1 Green,Red #property indicator_width1 2 #property indicator_label1 "AC" //--- indicator buffers double ExtACBuffer[]; double ExtColorBuffer[]; double ExtFastBuffer[]; double ExtSlowBuffer[]; double ExtAOBuffer[]; double ExtSMABuffer[]; //--- handles for MAs int ExtFastSMAHandle; int ExtSlowSMAHandle; //--- bars minimum for calculation #define DATA_LIMIT 37 // FAST_PERIOD-1 + SLOW_PERIOD-1 //--- MA periods #define FAST_PERIOD 5 #define SLOW_PERIOD 34 //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ExtACBuffer,INDICATOR_DATA); SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,ExtFastBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(3,ExtSlowBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(4,ExtAOBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(5,ExtSMABuffer,INDICATOR_CALCULATIONS); //--- set accuracy IndicatorSetInteger(INDICATOR_DIGITS,_Digits+2); //--- sets first bar from what index will be drawn PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DATA_LIMIT); //--- name for DataWindow IndicatorSetString(INDICATOR_SHORTNAME,"AC"); //--- get handles ExtFastSMAHandle=iMA(NULL,0,FAST_PERIOD,0,MODE_SMA,PRICE_MEDIAN); ExtSlowSMAHandle=iMA(NULL,0,SLOW_PERIOD,0,MODE_SMA,PRICE_MEDIAN); }
If there is an indicator buffer, then you need to assign an array to the indicator buffer.
Example:
Thanks for the replay.
The issue is with the two arrays storing the close prices of the last 2 candles (highlighted in yellow).
D1Close is supposed to output the price of the last candle.
D2 is supposed to output the price of the second to last candle.
The idea is that the EA would go long after a bull candle and short after a bear candle.
So it would need a CopyBuffer, would it?
Please highlight the line where you are getting the error.
I have now highlighted in yellow the two lines where I am getting the error.
I have now highlighted in yellow the two lines where I am getting the error.
Well, where is your MQL5 code ???
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
a