Building an MQL5 Trade Replay Tool for Visual Review of Backtest Trades
Summary
This article explains how to build an MQL5 script that reconstructs closed trades from deal history and displays them in their original chart context. Entry and exit times, stop-loss and take-profit levels, and a trade annotation are drawn as chart objects. Keyboard navigation steps through the history one trade at a time, with the chart repositioned around the selected trade. The annotation includes measures such as duration, pip result, and R-multiple to support comparisons across trades.
The implementation joins entry and exit deals by position identifier, combines profit from partial closes, and falls back to order history when deal records lack stop or target values. It also describes prefixed object names for safe cleanup, keyboard polling and debouncing in a script, and derived trade statistics. Visual replay can reveal entry context, price paths, and stop behavior that aggregate backtest metrics hide, but it is a review aid rather than proof of strategy quality. The article notes limitations: chart symbol and timeframe, locally available history, original stop and target values, and chart focus for key detection.
Key ideas
- Closed MQL5 positions must be reconstructed by joining entry and exit deals that share a position identifier.
- Partial exits require aggregating realized profit and using the final exit time.
- Chart objects can show trade levels and outcomes while keyboard navigation supports sequential review.
- R-multiple normalizes results by initial risk, enabling comparisons across trade sizes and stop distances.
- Replay reveals individual trade context, but its usefulness depends on available history and stored trade details.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.