In this article
After this article, you can
- Separate platform object restrictions from an authored signal model.
- Record mode and the first divergent stage without placing trades.
Terms at hand: Expert Advisor (EA) · Backtesting
An EA that works only in MT5 visual testing needs a check of whether its decision depends on data or on something drawn on a chart. A graphical object should not replace an explicit signal value. Before changing the strategy, compare modes, versions, data and the first difference in its logs. The example below does not run MT5: it is an authored model separating a number from an unavailable reading. Missing input remains unknown rather than becoming zero, and no trade is placed.
What actually differs in visual mode?
The MQL5 tester documentation states that graphical objects are not plotted outside visual testing, and queries for properties of a created object return zero values. The limitation does not apply to visual mode. This is documented platform behaviour rather than an experiment we performed on your EA. It does not establish that every discrepancy between tests has the same cause.
If an EA reads a line price or button state as an input, record that stage separately from an indicator or price data. Establish whether the value exists in that mode first. An explicit unavailable status can stop diagnosis before calculation instead of accepting a technical zero as a price. A visible chart does not confirm readiness of every input used by the strategy.
How do you separate a numeric signal from a chart object?
Unavailable input is not a zero price
| Path | Input | Evaluation |
|---|---|---|
| Explicit numeric signal | 1.1050 | 1.1050 > 1.1040: true in the model. |
| Unavailable object | null: no value | The condition is not evaluated. |
| Incorrect substitution | 0 instead of no value | 0 > 1.1040: apparently an ordinary false result. |
The last row illustrates the faulty comparison version. The guarded path retains a missing reading as null; a separate version shows the consequence of replacing it with zero. Zero and null answer different questions: one is a number, while the other indicates missing input. Under the opposite condition, “signal below threshold”, substituted zero could even appear to satisfy the criterion. Do not repair the program by inserting an arbitrary fallback value.
Separate data from a chart object
Our teaching example runs locally in your browser: it does not connect to an account or API, send your entries or save them persistently. Do not enter passwords or personal details.
The tool lets you change two positive finite values. It evaluates the explicit number while leaving the unavailable-object path without a comparison result. The page reads no chart, executes no platform test and creates no investment signal. It demonstrates why diagnosis must distinguish a false condition from one that cannot be evaluated.
How do you record program mode without trading?
The MQL5 flags MQL_TESTER, MQL_VISUAL_MODE and MQL_OPTIMIZATION describe the program's environment. TERMINAL_BUILD identifies the terminal build. Record actual readings rather than assuming a tester mode from a window's appearance. That record alone does not establish identical data or parameters.
The small standalone diagnostic EA below logs configuration in OnInit and has an empty OnTick. It sends or modifies no orders. OnInit documents the initialization signature, and PrintFormat documents formatted output. Save it as a separate MQ5 file, compile it in MetaEditor and compare actual logs from your own terminal.
#property strict
int OnInit()
{
PrintFormat("tester=%d visual=%d optimization=%d build=%d symbol=%s period=%d",
(int)MQLInfoInteger(MQL_TESTER),
(int)MQLInfoInteger(MQL_VISUAL_MODE),
(int)MQLInfoInteger(MQL_OPTIMIZATION),
(int)TerminalInfoInteger(TERMINAL_BUILD),
_Symbol, (int)_Period);
return INIT_SUCCEEDED;
}
void OnTick() {}
Do not create a second OnInit in an existing EA or replace its initialization with this snippet. Adding logging requires preserving the program's existing flow. Tester documentation also gives an OnInit exception to the PrintFormat restriction during optimization; missing print output from every other stage does not prove those stages were never executed.
How do you find the first difference instead of comparing profit?
Prepare a paired-run record: visual/non-visual mode, terminal and code versions, inputs, symbol and timeframe, tick-generation model, requested and actual start, data snapshot, costs and initial state. Preserve settings files and version identifiers too. If these declarations differ, do not attribute the whole change to the chart window. The two-backtest record comparator helps organise this check.
Find the earliest stage where one path has a different value: retrieval success, data timestamp, indicator readiness, signal, condition or decision. A note saying “profit 120 rather than 80” does not identify that stage. Preserve original logs and create a small comparison table beside them. Do not invent values that the program did not record previously.
Keep the diagnostic record small enough to match events in both runs. Logging everything without a stable identifier can obscure the first divergence. Record which input was requested, its timestamp or sequence position and whether the program accepted it. These are practical record-design choices, not a guarantee that a log identifies every dependency automatically.
Add an observation identifier and record which input was requested. Matching the sequences then need not rely on guessing whether similar prices came from the same stage of the test.
What should change in the signal's design?
The calculation should return an explicit value plus data-availability status; the graphical layer can display that value. Switching drawing off then need not deliberately change the input source. Check the same module on several controlled inputs, including unavailable data and a value equal to the threshold. This does not guarantee matching results for the entire tester: versions, data, costs and other code dependencies remain relevant.
“This limitation does not apply to testing in visual mode.” — MetaQuotes, MQL5 tester documentation, graphical-objects section; accessed 13 October 2026.
Without source code, send the EA author your paired-run record and the first documented divergence. Do not replace diagnosis with a sequence of live trial orders. The MT4 and MT5 backtesting guide covers general test preparation.
What to do tomorrow
- Complete a paired-mode record. Preserve code and terminal versions, inputs, data and range for one pair of runs. Mark unconfirmed fields. The same EA file does not establish that all other settings match or that the data used in each run are identical.
- Distinguish no value from zero. Run our model with signal 1.1050 and threshold 1.1040, then set equal values. Check that an unavailable object remains null regardless of the comparison result for explicit numeric inputs. This does not require a trading account.
- Record the first divergent stage. In a separate demo configuration or tester, gather non-trading diagnostic entries and compare their sequence. Establish whether input, availability or the condition changed. The diagnostic description neither proves profitability nor provides an investment recommendation.
Check your understanding
One short exercise
About 3 min · you can try again
Threshold is 1.1040. The object reading is unavailable. How does our simulation evaluate greater than threshold?
- Replace it with zero and return false.
- Keep null and do not evaluate the condition.
- Use a number from a previous chart.
Check the answer and explanation
Keep null and do not evaluate the condition.
Correct. That is our explicit model semantics, not an assertion that an MT5 function returns null.
Frequently asked
Does null in the model mean MT5 object functions return null?
No. Platform documentation describes zero values when querying object properties outside visual testing. Null is our explicit representation of unavailable input in the page simulation. We separate the platform’s reporting behaviour from reasoning about available data. The model substitutes no zero and makes no comparison without input. Diagnosing an actual EA requires checks of the function, its success, mode and expected data. This model demonstrates one dependency rather than every MQL5 behaviour.
Does a true simulation result mean the EA will open a trade?
No. The page compares two declared positive numbers and connects to neither a terminal nor an account. A true model condition establishes neither data readiness, other strategy criteria, permissions nor order execution. These are separate stages in an actual EA too. Our demonstration distinguishes a false result from inability to evaluate. It generates no investment signal, does not reproduce the MT5 tester and cannot prove the effectiveness of any specific program.
Does removing graphical objects guarantee matching tests?
No. Removing a signal’s drawing dependency addresses one possible cause, while versions, inputs, data snapshots, tick models, costs and initial state remain relevant. Record both runs first and find the earliest input or calculation difference. Do not change several components at once or judge the fix only by higher final profit. Without preserved evidence you cannot honestly assign the discrepancy to one cause. Give the developer a concrete sequence and identify unconfirmed fields.
Is the small logger a strategy ready for trading?
No. It is a standalone diagnostic example logging configuration in OnInit with an empty OnTick. It sends or modifies no orders, calculates no signal and manages no open positions. Compile your own file in MetaEditor and preserve the actual result and log. Do not add a second OnInit to an existing EA or replace initialization without understanding the code. The snippet checks mode flags rather than proving another program’s safety or profitability.
Sources & bibliography
-
MetaQuotes Ltd MQL5 Reference — Testing Trading Strategies · Non-visual graphical objects, zero readings, visual exception and optimization OnInit PrintFormat exception. www.mql5.com ↗
-
MetaQuotes Ltd MQL5 Reference — Running MQL5 Program Properties · MQL_TESTER, MQL_VISUAL_MODE and MQL_OPTIMIZATION. www.mql5.com ↗
-
MetaQuotes Ltd MQL5 Reference — Client Terminal Properties · TERMINAL_BUILD for the actual client build. www.mql5.com ↗
-
MetaQuotes Ltd MQL5 Reference — OnInit · int OnInit signature and INIT_SUCCEEDED. www.mql5.com ↗
-
MetaQuotes Ltd MQL5 Reference — PrintFormat · Formatted integer and string logging. www.mql5.com ↗
