My guarded indicator reader compiled with 0 errors, but that proves no working signal on your account.
A trader reported repeated 4806 failures while reading indicator values across multiple currency pairs. The official runtime table names 4806 as requested indicator data not found. That describes missing data at the call. It does not identify one universal repair for every program.
I keep missing data out of the trading decision. For this small original example, the intended sample is one completed-bar value from buffer zero of an existing moving-average handle. The code first rejects an invalid handle or fewer than two calculated values. It then requests exactly one value starting at shift one. Only a complete copy with a finite, non-empty sample can update the caller's output.
The readiness check is useful but does not guarantee that the next call succeeds. The copy result is checked again. A failed read leaves the caller's output untouched. The caller still has to respect the false result and skip its decision. Treating that untouched old output as a new signal would defeat the whole guard.
These choices are specific to this example. A different indicator may expose a different buffer number, require a longer warm-up period or use different empty-value semantics. A multi-symbol program also needs to identify which handle and symbol failed. Keep a bounded retry on a later event rather than adding an endless loop that blocks the program. The compiled helper alone does not implement handle creation, retries or signal generation.
A handle exists before the requested values are ready.
Record the handle, calculated count, requested shift and count at the failure. A handle number alone is not evidence that a sample exists.
The requested buffer does not match the indicator.
Check the actual indicator interface. This example uses moving-average buffer zero. Do not apply that number blindly to a custom indicator.
A failed copy was turned into an ordinary number.
Check the returned copy count before reading the array. Keep a missing sample separate from a legitimate zero or a previous value.
A one-value reader that refuses an incomplete copy
bool TryClosedMA(const int handle,double &value)
{
if(handle==INVALID_HANDLE || BarsCalculated(handle)<2) return false;
double sample[1];
ResetLastError();
if(CopyBuffer(handle,0,1,1,sample)!=1) return false;
if(!MathIsValidNumber(sample[0]) || sample[0]==EMPTY_VALUE) return false;
value=sample[0];
return true;
}
I compiled BufferReader.mq5 with native MetaEditor on 22 October 2026. It produced zero errors and zero warnings. Its OnStart only prints a label and never calls TryClosedMA. I did not run the script. The image below renders the actual compiler result.
This is a source-level example, not an observed cure for error 4806. There is no reproduced error-to-recovery sequence, indicator output, strategy run or broker request in this proof. Before using it, test the caller's false-result path and the chosen indicator's actual data behaviour on demo.
Compile-only proof. No reproduced runtime 4806, indicator readiness check, retry sequence, strategy validation or order submission.
Preserve the failing request
Record symbol, timeframe, indicator parameters, handle, buffer number, shift, count and the copy result. Reset the error before the call and capture it immediately after a failure.
Test the no-data branch
On demo, a missing sample must skip the trading decision. The previous output must not become a new signal merely because the read failed.
Your five-minute source check
Find the CopyBuffer call that failed. Compare its requested buffer, shift and count with the indicator interface, then find the branch that prevents use of an incomplete copy.
Does BarsCalculated alone remove error 4806?
No. The subsequent copy can still fail or return an incomplete sample. Check its result as well.
Did this proof reproduce and repair a runtime error?
No. It proves only that this original defensive reader compiles. A real indicator and caller still require runtime tests.
Sources: CopyBuffer, BarsCalculated, runtime error codes.

Top comments (0)