Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# SafeTradingBot - Risk-Free MQL5 Expert Advisor

[![Version](https://img.shields.io/badge/version-1.0-blue.svg)](https://github.com/your-repo/SafeTradingBot)
[![Platform](https://img.shields.io/badge/platform-MetaTrader%205-green.svg)](https://www.metatrader5.com/)
[![License](https://img.shields.io/badge/license-MIT-yellow.svg)](LICENSE)

## 🎯 Overview

SafeTradingBot is a comprehensive, risk-managed Expert Advisor for MetaTrader 5 that addresses critical issues found in typical algorithmic trading systems. Unlike the risky Python trading bot it replaces, this EA implements multiple layers of protection to ensure safe trading operations.

## ⚡ Quick Start

1. **Download** `SafeTradingBot.mq5`
2. **Copy** to `MetaTrader5/MQL5/Experts/`
3. **Compile** in MetaEditor (F7)
4. **Attach** to any chart
5. **Configure** risk parameters
6. **Enable** automated trading

## 🛡️ Key Safety Features

### Risk Management
- ✅ **Emergency Stop System** - Automatic shutdown on critical conditions
- ✅ **Daily Loss Limits** - Maximum 5% daily loss (configurable)
- ✅ **Position Size Control** - Risk-based position sizing
- ✅ **Drawdown Protection** - Stops at 10% total drawdown
- ✅ **Consecutive Loss Limits** - Max 5 consecutive losses
- ✅ **Margin Level Monitoring** - 200% minimum margin requirement

### Technical Analysis
- ✅ **Trend Filtering** - EMA-based trend identification
- ✅ **Volatility Control** - ATR-based volatility filtering
- ✅ **Momentum Confirmation** - RSI overbought/oversold detection
- ✅ **Spread Filtering** - Avoids high-spread conditions

### Order Management
- ✅ **Guaranteed Stop Loss** - Every position has SL
- ✅ **Take Profit Targets** - Defined profit levels
- ✅ **Time-based Filters** - Trading hours control
- ✅ **News Avoidance** - Skips high-impact news times

## 📊 What's Fixed from the Original Python Bot

| Issue | Python Bot Problem | SafeTradingBot Solution |
|-------|-------------------|------------------------|
| **No Stop Loss** | Only TP orders placed | ✅ Guaranteed SL on every position |
| **Position Accumulation** | Unlimited position growth | ✅ Max 3 positions, size limits |
| **No Drawdown Control** | Could drain account | ✅ 10% max drawdown protection |
| **WebSocket Dependency** | Connection failures = missed updates | ✅ Native MT5 integration |
| **Complex Order Management** | 75+ concurrent orders | ✅ Simple, controlled order system |
| **No Account Protection** | Could lose entire balance | ✅ Multiple safety mechanisms |

## ⚙️ Configuration

### Conservative Settings (Recommended)
```
Max_Risk_Per_Trade = 1.0% // Risk per trade
Max_Daily_Loss = 3.0% // Daily loss limit
Max_Total_Risk = 5.0% // Total drawdown limit
Base_Lot_Size = 0.01 // Position size
Take_Profit_Points = 100 // TP level
Stop_Loss_Points = 50 // SL level
```

### Aggressive Settings (Experienced Traders)
```
Max_Risk_Per_Trade = 2.0% // Higher risk per trade
Max_Daily_Loss = 5.0% // Higher daily limit
Max_Total_Risk = 10.0% // Higher drawdown limit
Max_Open_Positions = 5 // More positions
Max_Daily_Trades = 20 // More trades per day
```

## 📁 File Structure

```
SafeTradingBot/
├── SafeTradingBot.mq5 # Main Expert Advisor
├── SafeTradingBot_Documentation.md # Complete documentation
├── README.md # This file
└── examples/
├── conservative_settings.set # Safe parameter set
└── aggressive_settings.set # Higher risk parameters
```

## 🚀 Installation

### Method 1: Direct Copy
1. Download `SafeTradingBot.mq5`
2. Open MetaTrader 5
3. Press `Ctrl+Shift+D` (Data Folder)
4. Navigate to `MQL5/Experts/`
5. Copy the file here
6. Restart MT5 or press F5

### Method 2: MetaEditor
1. Open MetaEditor (F4)
2. File → New → Expert Advisor
3. Replace code with SafeTradingBot code
4. Save as `SafeTradingBot.mq5`
5. Compile (F7)

## 📈 Usage

1. **Demo Testing** (Mandatory)
- Test on demo account first
- Run for at least 1 week
- Monitor all safety features

2. **Live Trading**
- Start with minimum settings
- Monitor daily performance
- Adjust parameters gradually

3. **Monitoring**
- Check Experts tab for messages
- Watch for emergency stops
- Review daily statistics

## ⚠️ Important Warnings

- **No Guarantee**: This EA does not guarantee profits
- **Risk Exists**: All trading involves risk of capital loss
- **Demo First**: Always test thoroughly on demo account
- **Supervision Required**: Monitor the EA regularly
- **Market Changes**: Strategies may become less effective over time

## 🔧 Troubleshooting

### EA Not Trading?
- ✓ Enable automated trading (Ctrl+E)
- ✓ Check trading hours settings
- ✓ Verify account balance > minimum
- ✓ Ensure emergency stop is not active

### Orders Not Executing?
- ✓ Check spread conditions
- ✓ Verify lot size requirements
- ✓ Confirm broker connection
- ✓ Review fill policy settings

### Unexpected Stops?
- ✓ Check daily loss limits
- ✓ Review drawdown levels
- ✓ Verify margin requirements
- ✓ Check consecutive loss counter

## 📚 Documentation

- **Complete Guide**: [SafeTradingBot_Documentation.md](SafeTradingBot_Documentation.md)
- **Parameter Reference**: See documentation for all settings
- **Risk Management**: Detailed explanation of safety features
- **Technical Analysis**: How indicators are used
- **Troubleshooting**: Common issues and solutions

## 🤝 Contributing

1. Fork the repository
2. Create feature branch (`git checkout -b feature/improvement`)
3. Commit changes (`git commit -am 'Add improvement'`)
4. Push to branch (`git push origin feature/improvement`)
5. Create Pull Request

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🙏 Acknowledgments

- MetaQuotes for the MQL5 platform
- Trading community for feedback and testing
- Risk management principles from professional trading firms

## 📞 Support

- **Issues**: Use GitHub Issues for bug reports
- **Questions**: Check documentation first
- **Updates**: Watch repository for new releases

---

**Disclaimer**: Trading involves substantial risk of loss. This EA is provided for educational purposes. Past performance does not guarantee future results. Only trade with money you can afford to lose.

**Remember**: The goal is not just to make money, but to preserve capital and trade another day. 🛡️
Loading