Advertisement IC Markets

[FIXED] How to Resolve "Array Out of Range" (Error 4002) in MQL5 Scalping EAs

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
FXS Prop Desk
Posts: 1689
Joined: Wed Oct 07, 2026 9:52 am

Re: [FIXED] How to Resolve "Array Out of Range" (Error 4002) in MQL5 Scalping EAs

Post by FXS Prop Desk »

Moving buffer declarations out of OnTick is a good optimization. Another option is to calculate indicator values only on a new bar rather than on every tick, when the strategy logic depends on closed bars. That removes most of the CopyBuffer calls and reduces CPU load during volatile periods significantly.

For EAs that need indicator values on every tick, reusing a preallocated array with ArraySetAsSeries set once in OnInit also reduces overhead.
FXS Official Team | The Idea Lab & Strategy
Recommended broker for automated trading & scalping IC Markets
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: [FIXED] How to Resolve "Array Out of Range" (Error 4002) in MQL5 Scalping EAs

Post by Shadow Trader »

On the account page it looks like a simple menu: fixed spread, stable and predictable, or floating spread, tighter on average but variable. In practice the two categories overlap in ways the marketing does not mention.

Start with what a fixed spread can be. For a broker acting as the counterparty to the client, quoting a constant spread is a matter of pricing and risk management, not a law of nature. The underlying market still moves and widens. Someone absorbs that, and the cost usually appears elsewhere: a wider fixed number than the typical floating spread, requotes or rejected orders when the market is fast, or terms that allow the spread to change around news or rollover. Read the small print on "fixed" and there is often a clause covering exceptional conditions.

Floating has its own subtle versions. A spread that floats on a raw feed with a commission is not the same as a spread that floats with a markup built in. Both move, but the first starts lower and shows the cost in a separate line, while the second blends it in. Comparing the two by looking only at the quoted spread leaves out half of the picture.

Then there is the average problem. Floating spreads are usually advertised as averages or minimums. An average can look great while hiding quiet hours that are tight and active hours that are wide, and a fixed number can look dull while being the more honest one.

So what is the real difference? One pushes uncertainty into the price paid at execution. The other tucks it into the terms. For a scalper, a fixed spread is sometimes helpful for backtesting, since the cost becomes a single input, while floating is more honest about live conditions and can be cheaper in the quiet hours that matter most.

Which has worked better in practice on fast pairs, fixed or floating, and has a fixed account ever shown a wider spread than advertised?
Post Reply