The error "Invalid stop distance: 0.0" was occurring because the entry signals were being generated with invalid (zero) stop distances. This happened when the market volatility (ATR) value was 0 or not properly calculated.
Key Changes Made (Version 6.5.1):
Added GetValidATR() Helper Method in EntrySystem.mqh:
This method ensures we always have a valid ATR value
Includes multiple fallback mechanisms:
Direct ATR calculation if market data is invalid
0.1% of current price as a fallback
Minimum 20 pips for forex pairs
Updated All Entry Strategy Methods to use GetValidATR():
CheckMACrossover()
CheckMAPullback()
CheckMomentum()
CheckContrarian()
CheckBreakout()
CheckMeanReversion()
CheckMultiStrategy()
Enhanced Signal Validation in CheckSignal():
Added explicit check for stop_loss_distance > 0
Signal is rejected if stop distance is invalid
Better error logging to identify which strategy produced invalid signals
Improv
Parameter Confusion: The function was receiving stop distance in price units (e.g., 0.00255 for EURUSD) but treating it as if it was already in points.
Double Conversion: The code was multiplying by point size when it shouldn't have, causing the calculation to be off by a factor of 10,000 or more on 5-digit brokers.
The Fix:
I've updated the lot size calculation to properly handle the conversion:
cpp// OLD (INCORRECT):
double ticks = (stop_points * point_size) / tick_size; // Wrong!
// NEW (CORRECT):
double stop_points = stop_distance_price / point_size; // Convert to points first
double stop_ticks = stop_points * point_to_tick_ratio; // Then to ticks
Additional Improvements:
Safety Checks: Added validation to reject unreasonably high lot sizes (>1000 lots)
Enhanced Logging: More detailed debug output to diagnose issues
Dual Calculation Methods: Added a simplified calculation method for verification
Configuration Limits: Properly integrated min/max lot size limits f
I've identified and fixed the lot size calculation issue. The problem was in the formula used to calculate lot size from risk amount. Here's what was wrong and how it's fixed:
The Problem
The original calculation was producing lot sizes that were off by a factor of 100,000 (e.g., 1,315,295 lots instead of ~13 lots). This was due to an incorrect formula that wasn't properly using the tick value and tick size.
The Solution
The corrected formula now:
Uses tick value properly: The tick value represents the profit/loss in account currency for a 1 tick movement with 1 lot
Converts points to ticks: Since stop distance is in points, we convert it to ticks using point size and tick size
Calculates correctly: Lot Size = Risk Amount / (Stop Distance in Ticks × Tick Value)
Problem: EA was not opening trades during backtesting due to overly restrictive spread validation and position sizing calculation failures.
Changes Made:
1. EntrySystem.mqh - Improved Signal Validation
✅ Relaxed spread filter from fixed 10% ATR to dynamic 20-50% based on market conditions
✅ Added absolute maximum spread limit (5 pips for majors)
✅ Enhanced spread rejection logging with actual values
2. RiskManager.mqh - Fixed Position Sizing
✅ Added comprehensive logging throughout position size calculation
✅ Improved handling of minimum lot size requirements
✅ Added account balance validation before attempting trades
✅ Enhanced error messages for debugging
✅ Fixed lot size calculation for proper point value conversion
✅ Added validation for stop distance and risk amount inputs
3. ERMT_6.0.mq5 - Enhanced Configuration
✅ Increased default risk percent from 1% to 2.5% for better testing
✅ Increased max risk percent from 2% to 5%
✅ Adde
2- Compile and debug - Critical error on exit - OnDeinit
3- Fix for Entry System - Add to OnTick():
4 - ENUM_TECHNICAL_LEVEL enum in DataTypes.mqh -> other Enums and structures DataTypes.mqh v3
The Complete DataTypes Module provides the robust foundation needed for your institutional-grade risk management system, offering better trade tracking, risk analysis, and technical integration capabilities essential for professional algorithmic trading.
Moved modules to inside Advisors post-compile 1 debug; became unversioned
2 -