π€ GOLD MEAN REVERSION BOT - Cephas Nzaana Fixed & Enhanced Multi-System Mean Reversion Strategy π PROJECT OVERVIEW Owner: Cephas Nzaana Strategy: Multi-system mean reversion with profit protection Risk/Reward: Dynamic with profit locking Risk Per Trade: 0.01 fixed lot (Phase 1) Broker: Any MT5 compatible Platform: MetaTrader 5 Symbol: XAUUSD (Gold) Timeframe: M5 (5-minute chart)
π― STRATEGY SPECIFICATIONS CORE FIXES APPLIED: Fixed "Invalid Stops" Errors - Added validation for all stop loss modifications
Added Profit Protection - Smart breakeven movement and trailing stops
Enhanced Exit Strategy - Mean reversion exits with profit tracking
Risk Management - Daily loss limits and trade frequency controls
Dual System Architecture - Two independent trading systems
TRADING SYSTEMS: SYSTEM 1: Price Z-Score + RSI
Detects price deviation from 20-period mean
RSI confirmation for oversold/overbought conditions
Entry on mean reversion with reversal confirmation
SYSTEM 2: Bollinger Bands + MACD
Price touches Bollinger Bands (Β±2 standard deviations)
MACD crossover confirmation
Institutional-style mean reversion entries
ENTRY LOGIC: System 1 BUY Signal:
Price > 0.3% below 20-period mean
RSI < 30 and rising
Bullish reversal candle pattern
All conditions must be met
System 1 SELL Signal:
Price > 0.3% above 20-period mean
RSI > 70 and falling
Bearish reversal candle pattern
All conditions must be met
System 2 BUY Signal:
Price touches lower Bollinger Band
MACD bullish crossover
Previous MACD was bearish
System 2 SELL Signal:
Price touches upper Bollinger Band
MACD bearish crossover
Previous MACD was bullish
STOP LOSS MANAGEMENT (FIXED): Dynamic ATR-based stops (optional)
Fixed 200-pip safety stops
Smart breakeven at +15 pips profit
Trailing stops start at +25 pips profit
ALL stops validated before modification (prevents "Invalid stops" errors)
EXIT STRATEGY: Mean Reversion Exit: Close when price returns to 20-period SMA
Trailing Stop: Protects profits during strong trends
Emergency Close: Exit if price moves 1% against position
Time Exit: Maximum 20 bars hold time
Manual Close: Profit shown in logs (e.g., "Profit: $3.64")
KEY IMPROVEMENTS FROM ORIGINAL: β No more "Invalid stops" errors
β Profit locking with breakeven movement
β Trailing stops to protect gains
β Daily loss limits
β Better trade frequency control
β Validated stop loss placement
β Emergency adverse move protection
GoldBot_Project/ β βββ README.md # This updated file βββ STRATEGY_SPEC.md # Detailed strategy document β βββ Fixed_Version/ β βββ Cephas_GoldBot_Phase1_FIXED.mq5 # Working MT5 EA (Fixed) β βββ installation_guide.md # How to install in MT5 β βββ backtest_guide.md # How to backtest β βββ parameters_explained.md # EA settings explained β βββ compilation_fixes.md # Fixed MQL5 syntax issues β βββ Original_Issues/ β βββ error_logs.md # Analysis of original errors β βββ sample_logs.png # Screenshot of log issues β βββ problem_analysis.md # What was wrong with original β βββ Backtesting/ β βββ fixed_performance.md # Expected improvements β βββ validation_tests.md # Tests to verify fixes β βββ Documentation/ βββ mql5_syntax_fixes.md # Common MQL5 errors & fixes βββ debugging_guide.md # How to debug EA issues
issues
π QUICK START (For MT5) Installation: Copy EA to MT5:
Open MetaTrader 5
File β Open Data Folder
Navigate to MQL5/Experts/
Copy Cephas_GoldBot_Phase1_FIXED.mq5 here
Restart MT5
Attach to Chart:
Open XAUUSD M5 chart
Drag EA from Navigator to chart
Configure parameters (see below)
Click OK
Essential Parameters: Risk Management:
Lot_Size = 0.01 (Start small)
Use_Validation = true (CRITICAL - prevents errors)
Max_Daily_Loss = 100 (Stop trading if losing $100)
Max_Daily_Trades = 100 (Prevent overtrading)
Profit Protection:
Use_Smart_Breakeven = true
Breakeven_Trigger = 15 (Move to breakeven at +15 pips)
Use_Profit_Trailing = true
Trail_Trigger = 25 (Start trailing at +25 pips)
Systems:
System_1_Enable = true
System_2_Enable = true
Backtest: Open MT5 Strategy Tester (Ctrl+R)
Select Cephas_GoldBot_Phase1_FIXED
Symbol: XAUUSD
Timeframe: M5
Date Range: At least 3 months
Model: Every tick (most precise)
Click Start
π οΈ TECHNICAL IMPROVEMENTS Fixed Issues from Original: "Invalid stops" Errors: Added validation logic before modifying stops
Poor Exit Strategy: Added mean reversion exits and profit locking
No Profit Protection: Added trailing stops and breakeven movement
Overtrading: Added daily trade limits and time filters
Compilation Errors: Fixed MQL5 syntax and indicator calls
New Features: Stop Loss Validation: Checks minimum distance and price validity
Smart Breakeven: Moves SL to entry with buffer when profitable
Trailing Stops: Follows price to protect profits
Emergency Close: Exits if trade moves 1% against
Time-based Exit: Maximum hold time of 20 bars
Daily Reset: Clears counters at midnight
System Tracking: Monitors performance per system
Performance Expectations: Reduced Errors: No more "Invalid stops" in logs
Better Exits: Profits locked with trailing stops
Controlled Risk: Daily loss limits prevent blowouts
Consistent Execution: Validated entries and exits
π PERFORMANCE METRICS TO TRACK Log Analysis:
β No "failed modify" errors
β "Breakeven move applied" messages
β "Trailing stop applied" messages
β "Mean reversion complete - Profit: $" entries
β Daily P/L reporting
Backtest Metrics:
Win Rate: Target 40-50%
Profit Factor: Target 1.5+
Max Drawdown: < 10%
Average Win > Average Loss
π§ TROUBLESHOOTING Common Issues: EA Won't Compile:
Ensure using MQL5 (not MQL4) syntax
Check all indicator function calls
Verify semicolons and parentheses
No Trades Opening:
Check journal for "Trade blocked" messages
Verify symbol is XAUUSD
Check if systems are enabled
Ensure not at daily trade limit
Stop Loss Errors:
Enable Use_Validation = true
Increase Min_Stop_Distance
Check broker's minimum stop distance
Compilation Warnings:
Most warnings are fine if EA runs
Focus on fixing errors first
Update to latest MT5 build
Debug Mode: Set these for testing:
Use_Validation = false (temporarily)
Max_Daily_Trades = 999
Lot_Size = 0.01
Run on demo account first
π NEXT STEPS Phase 1.5: Optimization Fine-tune entry parameters
Optimize stop loss distances
Test different profit targets
Add more confirmation filters
Phase 2: Enhanced Systems Add volume confirmation
Implement order flow analysis
Add market structure detection
Include economic calendar filter
Phase 3: Machine Learning Pattern recognition
Adaptive parameters
Risk adjustment based on volatility
Performance prediction
π KEY LESSONS FROM FIXES What Was Wrong: No stop validation β "Invalid stops" errors
Poor exit strategy β Missed profits
No profit protection β Winners turned to losers
Overtrading β Compounded small losses
What's Fixed: Validated stops β No more broker rejections
Smart exits β Lock in mean reversion profits
Trailing protection β Ride trends, protect gains
Risk controls β Prevent overtrading and large losses
π‘ PRO TIPS Start Small: Use 0.01 lots until proven
Backtest Thoroughly: Minimum 3-6 months data
Monitor Logs: Watch for "Profit: $" messages
Paper Trade: 2 weeks minimum before live
Keep It Simple: Add complexity only if it improves results
π VERSION HISTORY v2.0 (Fixed) - February 2026
Fixed all compilation errors
Added stop loss validation
Implemented profit protection
Enhanced exit strategy
Added risk management controls
v1.0 (Original) - Issues:
"Invalid stops" errors
Poor exit timing
No profit protection
Compilation errors
π€ SUPPORT For Issues:
Check the compilation_fixes.md
Review EA parameters
Check MT5 journal
Test on demo first
Remember: Trading involves risk. This EA includes risk management, but past performance doesn't guarantee future results. Start with small position sizes and always use proper risk management.
Built with excellence for Cephas Nzaana Kampala, Uganda "From Errors to Excellence"
Last Updated: February 2026 Version: 2.0 Fixed Status: β COMPILES, β BACKTESTS, β NO INVALID STOPS