Dears for now i ended up doing the following though am not sure if its a best way to handle it:
i created a function to check if within array range:
bool InRange(int array_size, int val) { return (val >= 0) && val < array_size; }
Then updated the code with:
int ih = iHighest(Symbol(), Period(), MODE_HIGH, num_elements, bar_far_right_position); int il = iLowest(Symbol(), Period(), MODE_LOW, num_elements, bar_far_right_position); // Print("hight size: " + ArraySize(high), " xx: ", + xx); if(!InRange(ArraySize(high), ih)) return (0); if(!InRange(ArraySize(high), il)) return (0); price_high = high[ih]; price_low = low[il];
I didn't seem to get that error when I tested it.
On a side note - you can get ObjectsDeleteAll to work if you do this:
#define OBJ_PREFIX MQLInfoString(MQL_PROGRAM_NAME) void OnDeinit(const int reason){ ObjectsDeleteAll(0, OBJ_PREFIX); }
and anywhere you were using "obj_str", replace it with OBJ_PREFIX instead:
if(!plotArrow(chart_id, OBJ_PREFIX + (string)idx+ "-BeOBH", time[idx], high[idx], OBJ_ARROW_DOWN, ANCHOR_BOTTOM, beOColor)){ Print(__FUNCTION__, ": Failed to plot arrow ",GetLastError()); return(false); } ResetLastError(); if(!plotArrow(chart_id, OBJ_PREFIX + (string)idx+ "-BeOBL", time[idx], low[idx], OBJ_ARROW_UP, ANCHOR_TOP, beOColor)){ Print(__FUNCTION__, ": Failed to plot arrow ",GetLastError()); return(false); }
(there are more areas in the code where obj_str can be replaced)
I found that using a for loop inside of OnDeinit can cause problems and processing lag

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
i have the code below for creating simple order blocks. however it throws an index out of range error once i shift to higher time frames.
Can you help me understand where i got it wrong:
2024.04.13 08:29:06.242 AM_Fractal_OrderBlock (AUDUSD,MN1) array out of range in 'AM_Fractal_OrderBlock.mq5' (112,25)
-------------------------------------------------------------------------------------------------