python Case study
MT5 Strategy Engine
Most strategy code answers when to enter and treats position size and exit as configuration. That is backwards: on a leveraged instrument the size and the exit determine the outcome far more than the entry does.
The business problem
A price-action rule that looks good on a single timeframe is usually reading noise. Worse, a strategy that treats risk as a parameter rather than as part of the signal will size the same on a marginal setup as on a strong one, which is how a run of ordinary losses becomes an account failure rather than a drawdown.
What I delivered
- A strategy engine combining price-action entry rules with risk sizing and exits as one unit rather than as separate concerns.
- ATR-based exits, so stop distance is a function of current volatility instead of a fixed number that is too tight in one regime and too loose in another.
- Multi-timeframe signal confirmation, so a setup on the trading timeframe is only acted on when the higher timeframe agrees.
- Position sizing derived from the stop distance and a fixed risk fraction, which makes every trade risk the same amount regardless of where the stop sits.
- Rules expressed explicitly enough to be evaluated, since a strategy you cannot state precisely is one you cannot test.
Technical approach
- Entry, size and exit are one decision. Separating them is what allows a system to take a large position on a weak signal, which is the failure that actually ends accounts.
- Volatility-scaled stops rather than fixed ones, because a fixed stop is implicitly a bet that volatility will not change, and it always does.
- Higher-timeframe confirmation is a filter that removes trades, and removing trades is usually where the improvement is. The instinct to add signals is the wrong one.
- Fixed fractional risk means the position size falls out of the stop distance automatically, so a wider stop cannot quietly become a larger loss.
Result and evidence
The engine produces trades where the risk per position is constant by construction and the exit adapts to volatility, and it declines setups the higher timeframe does not support.
Commercial value
On leveraged instruments, survival is the strategy. A system that cannot take an oversized loss is worth more than one with a better entry rule.
Readable implementation brief
implementation_brief {
project: "MT5 Strategy Engine"
platform: "MetaTrader"
unit_of_decision: "entry + size + exit together, never apart"
exits: "ATR-scaled; stop distance follows volatility"
sizing: "fixed fractional risk derived from stop distance"
filter: "higher-timeframe agreement required to act"
bias: "removing trades over adding signals"
}What this project shows
The decision I would defend is treating risk sizing as part of the signal. It is the difference between a system with a bad month and one with a bad month it does not recover from.
Multi-timeframe confirmation removes trades, and being comfortable shipping something that trades less is its own kind of discipline.