Why 0.1 plus 0.2 can confuse an MQL5 comparison

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.

NormalizeDouble reference

Back to top

MQLume Bespoke

Built around your ambition.

Explore bespoke services →

Have something more specific in mind?

Ask us about advanced custom development. Share your requirements through private support or email; we will discuss the scope and quote separately.

100% committed to following up on your delivery and support requests.

Free downloads. Real source files.

FREE

Lizard [MQLume]

MQL5 / MT5Version v2.1

Free editable gold breakout project with six independently selectable cores, session filters and flexible position sizing.

US$99.00FREE
FREE

Scraper Gold [MQLume]

MQL5 / MT5Version v3.7

Free editable source with compiled EX5: four gold breakout engines with independent profiles, sizing, direction and exits.

US$95.00FREE
MQLume

More to explore. A community to share it with.

Stay close to MQLume, wherever you like to learn.

YouTube

See our EAs in action. Explore backtests, walkthroughs and practical guides.

Watch on YouTube

Telegram

Meet other EA users, share ideas and keep up with what’s new.

Join the community Follow official updates

Cart

One personal-use licence per project. Each project can be added once.

Your cart is waiting for its first passenger.

Choose an EA or source edition to get started.

Continue shopping