forked from LengKundee/MQL5-Google-Onedrive
241 lines
6.6 KiB
Markdown
241 lines
6.6 KiB
Markdown
# 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 trading
|
|
- `Expert_ShowAlerts`: Control alert notifications
|
|
- `Inp_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 alerts
|
|
- `LogInfo()`: General information
|
|
- `LogDebug()`: 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
|
|
```mql5
|
|
- 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
|
|
```mql5
|
|
- 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
|
|
```mql5
|
|
- Configurable log levels
|
|
- Detailed error messages
|
|
- Trading activity logging
|
|
- Statistics logging
|
|
```
|
|
|
|
### 4. Safety Features
|
|
```mql5
|
|
- 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
|
|
|
|
1. **Copy the improved EA** to your MT5 Experts folder
|
|
2. **Compile** in MetaEditor (F7)
|
|
3. **Configure parameters**:
|
|
- Set your preferred risk management limits
|
|
- Configure logging level
|
|
- Set time filters if needed
|
|
4. **Test on demo account** first
|
|
5. **Monitor logs** to verify behavior
|
|
|
|
### Parameter Mapping
|
|
|
|
Most original parameters remain the same:
|
|
- `Inp_Signal_MA_Period` → Same
|
|
- `Inp_Trailing_ParabolicSAR_Step` → Same
|
|
- `Inp_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
|
|
|
|
1. **Start Conservative**: Begin with strict limits and gradually relax
|
|
2. **Monitor Logs**: Check logs regularly to understand EA behavior
|
|
3. **Test First**: Always test on demo account before live trading
|
|
4. **Set Limits**: Use daily loss limits to protect your account
|
|
5. **Review Daily**: Check daily statistics and adjust as needed
|
|
|
|
## Troubleshooting
|
|
|
|
### EA Not Trading
|
|
- Check `Expert_EnableTrading` is 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:
|
|
1. Check the logs (Expert tab in MT5)
|
|
2. Review this documentation
|
|
3. Verify all parameters are set correctly
|
|
4. Test on demo account first
|