Files
LSTM-PPO-Reinforcement-Lear…/README.md
T

172 lines
4.4 KiB
Markdown
Raw Normal View History

2026-06-19 16:59:27 +02:00
# MT5 XAUUSD LSTM PPO Trading Bot
2026-06-19 16:59:27 +02:00
A MetaTrader 5 reinforcement learning trading bot for XAUUSD (Gold).
2026-06-19 16:59:27 +02:00
The bot combines an LSTM neural network for sequence learning with Proximal Policy Optimization (PPO) to learn trading decisions directly from historical market data.
2026-06-19 16:59:27 +02:00
Unlike traditional bots that rely on fixed rules, the PPO agent learns when to Buy, Sell or Hold from thousands of market examples.
The program should be in a folder or the desktop where the 5m csv file with OHLC data downloaded from dukascopy, 3 years. is, in training it will then make a LSTM-PPO-saves folder where the training is saved (used for making decisions, also in testing).
2026-06-19 17:01:42 +02:00
---
## Features
2026-06-19 16:59:27 +02:00
### Reinforcement Learning
- LSTM policy network
- PPO training
- Continuous online training
- Live inference on MT5
- Automatic checkpoint saving/loading
### Technical Indicators
- EMA 7
- EMA 21
- EMA Difference (Momentum)
- ADX
- +DI
- -DI
- Stochastic
- VWAP
- VWAP Bands
- VWAP Slope
- Volume Moving Average
### Smart Money Concepts
- Bullish Order Blocks
- Bearish Order Blocks
- Bullish Fair Value Gaps
- Bearish Fair Value Gaps
- Bullish Rejection Blocks
- Bearish Rejection Blocks
- Equal Highs
- Equal Lows
- Market Breaks
- Indecision Candles
### PPO State Features
Current state contains:
- OHLC
- EMA trend
- Momentum
- ADX trend strength
- DI Direction
- Stochastic
- VWAP
- VWAP Bands
- VWAP Position
- VWAP Slope
- Volume MA
- Order Blocks
- Fair Value Gaps
- Rejection Blocks
- Equal Highs/Lows
- Buy Score
- Sell Score
---
2026-06-19 16:59:27 +02:00
## Current Strategy
2026-06-19 16:59:27 +02:00
Current reward structure:
2026-06-19 16:59:27 +02:00
- Take Profit: 20 pips
- Stop Loss: 40 pips
- Risk/Reward: 1 : 0.5
2026-06-19 16:59:27 +02:00
The current focus is high-probability momentum trades rather than large swing trades.
---
2026-06-19 16:59:27 +02:00
## Training
2026-06-19 16:59:27 +02:00
The PPO agent trains continuously over historical MT5 data.
2026-06-19 16:59:27 +02:00
Example metrics during training:
2026-06-19 16:59:27 +02:00
- Win rate: 7085%
- Profit Factor: 1.53+
- Weekly performance: typically 1030R during training (varies by market conditions)
2026-06-19 16:59:27 +02:00
These figures are training statistics only and are not guarantees of future performance.
2026-06-23 20:34:42 +02:00
### Quarterly stats
## Weekly PPO Training Performance by Quarter
Training period: **~June 2024 June 1, 2026** (102 rolling weekly training windows)
| Period | Approx. Dates | Avg Weekly R | Avg PF | Avg Max DD | Avg Recovery Factor |
| ------ | ---------------------- | -----------: | -----: | ---------: | ------------------: |
| Q1 | Jun 2024 Sep 2024 | 6.20R | 1.10 | 8.80R | 2.04 |
| Q2 | Sep 2024 Dec 2024 | 7.39R | 1.12 | 9.80R | 2.25 |
| Q3 | Dec 2024 Mar 2025 | 16.89R | 1.25 | 8.14R | 5.42 |
| Q4 | Mar 2025 Jun 2025 | 43.73R | 1.29 | 10.81R | 9.20 |
| Q5 | Jun 2025 Sep 2025 | 36.54R | 1.38 | 8.94R | 8.72 |
| Q6 | Sep 2025 Dec 2025 | 75.07R | 1.38 | 8.62R | 19.42 |
| Q7 | Dec 2025 Mar 2026 | 164.37R | 1.82 | 7.23R | 54.69 |
| Q8* | Mar 2026 Jun 1, 2026 | 126.55R | 1.49 | 8.76R | 34.54 |
*Q8 contains the final 11 weeks of training.
### Observations
* Profit Factor increased from approximately **1.10** during the earliest training period to **1.41.8** in the later periods.
* Average weekly drawdown remained relatively stable between **7R and 10R** despite substantially higher returns.
* Recovery Factor improved significantly over time, indicating that profitability increased faster than drawdown.
* The strongest performance occurred during the final two quarters while maintaining comparable risk characteristics.
2026-06-23 20:34:42 +02:00
---
## Requirements
2026-06-19 16:59:27 +02:00
- Python 3.11+
- MetaTrader 5
- MetaTrader5
- pandas
- numpy
- torch
2026-06-19 16:59:27 +02:00
Install dependencies:
2026-06-19 16:59:27 +02:00
```bash
pip install MetaTrader5 pandas numpy torch
```
---
## Running
Train:
```bash
2026-06-21 08:21:33 +02:00
python mt5-xau-lstm-ppo-bot.py --train
2026-06-19 16:59:27 +02:00
```
Live trading:
```bash
2026-06-21 08:21:33 +02:00
python mt5-xau-lstm-ppo-bot.py --test
2026-06-19 16:59:27 +02:00
```
Train and trade simultaneously:
```bash
2026-06-21 08:21:33 +02:00
python mt5-xau-lstm-ppo-bot.py --train --test
2026-06-19 16:59:27 +02:00
```
To train download a m5 xauusd csv file form kaggle or dukascopy and place the folder in "download" relative to the directory the mt5-xau-lstm-ppo-bot.py is in.
---
## Disclaimer
2026-06-19 16:59:27 +02:00
This project is for educational and research purposes only.
2026-06-19 16:59:27 +02:00
Trading leveraged products involves substantial risk. Always test thoroughly on historical data and demo accounts before risking real capital.