Source code
Why 0.1 plus 0.2 can confuse an MQL5 comparison
Computers store many decimal values approximately. A printed value that looks rounded can still differ slightly internally. This becomes visible when an EA tests exact equality or repeatedly decides that a price has changed.
Formatting is not identity
NormalizeDouble rounds to a requested number of decimal digits, but floating-point representation can still produce extra digits in diagnostic output. Converting a number to a short string changes its display, not the underlying trading rule.
Choose a meaningful tolerance
For an illustrative calculation, values separated by a tiny arithmetic residue may be equivalent for the purpose of a comparison. Choose the tolerance from the task and instrument units. Do not use one broad epsilon for prices, money and lot sizes indiscriminately.
Test boundary behaviour
Check values just below, at and just above a threshold. Repeat after adding and subtracting a small increment. If equality is intended to detect a new price level, compare aligned increments rather than arbitrary formatted strings.
Explain the change to AI
Describe what equal means in the specific rule and ask for a small diagnostic example. Keep symbol tick-size and volume-step validation separate from decimal rounding. A successful fix removes accidental comparison noise without changing which legitimate market conditions qualify.
Back to top










