Golden-file testing compares the trade decisions of a modified Expert Advisor with an accepted run, so an unintended logic change appears as changed decisions. CDecisionRecorder writes each recorded request with run context and a tick hash, and CGfFile refuses truncated or malformed files. CGoldenCompare pairs rows by time and returns a verdict that separates changed decisions from different settings or ticks. Random execution delay made the tested runs differ, so compare runs with the same fixed delay or none.
When I change an Expert Advisor, I want to know whether its trades changed. The Strategy Tester answers with a summary: net profit, the number of trades, drawdown. A summary is a poor detector. Two small changes can cancel each other in the net result, and a summary never says which trade moved or why.
To show the problem, I wrote a small demo EA and then a second version of it, the way I usually tidy code. I moved the logic into functions and rewrote the lot calculation. I also planted two changes on purpose, of the kind that slip into such a refactor. The lot size uses MathRound() instead of MathFloor(), and the session check uses "<=" instead of "<" for the last hour. In a test from January to September 2026 on EURUSD H1, the final balance of the second version was 9,436.15 USD instead of 9,538.86 USD. That difference says that something changed. The balance does not say what changed.
Unit tests do not close this gap either. A unit test calls one function with inputs that the developer chose. The decisions of an EA come from thousands of bars, the state of the account, and the order of events, so a function can pass its tests while the EA trades differently.
General software testing has an answer for this, called golden-file testing, or snapshot testing. You record the output of a version that you accept, keep that file as the "golden" file, and compare the output of every new version with it. Any difference is either a defect or a change that you intended and must confirm.
This article implements the method for MQL5 Expert Advisors. The implementation consists of three include files:
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: Implementing Golden-File Regression Tests for Expert Advisors in MQL5.
When I change an Expert Advisor, I want to know whether its trades changed. The Strategy Tester answers with a summary: net profit, the number of trades, drawdown. A summary is a poor detector. Two small changes can cancel each other in the net result, and a summary never says which trade moved or why.
To show the problem, I wrote a small demo EA and then a second version of it, the way I usually tidy code. I moved the logic into functions and rewrote the lot calculation. I also planted two changes on purpose, of the kind that slip into such a refactor. The lot size uses MathRound() instead of MathFloor(), and the session check uses "<=" instead of "<" for the last hour. In a test from January to September 2026 on EURUSD H1, the final balance of the second version was 9,436.15 USD instead of 9,538.86 USD. That difference says that something changed. The balance does not say what changed.
Unit tests do not close this gap either. A unit test calls one function with inputs that the developer chose. The decisions of an EA come from thousands of bars, the state of the account, and the order of events, so a function can pass its tests while the EA trades differently.
General software testing has an answer for this, called golden-file testing, or snapshot testing. You record the output of a version that you accept, keep that file as the "golden" file, and compare the output of every new version with it. Any difference is either a defect or a change that you intended and must confirm.
This article implements the method for MQL5 Expert Advisors. The implementation consists of three include files:
Author: Ali Akbar