M5 momentum FVG scalping bot for MetaTrader 5. Detects 3-candle impulse patterns that leave a Fair Value Gap, enters on limit orders back into the zone, and manages SL/TP automatically.
## Strategy
1.**Impulse detection** — a candle whose body ≥ `BODY_PCT_MIN` of its range, closing in the top/bottom `CLOSE_PCT_MIN` fraction
2.**FVG zone** — the gap between the pre-impulse candle and the post-impulse candle must be ≥ `MIN_FVG_PIPS`
3.**EMA filter** — trade only in the direction of the `EMA_PERIOD`-bar trend
4.**Entry** — limit order at the FVG zone edge; expires after `FVG_EXPIRY_CANDLES` bars if unfilled
5.**SL** — at the structural extreme of the impulse candle ± `SL_BUFFER`
6.**TP** — `MIN_RR × SL distance` from entry
## Requirements
- Rust (stable, 2024 edition)
- [MT5 HTTP Bridge](https://github.com/romysaputrasihananda/mt5-bridge) running and reachable at `MT5_BASE_URL`
## Setup
```bash
cp .env.example .env
# edit .env — set MT5_BASE_URL and your preferred params
```
## Usage
### Backtest
```bash
cargo run --release
```
Runs a walk-forward simulation over the last `BACKTEST_CANDLES` M5 bars and prints a summary.
### Live trading
```bash
LIVE=true cargo run --release
```
Polls MT5 every `LIVE_POLL_SECS` seconds. Places a pending limit order when a valid FVG is detected; cancels it when the setup expires. Uses magic number `19730` to identify its own orders and positions.
State for each symbol is persisted in `.ares_state_{symbol}.json` so the bot survives restarts without orphaning orders.