Audience
For MQL5 builders migrating MQL4-style iMA calls or debugging moving-average EAs where CopyBuffer returns empty values, wrong indexes, or array out of range.
MQL5 iMA buffer blocker
Fix MQL5 iMA handle and CopyBuffer buffer-index mistakes by checking buffer 0, BarsCalculated, copied counts, ArraySetAsSeries, and IndicatorRelease.
Common iMA CopyBuffer evidence
double ma = iMA(_Symbol, _Period, 20, 0, MODE_EMA, PRICE_CLOSE, 0); CopyBuffer(maHandle, 1, 0, 2, maBuffer) returns 0 BarsCalculated(maHandle) <= 0 array out of range reading maBuffer[1] IndicatorRelease missing
These are indicator-handle and buffer-read failures. Fix the data layer before changing the strategy rule.
Audience
For MQL5 builders migrating MQL4-style iMA calls or debugging moving-average EAs where CopyBuffer returns empty values, wrong indexes, or array out of range.
Problem
In MQL5, iMA returns a handle and CopyBuffer reads indicator data. A moving-average EA breaks when it treats iMA like a direct value, reads the wrong buffer index, skips BarsCalculated, or reads more bars than CopyBuffer copied.
Outcome
Workfusionapp keeps the fix narrow: create the iMA handle once, read buffer 0 safely, check BarsCalculated and copied counts, guard indexes, then release the handle on shutdown.
Support path
Start with the concrete blocker, keep the full EA context attached, then move to a reviewable output.
Create the iMA handle in OnInit, check for INVALID_HANDLE, and store it for OnTick instead of expecting iMA to return the current MA value.
Standard iMA data is read from buffer index 0. If the EA reads maBuffer[1], CopyBuffer must copy at least two values first.
Use BarsCalculated and copied-count logs during tests, and call IndicatorRelease in OnDeinit so handle lifecycle is reviewable.
Workflow
The repair is not to guess another MA period. The repair is to prove that the handle is valid, data is calculated, enough values were copied, and each buffer index exists before use.
Step 1
Paste the iMA and CopyBuffer block
Step 2
Check handle lifecycle
Step 3
Guard buffer 0 reads
Step 4
Retest manually with moving-average logs
Related resource cluster
Use the cluster hub when the first issue branches into adjacent compiler, draft, risk, or review checks.
Compiler cluster
Use this hub for undeclared identifiers, CTrade setup, CopyBuffer, invalid stops, invalid volume, and fill-policy blockers.
Open compiler cluster
Review cluster
Use this hub when the next useful step is a structured EA review, no-trades diagnostic, audit trail, or readiness handoff.
Open review cluster
iMA CopyBuffer handoff
Open the guide that matches the failed read, then run the free desk with the iMA handle setup, CopyBuffer call, buffer index, copied count, and signal log.
Use this when iMA, iRSI, iMACD, or another indicator is being treated like an MQL4 direct-value call.
Use this when CopyBuffer copies fewer values than the EA reads or the current/previous-bar index is unsafe.
Use this when the moving-average signal works but still needs spread, session, max-trade, and risk gates before testing.
Send me the iMA CopyBuffer repair workflow
Opt in only if your moving-average EA is blocked by iMA handles, CopyBuffer buffer indexes, BarsCalculated, copied counts, or array-index errors.
Lead activation handoff
No email wait is required. After saving the opt-in, continue into the free desk with the same blocker so the visitor-to-lead-to-workflow path is measurable.
Continue in free deskChoose the workflow you want, then opt in only if you want Workfusionapp updates.
For the standard iMA indicator, read buffer index 0. The bigger issue is checking that the handle is valid and enough values were copied before reading.
Do not recreate the handle on every tick. Create it in OnInit, reuse it in OnTick, and release it in OnDeinit.
No. It only proves the indicator data layer is safer. Signal rules, execution, risk gates, and testing remain separate.