Camovia Tray™

Blog · Knowledge

Data Types in MQL4: What Nobody Tells You About Type Conversions

Camovia Tray Team · 2026-09-10

The Mistake That Cost a Trader 50 Pips

A trader I know spent an entire afternoon debugging his Expert Advisor. The logic was flawless. The entry conditions were perfect. Yet his EA kept opening trades at the wrong price—off by exactly one pip. He checked his indicators, his risk management, his broker's spreads. Nothing.

The culprit? An implicit type conversion he didn't even know existed.

double entryPrice = Ask - (StopLoss * Point);
int stopLossPoints = (int)((entryPrice - StopLoss) / Point);

The code looked fine. But the compiler was quietly converting a double to an int in a way that truncated the fractional part—and with it, the precision he needed for accurate order placement.

This is the problem with MQL4 data types. They seem straightforward on the surface, but the hidden rules of type conversion and strictness can quietly undermine your code if you don't know what to watch for.

The Real Problem: MQL4 Is Forgiving, And That's Dangerous

By default, MQL4 doesn't enforce strict variable declaration or type checking . This means you can write code that compiles successfully but behaves unpredictably—like the trader who lost pips because he didn't notice a conversion that was silently truncating his price calculations.

The compiler might warn you about "possible loss of data due to type conversion," but it won't stop you . It assumes you know what you're doing. And if you're like most traders, you're focused on strategy logic, not type system nuances.

Here's what's actually happening under the hood:

  • When you convert a double to an int, the fractional part is deleted—not rounded
  • When you store a value that exceeds a type's range, it gets truncated silently
  • When you mix types in expressions, MQL4 promotes them to the "highest" type in a priority hierarchy

None of this raises an error. But all of it can introduce subtle bugs that are extremely hard to trace.

The Overlooked Tool: #property strict

The first line of defense is a compiler directive most MQL4 developers ignore:

#property strict

With strict mode enabled, undeclared variables become compile-time errors, and many implicit type conversions that could lead to data loss are flagged . This is the difference between catching a bug before it costs you money versus discovering it after a losing trade.

Without #property strict, MQL4 might implicitly declare variables and silently convert between types without warning . In practice, this means a simple typo in a variable name could compile successfully and introduce unintended behavior.

The Type Conversion Trap Most Developers Walk Into

The most common hidden conversion trap involves the MarketInfo() function. It returns a double, but NormalizeDouble() expects an int for its second parameter .

// This will trigger a compiler warning about potential data loss
NormalizeDouble(price, MarketInfo(Symbol(), MODE_DIGITS));

The fix is simple but easy to overlook:

// Explicitly cast to int
NormalizeDouble(price, (int)MarketInfo(Symbol(), MODE_DIGITS));

The warning is the compiler telling you "I'm going to convert this for you, but it might not do what you expect." Casting explicitly doesn't change the conversion—it simply acknowledges that you're aware of it .

Why This Matters For Your Trading System

If you're managing an MT4 terminal, the data integrity of your code has a direct impact on your trading outcomes. Price calculations, position sizing, stop-loss placement—all of it depends on MQL4 handling data types correctly.

This is part of why tools that complement MT4, like the Camovia Tray app, focus on clean data handling. Camovia Tray reads live quotes and position data directly from your MT4 or MT5 terminal, displaying them in the system tray without any data leaving your machine [product_knowledge]. It doesn't interfere with your EA's logic, but it can help you verify what's actually happening—checking real-time prices and open positions visually, independent of your code's calculations.

Safer Type Handling: Rules Worth Remembering

Here are the practical rules that would have saved that trader 50 pips:

Rule 1: Always use #property strict at the top of your code. It doesn't solve all problems, but it catches the most common ones.

Rule 2: When converting between numeric types, use explicit casting. This doesn't change the behavior, but it makes your intention clear and silences the warnings you might otherwise ignore.

Rule 3: Never assume a conversion does what you intuitively expect. (int)1.999 yields 1, not 2. Use MathRound() if you need rounding .

Rule 4: For string concatenation with numbers, use IntegerToString() or DoubleToString(). Implicit conversions from number to string can hide logic errors and generate compiler warnings .

Rule 5: Pay attention to compiler warnings. They're not errors, but they're pointing out places where the compiler is making assumptions that might not match your intentions.

The Bottom Line

MQL4's type system is designed to be flexible, but that flexibility comes at a cost. The language assumes you're paying attention. Most of the time, you're focused on strategy logic, not type conversions.

The best practice is to make your type handling explicit, enable strict mode, and treat warnings as signals worth investigating. Your trading code handles real money—it deserves the same precision you'd want from any professional financial application.

Turn MT5 / MT4 into a Tray Tool

Check quotes, manage positions, and hide in one click.

Download Camovia Tray

Frequently Asked Questions

Can the tray icon be disguised?

Yes. The tray icon can disguise itself as a cloud drive or a common system tool, so market watching stays low-key.

What is the tray lock feature?

Lock the tray function instantly at key moments to protect your privacy and prevent private information from leaking.

What information can I monitor?

Quotes and open positions: symbol, direction, open time, current P&L, and more - all visible in the popup positions tab. Click an order to close it.

Which languages are supported?

Chinese and English, switchable on both the website and the client.

Popular Symbols Trading Hours

Open/close times, weekend hours & live market status: