MetaTrader 5 Expert Advisor for Supply & Demand Zone Trading on XAUUSD (Gold) with configurable risk management, time/day filters, auto SL/TP placement, and trade logging.
- π₯ Demand Zones: Formed after bullish streaks (β₯5 green candles).
- π€ Supply Zones: Formed after bearish streaks (β₯5 red candles).
- π Zone Expiry: Old zones automatically removed after configurable bars.
- π Automatic SL/TP: Stop-loss at zone edge, take-profit at 3Γ SL distance.
- π° Fixed Lot Sizing (configurable).
- π‘οΈ Minimum SL Buffer: Avoids trades with too-tight stop losses.
- β‘ One Trade per Zone: Prevents overtrading the same zone.
- π Session Management: Trade only within specified hours.
- π Day Filters: Enable/disable trading for each weekday.
- β³ Zone Retest Expiry: Avoids trading expired retests.
- π Zone Visualization: Supply (red) & Demand (blue) zones on chart.
- π SL/TP Markers: Lines drawn for each executed trade.
- π CSV Logging: Trades recorded in
TradeLog.csvwith time, type, price, SL, TP, and lots.
- Installation
- Quick Start
- Configuration
- Architecture
- Usage Examples
- Performance Notes
- Troubleshooting
- Contributing
- License
- MetaTrader 5 Terminal (build 2000+ recommended)
- Active demo or live account
- Windows, macOS, or Linux with MT5
-
Copy
XAUUSD_Zones_Trading.mq5into:MQL5/Experts/ -
Open MetaEditor and compile the file.
-
Attach the EA to a XAUUSD M5 chart in MT5.
-
Enable Algo Trading β .
- Open XAUUSD M5 chart.
- Attach
XAUUSD_Zones_TradingEA. - Adjust input parameters if needed.
- Watch zones and trades execute automatically.
| Parameter | Default | Description |
|---|---|---|
Lots |
0.25 | Fixed lot size per trade |
ZoneWidthLimit |
25 | Maximum width (points) of valid zone |
ZoneSpacingBars |
70 | Minimum spacing between zones |
ZoneHistory |
300 | Number of candles scanned for streaks |
EntryBuffer |
1.5 | Buffer (points) before entering a trade |
ZoneRetestExpiryBars |
50 | Bars before a zone expires |
MinSLBufferPips |
1.0 | Minimum SL distance in pips |
| Parameter | Default | Description |
|---|---|---|
StartHour |
9 | Start trading hour (broker time) |
EndHour |
18 | End trading hour (exclusive) |
TradeMonday |
true | Trade on Monday? |
TradeFriday |
true | Trade on Friday? |
TradeSunday |
false | Trade on Sunday? |
XAUUSD_Zones_Trading.mq5
β
βββ Zone Detection
β βββ Bullish/Bearish streak identification
β βββ Supply/Demand zone creation
β
βββ Trade Execution
β βββ Buy/Sell entries with SL/TP
β βββ Risk filter (min SL buffer)
β βββ One-trade-per-zone enforcement
β
βββ Visualization
β βββ Rectangle zones on chart
β βββ SL/TP lines
β
βββ Logging
β βββ TradeLog.csv (time, type, price, SL, TP, lots)
- Attach EA to XAUUSD M5.
- Zones auto-detected, trades executed with default parameters.
- Set
StartHour=8,EndHour=16. - EA trades only during London trading hours.
- Use
Lots=0.1,MinSLBufferPips=3.0. - Filters out small zones, safer trading.
- Optimized for XAUUSD on M5 timeframe.
- Risk/Reward ratio = 1:3 (configurable via code).
- Performance varies by broker, spread, and market conditions.
- Backtest before running live.
| Issue | Possible Fix |
|---|---|
| EA not trading | Check if Algo Trading is enabled |
| Zones not drawing | Ensure chart has enough history (ZoneHistory β₯ 300) |
| Trade skipped | SL distance below MinSLBufferPips |
| CSV not generated | Check MQL5/Files/TradeLog.csv permissions |
We welcome improvements!
- Fork the repo
- Create a feature branch (
git checkout -b feature/NewFeature) - Commit changes (
git commit -m "Add NewFeature") - Push branch (
git push origin feature/NewFeature) - Open a Pull Request
This project is licensed under the MIT License β see the LICENSE file for details.
- Supply & Demand trading methodology
- MetaTrader 5 API (MetaQuotes)
- Community contributions & testing
Email: Savilla171@gmail.com Linkedin: www.linkedin.com/in/sarano-tikhak