forked from LengKundee/MQL5-Google-Onedrive
6.6 KiB
6.6 KiB
Expert Advisor Improvements
ExpertMAPSARSizeOptimized_Improved.mq5
Overview
This document describes the improvements made to the original Expert Advisor script.
Key Improvements
1. Enhanced Input Parameters
-
Organized Input Groups: All inputs are now organized into logical groups:
- Expert Settings
- Moving Average Signal
- Parabolic SAR Trailing
- Money Management
- Risk Management
- Logging & Debug
-
Additional Safety Parameters:
Expert_EnableTrading: Master switch to enable/disable tradingExpert_ShowAlerts: Control alert notificationsInp_Trailing_Enable: Enable/disable trailing stop- Lot size limits (Min/Max)
- Equity vs Balance selection
2. Risk Management Features
Daily Limits
- Max Daily Loss: Stop trading if daily loss exceeds percentage of balance
- Max Daily Profit: Stop trading if daily profit target is reached
- Max Trades Per Day: Limit number of trades per day
Time Filter
- Trading Hours: Restrict trading to specific hours
- Supports overnight trading windows
- Configurable start and end hours
3. Enhanced Logging System
Log Levels
- Level 0 (Errors): Only critical errors
- Level 1 (Info): Important information (default)
- Level 2 (Debug): Detailed debugging information
Logging Functions
LogError(): Critical errors with alertsLogInfo(): General informationLogDebug(): Detailed debugging
4. Trading Statistics
Daily Tracking
- Trades executed today
- Daily profit/loss
- Automatic reset at start of new day
Account Statistics
- Initial balance tracking
- Total profit/loss calculation
- Profit percentage calculation
5. Safety Checks
Trading Allowed Checks
- Master enable/disable switch
- Terminal AutoTrading check
- EA AutoTrading check
- Time filter validation
- Daily limits validation
Pre-Trade Validation
- All checks performed before each trade
- Prevents trading when limits are reached
- Clear logging of why trading is blocked
6. Error Handling
Comprehensive Error Messages
- Detailed error messages for each failure point
- Error codes for different failure types
- User-friendly error descriptions
Graceful Degradation
- EA continues to function even if some features fail
- Proper cleanup on initialization failure
- Statistics still tracked even if trading is disabled
7. Code Organization
Better Structure
- Clear separation of concerns
- Modular functions for different features
- Well-commented code sections
Maintainability
- Easy to modify and extend
- Clear function names
- Consistent coding style
New Features
1. Daily Statistics Tracking
- TradesToday: Number of trades executed today
- DailyProfit: Total profit for the day
- DailyLoss: Total loss for the day
- Automatic reset at midnight
2. Risk Management
- Max Daily Loss: Stop trading if loss exceeds limit
- Max Daily Profit: Stop trading if profit target reached
- Max Trades Per Day: Limit trading frequency
- Time Filter: Restrict trading hours
3. Enhanced Logging
- Configurable log levels
- Detailed error messages
- Trading activity logging
- Statistics logging
4. Safety Features
- Multiple trading permission checks
- Pre-trade validation
- Daily limit enforcement
- Time-based restrictions
Usage Recommendations
For Conservative Trading
Inp_Risk_MaxDailyLoss = 5.0 // 5% max daily loss
Inp_Risk_MaxDailyProfit = 10.0 // 10% profit target
Inp_Risk_MaxTradesPerDay = 5 // Max 5 trades per day
Inp_Risk_EnableTimeFilter = true // Enable time filter
Inp_Log_Level = 1 // Info level logging
For Aggressive Trading
Inp_Risk_MaxDailyLoss = 0.0 // No daily loss limit
Inp_Risk_MaxDailyProfit = 0.0 // No profit limit
Inp_Risk_MaxTradesPerDay = 0 // Unlimited trades
Inp_Risk_EnableTimeFilter = false // Trade 24/7
Inp_Log_Level = 2 // Debug logging
For Testing
Expert_EnableTrading = false // Disable actual trading
Inp_Log_Level = 2 // Full debug logging
Expert_ShowAlerts = true // Show all alerts
Comparison: Original vs Improved
| Feature | Original | Improved |
|---|---|---|
| Input Organization | Basic | Grouped by category |
| Risk Management | None | Daily limits, time filter |
| Logging | Basic Print | Multi-level logging system |
| Error Handling | Basic | Comprehensive |
| Statistics | None | Daily & account tracking |
| Safety Checks | Minimal | Multiple validation layers |
| Trading Control | Limited | Master switch + filters |
| Code Documentation | Minimal | Well documented |
Migration Guide
From Original to Improved
- Copy the improved EA to your MT5 Experts folder
- Compile in MetaEditor (F7)
- Configure parameters:
- Set your preferred risk management limits
- Configure logging level
- Set time filters if needed
- Test on demo account first
- Monitor logs to verify behavior
Parameter Mapping
Most original parameters remain the same:
Inp_Signal_MA_Period→ SameInp_Trailing_ParabolicSAR_Step→ SameInp_Money_SizeOptimized_Percent→ Same
New parameters have defaults that maintain original behavior:
- Risk limits default to 0 (disabled)
- Time filter defaults to disabled
- Logging defaults to Info level
Best Practices
- Start Conservative: Begin with strict limits and gradually relax
- Monitor Logs: Check logs regularly to understand EA behavior
- Test First: Always test on demo account before live trading
- Set Limits: Use daily loss limits to protect your account
- Review Daily: Check daily statistics and adjust as needed
Troubleshooting
EA Not Trading
- Check
Expert_EnableTradingis true - Verify AutoTrading is enabled in terminal
- Check daily limits haven't been reached
- Verify time filter settings
Too Many/Few Trades
- Adjust
Inp_Risk_MaxTradesPerDay - Check signal parameters
- Review time filter settings
Logging Issues
- Adjust
Inp_Log_Level(0=Errors, 1=Info, 2=Debug) - Check Expert tab in MT5 for logs
- Enable
Inp_Log_EnableDetailedLog
Future Enhancements
Potential improvements for future versions:
- Email/SMS notifications
- Telegram bot integration
- Advanced statistics dashboard
- Multi-timeframe support
- Additional risk management features
- Backtesting optimization tools
Support
For issues or questions:
- Check the logs (Expert tab in MT5)
- Review this documentation
- Verify all parameters are set correctly
- Test on demo account first