RepositoryPython
MT5-Automation-Labs

MT5-Automation-Labs/mt5-xauusd-bot

Python multi-strategy XAUUSD trading bot for MetaTrader 5: reads terminal data, runs technical strategies such as an HFT EMA scalper, and routes orders through a shared risk layer. Windows live trading, simulated macOS mode.

141sao
1fork
0issue
4lượt xem

mt5-xauusd-bot

A MetaTrader 5 trading system that reads market data from a local terminal, evaluates it with technical strategies, and submits orders through a shared risk layer.

Live order flow is built for Windows, where the official MetaTrader5 Python package can talk to the terminal. The macOS runner uses the same idea and falls back to a simulated book when that package is not available. Use a demo account until you have reviewed the strategy parameters and risk limits.

Requirements

  • Windows 10 or later, with the MetaTrader 5 terminal installed and logged in
  • Python 3.10 or newer
  • Automated trading enabled in the terminal before you expect orders to fill

Install

From the repository root:

py -3 -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
copy .env.example .env

Set these values in .env:

VariablePurpose
MT5_LOGINAccount number
MT5_PASSWORDAccount password
MT5_SERVERBroker server name
MT5_PATHOptional path to terminal64.exe
TRADING_SYMBOLDefault XAUUSD
TRADING_TIMEFRAMEDefault M5 for the standard bot
DEFAULT_LOT_SIZEDefault 0.01

The repository does not ship with a login or password. .env is ignored by git.

Run

Start the terminal, then from the repository root:

py -3 -m mt5bot.runners.main

On Windows you can also use scripts\launch.bat, which activates venv or trading_bot_env when one of those folders exists.

Enable automated trading in MetaTrader 5 before expecting fills: Tools → Options → Expert Advisors → Allow automated trading, or press Ctrl+E. If that switch is off, the bot can still compute signals while the terminal rejects orders. See docs/troubleshooting.md.

Runners

CommandWhat it does
py -3 -m mt5bot.runners.mainOne strategy, selected by active_strategy in mt5bot/config.py. Default is EMA crossover on M5.
py -3 -m mt5bot.runners.multi_strategy_botFive strategies on M1 XAUUSD, each with its own position cap.
py -3 -m mt5bot.runners.production_multi_strategyAggressive scalp and momentum breakout, with per-strategy position limits.
py -3 -m mt5bot.runners.optimized_multi_strategyThe five-strategy set with tighter loop and position handling.
py -3 -m mt5bot.runners.hft_main50 ms loop using mt5bot/config_hft.py and the HFT EMA scalper.
py -3 -m mt5bot.runners.data_collection_botRecords live bars and features under data/collected. Does not trade.
py -3 -m mt5bot.runners.data_collectorInteractive historical and tick export under data/ml/training.
py -3 -m mt5bot.runners.simple_data_collectionShorter one-second collection loop. Writes to data/ml.
py -3 -m mt5bot.macos.mac_multi_strategy_botmacOS entry point. Simulates fills when MetaTrader 5 cannot be imported.

Stop a runner with Ctrl+C. The multi-strategy runners write a performance snapshot to data/reports on shutdown.

Project layout

.
├── mt5bot/
│   ├── config.py              Standard session, risk, and strategy settings
│   ├── config_hft.py          Tighter settings for the high-frequency runner
│   ├── paths.py               Repository paths for logs and data
│   ├── core/                  Terminal connection, orders, and risk checks
│   ├── strategies/            Signal generators
│   ├── runners/               Processes you actually start
│   └── macos/                 macOS connector and runner
├── scripts/                   Windows launchers and the macOS setup script
├── tests/                     Offline strategy checks and speed probes
├── docs/                      Architecture, HFT notes, macOS setup, troubleshooting
├── data/                      Collected bars, ML exports, and performance reports
└── logs/                      Runtime logs

Strategies

Every strategy subclasses BaseStrategy and returns BUY, SELL, or no signal from OHLC bars.

