Strategy Autopsy Generator
The Strategy Tester's own results tab gives a balance number and a few headline stats, then throws away everything else the moment you close the window. This EA keeps the detail. The trading logic - a fast/slow MA cross with an ATR stop and target - is intentionally plain; the point of the submission is OnTester(), which MetaTrader calls exactly once when a test run finishes, with this run's own closed-trade history still available to read. OnTester() walks that history (filtered to this EA's own magic number and the chart's symbol) and computes win rate, profit factor, expectancy per trade, average and largest win/loss, longest consecutive win and loss streaks, average/shortest/longest trade duration, and a day-of-week profit breakdown. It also rebuilds an approximate drawdown figure from the running total of closed-trade profit in the order trades closed - explicitly documented as an approximation, since it is not the tick-by-tick equity curve and it ignores floating drawdown on anything still open when the test ended. Everything is written to a plain-text report plus a per-trade CSV, both under MQL4\Files\ (or MQL5\Files\ on the native MQL5 build), so a single test run leaves a readable post-mortem behind rather than a number that vanishes when the tester tab closes. Notes and limitations - The strategy itself is a teaching vehicle for the reporting layer, not a tuned system - do not expect it to be profitable out of the box. - OnTester() only fires at the end of a Strategy Tester run; running the EA live or on a demo chart never triggers the report (there is no equivalent "the run is over" moment outside the tester). - The drawdown figure is an approximation built from closed-trade sequence, not genuine tick-by-tick equity - see the full description. - Each run OVERWRITES the previous report pair; rename the files between runs if a history of separate autopsies is wanted. - No hardcoded contract size; lot sizing is fixed (InpFixedLots) and normalised to the symbol's MODE_LOTSTEP/MIN/MAXLOT.
Expert advisor · MT5 · v1.0 · Free
About Strategy Autopsy Generator
Strategy Autopsy Generator is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average and ATR. It has 12 settings, such as Fast ma period, Slow ma period and Ma method. MQL source code included.
Files in the download: StrategyAutopsyGenerator.ex5, StrategyAutopsyGenerator.mq5, StrategyAutopsyGenerator.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Fast ma period | 10 | Fast MA period |
| Slow ma period | 30 | Slow MA period |
| Ma method | MODE_EMA | MA method |
| Atr stop multiple | 2.0 | Stop distance, ATR multiples |
| Atr target multiple | 3.0 | Target distance, ATR multiples |
| Atr period | 14 | ATR period |
| Fixed lots | 0.10 | Fixed lot size |
| Magic number | 20260420 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Order-send attempts before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
| Report base name | StrategyAutopsyGenerator | Base filename for the report pair, written under MQL5\Files\ |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Moving Average · ATR · MT5 Expert Advisor · MQL5 Source Code