A production-ready desktop trading application that replicates TradingView Pine Script strategy logic with MetaTrader 5 integration.
This application implements a LONG ONLY Double Bottom pattern trading strategy for XAUUSD (Gold) on the 1-hour timeframe. It faithfully reproduces Pine Script trading logic while providing automated execution capabilities through MetaTrader 5.
- โ Pattern Detection: Automated Double Bottom pattern recognition
- โ Risk Management: Fixed % risk per trade with position sizing
- โ MT5 Integration: Real-time data and order execution
- โ Desktop UI: PySide6-based trading dashboard
- โ Demo Mode: Test strategies safely before live trading
- โ Comprehensive Logging: All decisions and trades logged
- โ State Persistence: Trade history and positions saved
- Python: 3.10 or higher
- MetaTrader 5: Installed and configured
- Operating System: Windows (MT5 Python API requirement)
cd C:\Users\mutaf\TRADINGpython -m venv venv
.\venv\Scripts\Activate.ps1pip install -r requirements.txtEdit config/config.yaml:
mt5:
login: YOUR_ACCOUNT_NUMBER # Or null to use current login
password: YOUR_PASSWORD # Or null
server: YOUR_BROKER_SERVER # Or null
symbol: "XAUUSD"
timeframe: "H1"python src/main.py-
Connect to MT5
- Ensure MetaTrader 5 is running
- Log in to your demo/live account
- Click "Start Trading" in the application
-
Configure Strategy
- Go to "Settings" tab
- Adjust risk %, ATR multiplier, R:R ratio
- Save settings
-
Monitor Trading
- "Market Data" tab shows current price and indicators
- "Position" tab displays open trades
- "History" tab shows past performance
- "Logs" tab shows all decisions
mode:
demo_mode: true # Keep true for demo account
auto_trade: false # Set true to enable automatic tradingsrc/
โโโ engines/ # Core trading logic
โ โโโ market_data_service.py # MT5 data fetching
โ โโโ indicator_engine.py # EMA, ATR calculations
โ โโโ pattern_engine.py # Double Bottom detection
โ โโโ strategy_engine.py # Entry/exit conditions
โ โโโ risk_engine.py # Position sizing
โ โโโ execution_engine.py # MT5 order execution
โ โโโ state_manager.py # State persistence
โโโ ui/ # User interface
โ โโโ main_window.py # PySide6 GUI
โโโ utils/ # Utilities
โ โโโ config.py # Configuration management
โ โโโ logger.py # Logging system
โโโ main.py # Application entry point
Entry Conditions (ALL must be true):
- โ Valid Double Bottom pattern detected
- โ Close breaks above neckline
- โ Close > EMA50 (trend filter)
- โ Breakout candle has momentum (ATR-based)
- โ Cooldown period respected
Exit Conditions:
- Stop Loss: ATR-based or swing low
- Take Profit: Risk ร R:R ratio
risk_amount = equity ร risk_percent
position_size = risk_amount / abs(entry_price - stop_loss)pytest tests/ -v# Test indicator engine
python src/engines/indicator_engine.py
# Test pattern engine
python src/engines/pattern_engine.py
# Test strategy engine
python src/engines/strategy_engine.pyTo validate against historical data:
- Export XAUUSD H1 data from TradingView to CSV
- Place CSV in
data/historical/ - Run backtest script:
python scripts/backtest.py --data data/historical/XAUUSD_H1.csv| Parameter | Default | Description |
|---|---|---|
risk_percent |
1.0% | Risk per trade |
atr_multiplier_stop |
2.0 | ATR multiplier for SL |
risk_reward_ratio |
2.0 | R:R for TP |
momentum_atr_threshold |
0.5 | Min momentum filter |
cooldown_hours |
24 | Hours between trades |
equality_tolerance |
2.0% | Double Bottom tolerance |
- โ Demo mode by default
- โ Manual confirmation for auto-trade
- โ Maximum drawdown limits
- โ Position size constraints
- โ Cooldown periods between trades
- Always start in demo mode
- Validate with historical data first
- Use small risk % for live trading (0.5-1%)
- Monitor the first 10-20 trades closely
- Never leave auto-trade unattended initially
- Total trades
- Win rate %
- Total profit/loss
- Average win/loss
- Profit factor
- Maximum drawdown
- System logs:
logs/system.log - Trade logs:
logs/trades.log - State file:
data/state.json
-
"MT5 initialization failed"
- Ensure MetaTrader 5 is running
- Check you're logged in to an account
- Verify Python and MT5 are same architecture (64-bit)
-
"Symbol XAUUSD not found"
- Enable XAUUSD in MT5 Market Watch
- Verify symbol name with your broker
-
"Insufficient data"
- Wait for more bars to load
- Requires 250+ bars for EMA200
-
UI not responding
- Check logs for errors
- Restart application
- Verify all dependencies installed
# Edit config
notepad config\config.yaml
# Restart application to apply changes# System logs
Get-Content logs\system.log -Tail 50
# Trade logs
Get-Content logs\trades.log -Tail 20The strategy logic is based on TradingView Pine Script specifications. All indicator calculations match TradingView's implementation:
- EMA:
ta.ema(source, length) - ATR:
ta.atr(length) - Pivot Lows:
ta.pivotlow(source, leftbars, rightbars)
This software is for educational purposes only.
- Trading involves substantial risk of loss
- Past performance does not guarantee future results
- Always test thoroughly in demo mode
- Never risk more than you can afford to lose
- The authors assume no liability for trading losses
This project is provided as-is for personal use.
For issues or questions:
- Check the logs in
logs/directory - Review configuration in
config/config.yaml - Ensure all dependencies are installed
- Verify MT5 connection is active
Version: 1.0.0
Last Updated: January 2026
Trading Mode: LONG ONLY
Instrument: XAUUSD
Timeframe: 1H