StrategyModuleUsed by
EMA crossoverema_crossover.pyStandard bot, multi-strategy, optimized
RSI divergencersi_divergence.pyStandard bot
Bollinger scalpbollinger_scalp.pyStandard bot
Stochastic momentumstochastic_momentum.pyStandard bot
MACD signal crossmacd_signal_cross.pyStandard bot
Aggressive scalpaggressive_scalp.pyMulti-strategy, production, optimized
Momentum breakoutmomentum_breakout.pyMulti-strategy, production, optimized
Mean reversionmean_reversion.pyMulti-strategy, optimized
HFT EMA scalperhft_ema_scalper.pyMulti-strategy, optimized, HFT runner

Change the standard bot's strategy with STRATEGY_SETTINGS['active_strategy'] in mt5bot/config.py. The multi-strategy runners construct their own strategy list in code.

Risk defaults

mt5bot/config.py is the standard profile:

  • 1% of balance risked per trade
  • 5% maximum daily loss
  • 10% maximum drawdown
  • 15 open positions across the account
  • 5-pip stop and 10-pip target as the default gold distances
  • Trailing stop enabled

RiskManager and TradeManager read mt5bot/config.py for every Windows runner. mt5bot/config_hft.py supplies the HFT runner's loop interval (50 ms), timeframe (M1), and lot size. The position and loss caps written in config_hft.py are kept with that profile for reference; the shared risk layer does not load them yet. Read both files before running on a funded account. Per-strategy caps in the multi-strategy runners can be stricter than the global cap.

Logs and data

PathContents
logs/Runner logs
data/collected/Live collection bot output
data/ml/Feature exports for later research
data/reports/JSON snapshots written when a multi-strategy runner stops

data/reports/optimized_multi_strategy_performance_20250830_013000.json is a saved session file. It is a record of one run, not a performance target.

Tests

These checks do not send orders:

py -3 tests/test_strategies.py
py -3 tests/test_setup.py

test_setup.py loads .env and, on Windows, checks that the MetaTrader 5 package imports. tests/speed_test.py and tests/hft_debug.py time the live terminal path, so they need a running terminal.

macOS

pip3 install -r requirements-macos.txt
python3 -m mt5bot.macos.mac_multi_strategy_bot

scripts/deploy_macos.sh creates a virtual environment and writes run_mac_bot.sh in the repository root. Details are in docs/macos.md.

Further reading

Disclaimer

This software is for education and research. Trading foreign exchange and CFDs can lose the entire amount you commit, and more where your broker allows it. Nothing in this repository is a recommendation to trade. Review every order rule on a demo account first.

Contact

Telegram: t.me/teraus111

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryMQL5
MT5-Automation-Labs/mt5-gold-scalper-ea

MT5 gold (XAUUSD) M1 scalper EAs: Z-score mean reversion plus trend breakout, with dynamic equity risk tiers, session window, spread filter and cost-aware broker-side take-profit.

135
Oct 15, 2026
RepositoryPython
freqtrade/freqtrade

Free, open source crypto trading bot

57.4k
Nov 29, 2026
RepositoryPython
Significant-Gravitas/AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

188.2k
Nov 29, 2026
RepositoryTypeScript
morluto/rea

Reverse engineer anything with agents, from app behavior down to native binaries.

487.0k
Dec 2, 2026
RepositoryPython
je-suis-tm/quant-trading

Python quantitative trading strategies including VIX Calculator, Pattern Recognition, Commodity Trading Advisor, Monte Carlo, Options Straddle, Shooting Star, London Breakout, Heikin-Ashi, Pair Trading, RSI, Bollinger Bands, Parabolic SAR, Dual Thrust, Awesome, MACD

11.4k
Jun 20, 2026
RepositoryPython
jesse-ai/jesse

An advanced trading bot written in Python

8.8k
Nov 23, 2026
RepositoryPython
marketcalls/openalgo

The Open Source Trading Ecosystem for Everyone.

3.1k
Nov 30, 2026
RepositoryPython
coding-kitties/investing-algorithm-framework

Framework for quantitative trading. Complete framework for development, backtesting, and deploying automated trading algorithms and trading bots.

2.3k
Nov 28, 2026
RepositoryPython
Lumiwealth/lumibot

Python trading framework with AI agents that actually place the trade. Backtest, paper and live trade on 12 brokers: stocks, options, futures, forex, crypto and prediction markets.

2.3k
Nov 28, 2026