Skip to content

CephasNzaana/Cephas-GoldBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– 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

About

Mean reversion trading bot for XAUUSD (Gold) on MT5

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •