The dynamic sizing ATR combo makes a lot more sense than fixed lot sizes. I like the broker-limit handling too. How do you usually test this across very different assets.
Algorithmic Risk Management in MT5: ATR Volatility Position Sizing & MQL5 Architecture
2 Comments
@[Md Siddikur Rahaman] Great question, Md Siddikur. Testing dynamic ATR sizing across disparate assets (e.g., EUR/USD vs. Gold XAU/USD vs. NAS100 vs. BTC) is where most EA architectures either shine or quietly blow up risk budgets.
When we run multi-market testing (such as in our cross-asset validation benchmarks across FX, metals, indices, and crypto), we follow this 4-step protocol:
- Audit the Symbol Specification Matrix (Contract & Tick Discrepancies)
Before running a single backtest, dump and compare the broker’s contract specs via SymbolInfoDouble():
Contract Multiplier (SYMBOL_TRADE_CONTRACT_SIZE): 1 lot of EURUSD is 100,000 units, but 1 lot of Gold (XAUUSD) is typically 100 oz, and NAS100 can be 1, 10, or 20 index contracts depending on the broker.
Dynamic Tick Value (SYMBOL_TRADE_TICK_VALUE): On non-USD quote pairs (like EUR/GBP) or synthetic CFDs, tick value fluctuates with real-time conversion rates. In MT5, always test using "Every tick based on real ticks" so the Strategy Tester reconstructs historical tick values rather than assuming a static rate.
- Track the "Clamped Minimum" Error Rate
The biggest hidden flaw with dynamic sizing on micro accounts or high-priced assets is SYMBOL_VOLUME_MIN:
If your risk budget is $50 with a tight ATR stop on Bitcoin or Gold, the raw mathematical lot might be 0.003.
If the broker's minimum volume is 0.01, forcing normalized_lots = min_lot means you are actually risking $160+ instead of $50 (a 300%+ risk overshoot).
How to test this: In your test logs, record effective_risk_usd / target_risk_usd. We reject or flag any asset where clamped_min == true on more than 2–3% of generated signals. If an asset frequently clamps, that asset either requires a higher account equity or a wider timeframe/ATR multiplier to trade safely.
- Cross-Market Walk-Forward Validation
When testing the strategy logic itself across different assets:
Uniform Risk Budgeting: Because ATR sizing normalizes volatility, each asset receives the exact same risk fraction (e.g., 1% risk per trade). This allows for honest cross-asset metric comparisons (Sharpe, Deflated Sharpe Ratio, Max Drawdown %) without arbitrary lot distortions.
Spread & Gap Stress Testing: Assets like Gold and Crypto have much wider spread expansions and slippage during session rollovers than major FX pairs. We stress-test the model with custom slippage delays (50–150 ms) and floating spread widening in MT5 to confirm the dynamic ATR stop buffer doesn't trigger false exits on normal spread spikes.
- Sanity Verification via OrderCalcProfit()
In MT5, you can double-check the sizing math programmatically before routing:
mql5
double check_profit = 0;
OrderCalcProfit(ORDER_TYPE_BUY, m_symbol, lots, open_price, sl_price, check_profit);
// check_profit will be negative (loss amount at SL)
// Verify: MathAbs(check_profit) ≈ effective_risk_usd
If OrderCalcProfit() deviates from your computed risk amount by more than 1 lot step of dollar tolerance, you know the broker's margin/tick calculation formula requires custom handling for that asset class.
Hope this helps! If you're running multi-symbol EAs in the MT5 tester, feel free to grab the base implementation from our open-source repo or check out the web calculator.
Please log in to add a comment.
Please log in to comment on this post.
More Posts
- © 2026 Coder Legion
- Feedback / Bug
- Privacy
- About Us
- Contacts
- You Tube
- Tiktok
- Premium Subscription
- Terms of Service
- Early Builders
I design open-source... Show moreFounder & Lead Quantitative Engineer at Gueta Quant (https://guetaquant.com).
I design open-source risk engines, statistical falsification frameworks, and algorithmic execution architectures across MetaTrader 5 (MQL5), cTrader (C#), TradingView (Pine Script v6), and Python.
Creator of 44 open-source quantitative tools (AGPLv3) registered on CERN Zenodo (DOI: 10.5281/zenodo.22012203). Show less
More From Guetaquant
Related Jobs
- JavaScript/LAMP Stack DeveloperEROS Technologies · Full time · Hagerstown, MD
- Job opening of FULL STACK DEVELOPER - C2C POSITION (Remote)Software Technology Inc · Full time · Boston, MA
- Senior Full-Stack Software Engineer, Storage Management Platform - DGX CloudNvidia · Full time · Santa Clara, CA
Commenters (This Week)
Contribute meaningful comments to climb the leaderboard and earn badges!