MQL5 runtime blocker

Fix array out of range before trusting the next indicator signal.

Fix MQL5 array out of range runtime errors by checking CopyBuffer return counts, ArraySize, buffer indexes, bar shifts, and indicator readiness before retesting.

Common array-range evidence

array out of range in Expert.mq5
CopyBuffer copied 1 values, EA reads buffer[2]
ArraySize(buffer)=0
bar shift 1 not ready
_LastError=4806

These are data-read and indexing failures. They do not prove anything about strategy quality; they prove the EA needs safer buffer guards before the next manual test.

Guard CopyBuffer indexes before reading
Check ArraySize and copied counts
Separate current-bar and previous-bar access
Route opt-in source as array-index repair interest
Guard array reads in MQL5

Audience

For MQL5 builders whose EA compiles but fails during Strategy Tester, demo, or live observation with array out of range around CopyBuffer, indicator buffers, or bar indexing.

Problem

Array out of range usually means the EA read an index that was never copied, assumed a current/previous bar existed, or mixed ArraySetAsSeries direction with unsafe buffer access.

Outcome

Workfusionapp keeps the fix narrow: prove the copied count, guard every indexed read, log missing data, and route the code into the free desk with the exact buffer evidence.

Support path

One problem, one fix path.

Start with the concrete blocker, keep the full EA context attached, then move to a reviewable output.

1. Check copied count against the exact index

If the EA reads buffer[2], CopyBuffer must return at least three values. Checking only for -1 still allows runtime crashes when fewer values were copied.

2. Guard ArraySize before every read

Use ArraySize and the copied count as gates before reading current, previous, or older bars. Return early with a clear log when the data is not ready.

3. Keep buffer direction explicit

ArraySetAsSeries changes index meaning. Decide whether [0] is the current bar and make current/previous-bar reads consistent across every buffer.

Workflow

From runtime crash to one safe buffer read.

The fix is not to hide the error or remove indicator logic. The fix is to prove that each buffer index exists before the EA reads it, then keep signal and execution evidence separate.

Step 1

Paste the failing buffer block

Step 2

Check CopyBuffer return count

Step 3

Guard the first unsafe index

Step 4

Retest manually with concise logs

Array-index handoff

Route the range crash into the right buffer evidence path.

Open the guide that matches the failed read, then run the free desk with the CopyBuffer call, requested count, copied count, ArraySize, index read, and signal log.

CopyBuffer count guide

Use this when CopyBuffer returns fewer values than the EA reads, or when current/previous-bar indexing is unsafe.

Logging diagnostics guide

Use this when the EA needs clear copied-count, ArraySize, _LastError, spread, session, and signal-state logs before changing strategy logic.

Send me the array-index repair workflow

Opt in only if your MQL5 EA is blocked by array out of range, unsafe CopyBuffer indexing, ArraySize problems, or missing indicator data. This captures the array-index source for conversion measurement.

Intent locked: Paste compiler errors

Choose the workflow you want, then opt in only if you want Workfusionapp updates.

Can I ignore array out of range if the EA keeps running later?

No. Treat it as a runtime correctness bug. The EA is reading data it has not proven exists.

Should I just request more CopyBuffer values?

Not by itself. Request enough values, but also check the copied count and ArraySize before every indexed read.

Does fixing array indexing prove the EA is ready?

No. It only fixes one data-read layer. Compile, signal, risk, Strategy Tester, and demo review remain separate checks.