-
You should encapsulate your iCustom calls to make your code self-documenting.
take candle color hekin ashi - MQL4 and MetaTrader 4 #8-9 or #1 (2018) -
double ha_close[], ha_open[], … ⋮ ArraySetAsSeries(ha_close, true); ⋮ ha_close[shift] = (pricedata[shift].open + pricedata[shift].close + pricedata[shift].high + pricedata[shift].low) / 4;
Your array has zero size; of course, you get array exceeded.
-
candlestocopy = 10; shift = 2; ⋮ pricedatapoints = CopyRates(_Symbol, 0, 0, candlestocopy, pricedata); ⋮ while(ha_close[shift] < ha_open[shift]) { ⋮ shift++;
You start shift at two; each tick you increase it in the while.
-
You should encapsulate your iCustom calls to make your code self-documenting.
take candle color hekin ashi - MQL4 and MetaTrader 4 #8-9 or #1 (2018) -
Your array has zero size; of course, you get array exceeded.
- You start shift at two; each tick you increase it in the while.
I'm not super knowledgeable in MQL5 yet so can you explain more as to what you mean by these things and what I should do?
So you mean I should make it a function instead? Your links give me an idea but it's MQL4 so it's a little confusing. I haven't learned much in the way of OOP.
As for point 3: I'm not sure what you mean here, because I want it to calculate only the bars that I want, so I figured making the shift++ conditional would be fine.
Thanks for the help so far.
Shift never goes down. How can that possibly be fine?
Ah. I see now.
I changed it to this, should this be alright? The error still persists, however, though I didn't expect this alone to fix it.
while(ha_close[shift] < ha_open[shift]) { bearishbars++; if(bearishbars > candlestocopy || bearishbars < candlestocopy) { candlestocopy = bearishbars; } shift++; if(ha_close[shift] >= ha_open[shift]) shift = 2; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello. I am practicing coding an EA that uses Heikin Ashi data (only close and open since that's all I need right now) to determine trades. When I backtest it I get an array out of size and ontick critical error, and debugging it points me to the pricedatapoints variable. The last time I had an issue like this I messed up the ordering of lines but it seems like I got it right this time.
I set up a loop to look from shift 2 and beyond for bearish Heikin Ashi bars and count them, as well as nesting an if statement in it to adjust the pricedata array data count (candlestocopy) if the loop counts more or less bearish bars than the size. This is the relevant part of the code. I'm not exactly sure what the issue is, but I am a beginner so I'd appreciate any help, thanks.