preview
Implementing Golden-File Regression Tests for Expert Advisors in MQL5

Implementing Golden-File Regression Tests for Expert Advisors in MQL5

MetaTrader 5 — Examples |
111 0
Ali Akbar
Ali Akbar

Contents

  1. Introduction
  2. Architecture
  3. What a decision file holds
  4. The recorder
  5. Reading a file strictly
  6. Pairing rows and the verdict
  7. Using the recorder in an EA
  8. Testing the module
  9. Results in the Strategy Tester
  10. Limitations
  11. What the checks do not cover
  12. Conclusion
  13. Attached files


Introduction

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:

  • CDecisionRecorder writes each trade request that the EA passes to its Record() method as one row of a CSV file. The file also holds the settings of the run and a hash of the ticks that the EA received in OnTick().
  • CGfFile reads such a file and refuses a file that is truncated, malformed, or out of order.
  • CGoldenCompare pairs the rows of two files by time and returns one of five verdicts: PASS, DIFF, DATA, CONTEXT, or FORMAT.

For the second version of the demo, the comparison reported 71 differences of two kinds. Each kind pointed at one of the two planted changes. A third version, with both changes undone, gave PASS.

The comparison is useful only if the same code produces the same decisions in repeated runs. I tested this on MetaQuotes-Demo (terminal build 6230) with EURUSD H1 from 2026.01.01 to 2026.10.01. The runs used two tick models: 1-minute OHLC and every tick based on real ticks. Without execution delay, repeated runs gave identical files. With the random delay of the tester, 35 of 40 runs on 1-minute OHLC matched the run without delay, while each of 10 real-tick runs differed from all the others. The numbers are in the Strategy Tester results below. The descriptions of the recorder, of the module tests, and of the tester results also include three mistakes of my own that the module found.

The checks of my own code consist of 88 unit checks, seven mutation runs, and a Python consistency check that repeats 63 comparisons with a second implementation of the pairing rule.

Several articles cover testing in MQL5. Article 22967 builds assertion macros for pure functions, 19154 adds a profiler and a minimal unit test runner, and 23070 audits the history data in Python. None of the ones I found compares the decisions of two versions of an EA over a test run.

The regression gate of article 17956 is the closest idea, because it also compares a new run with an accepted baseline. Its baseline holds timings of code sections and the status of unit tests. My golden file holds the trade requests that the EA sent. My own article 25141 uses a golden file too, but for model outputs on fixed input rows. In that setting the data cannot drift between two runs.

What I add consists of four parts. The unit of comparison is the stream of recorded trade requests of a whole tester run. Rows are paired by time, so an extra order does not shift the rows of later seconds. The context lines and the tick hash let the comparer report a difference of the compared settings or of the received ticks apart from a difference of the decisions. And I measured on one server how the execution delay settings of the tester affect repeatability.


Architecture

The core module consists of three include files: DecisionFile.mqh, DecisionRecorder.mqh, and GoldenCompare.mqh. The archive also contains three scripts, three versions of the demo EA, and the Python script golden_check.py. Fig. 1 shows how the parts work together.

Parts of the golden-file test

From the decisions of an EA to a verdict

The EA writes rows through CDecisionRecorder. CGfFile reads the golden file and the new file. CGoldenCompare pairs their rows and returns a verdict. The script golden_check.py repeats the pairing on the same files

Fig. 1. The EA writes rows through CDecisionRecorder. CGfFile reads the golden file and the new file. CGoldenCompare pairs their rows and returns a verdict. The script golden_check.py repeats the pairing on the same files

The recorder runs inside the EA. The comparer runs either in a script after the Strategy Tester run or in OnTester() at the end of the run. The OnTester() comparison runs only when the EA specifies a golden file. By default, both use the common Files folder (the FILE_COMMON flag). The testing documentation describes this folder as the way for local agents and the terminal to share files. A remote agent or an agent of the MQL5 Cloud Network works in its own sandbox, so a file that it writes does not reach the terminal. In optimization, passes on several agents would also write files of the same name at the same time. For these reasons, Begin() refuses to record in optimization, and the module is meant for single tester runs on a local agent.


What a decision file holds

A decision is a trade request that the EA sends: a buy, a sell, a close, or a stop change. A row holds the time, the kind, the symbol, the volume, the price, the stop loss, the take profit, and the retcode. A note field holds free text, such as the indicator values behind the decision.

A row holds information of two levels. The kind, the symbol, the volume, and the three prices describe the request. The request is the decision of the EA. The retcode is the answer of the trading environment (the trade server or the tester) to that request. When only the ret field of a pair differs, the request stayed the same and the trading environment answered differently. CompareRetcode(false) turns off the retcode comparison.

The file does not record the results of execution: the order and deal tickets, the fill price, a partial fill, the commission, and the slippage. The tester report lists the deals, and a fill depends on the execution model, not only on the code. Positions closed by the server at their stop loss or take profit are not decisions of the EA, so they are not rows either. A changed stop loss still shows up, in the row of the request that set it. When a later decision depends on a fill, the comparer reports that later decision, while the fill behind it is not a compared field. The demo EA therefore writes the fill price and the filled volume of each entry and close into the note. The execution delay results show how this helps to find the cause of a difference.

The first lines of a file from the demo EA look like this:

#golden_file,1
#context,InpFast,12
#context,InpSlow,48
#context,InpAtr,14
#context,InpSlAtr,1.5000
#context,InpTpAtr,2.5000
#context,InpBreakevenAtr,1.0000
#context,InpRiskPct,1.0000
#context,InpStartHour,7
#context,InpEndHour,20
#context,InpMagic,37001
#context,symbol,EURUSD
#context,period,PERIOD_H1
#context,deposit,10000.00
#context,currency,USD
#context,leverage,100
#context,mode,tester
#context,server,MetaQuotes-Demo
#context,build,6230
#context,margin_mode,ACCOUNT_MARGIN_MODE_RETAIL_HEDGING
#context,digits,5
#context,contract_size,100000
#context,tick_size,0.00001
#context,volume_min,0.01
#context,volume_max,500
#context,volume_step,0.01
#context,stops_level,0
#context,freeze_level,0
#context,calc_mode,SYMBOL_CALC_MODE_FOREX
#context,exe_mode,SYMBOL_TRADE_EXECUTION_MARKET
#context,filling,1
#context,spread_float,true
#context,swap_mode,SYMBOL_SWAP_MODE_POINTS
#context,swap_long,-0.7
#context,swap_short,-1
#info,version,1.00
#info,program,GoldenDemo_v1
time,seq,kind,symbol,volume,price,sl,tp,ret,note
2026.01.02 09:00:00,0,SELL,EURUSD,0.88,1.17436,1.17549,1.17248,10009,fill 1.17436 0.88 fast 1.17510 slow 1.17512 atr 0.00075
2026.01.02 09:31:40,0,MODIFY,EURUSD,0.88,1.17349,1.17436,1.17248,10009,

The first line names the format and its version. The #context lines must be equal in two files before their rows are compared. The EA adds one line for each input that can change a decision. Begin() adds the symbol, the timeframe, the deposit, the account currency, the leverage, whether the run was in the tester, the server, the terminal build, and the margin mode. Begin() also adds the trading conditions of the symbol that an EA can read, such as the contract size, the volume step, the stops level, and the swaps. The header above shows the full list. The build is context because a new build can change how the tester works. After a terminal update, the comparison stops with CONTEXT until you accept the change with IgnoreContext("build").

The #info lines are shown but never compared. The version of the EA is info, because a new version is the point of the comparison.

The context covers only the values that it lists. For some settings of a tester run, I found no MQL5 function that returns them: the tick model, the execution delay, the test dates, and the commission. They are not in the context, so the person who runs the tests has to keep them equal. A different tick model or other dates change the ticks that the EA receives, and the tester results show that the tick hash then differs. A delay setting is not always visible in the hash. On 1-minute OHLC, the runs with a fixed delay received the same ticks as the run without delay (see the execution delay results).

The file ends with a line that the recorder writes when the run ends:

#end,rows,111,ticks,1107179,data,30522FC18AC41632

The #end line holds three values. The row count lets the reader detect a truncated file. The tick count and the data hash describe the ticks that the EA received. The hash is FNV-1a over 64 bits. For every tick that reaches OnTick(), it takes seven fields: the time in milliseconds, the bid, the ask, and the last price in points, the volume, the real volume (volume_real), and the flags.

The hash describes the ticks received by the EA. These ticks are not always the same as the tick history of the period. In the tester with an execution delay, the EA received fewer ticks in my runs (see the execution delay results). If two runs use the same code and settings but receive different ticks, their decisions may differ for reasons unrelated to the code. The hash lets the comparer report that case. Two equal 64-bit hashes make equal ticks very likely, but they do not prove it, because two different tick sequences can have the same hash. The hash also has gaps. The hash covers one symbol, and it does not cover the order book, other symbols, or the bars before the start date that the indicators use.

Numbers are printed with the digits of the symbol for prices and with the digits of the volume step for volumes. The same decision then always gives the same text. Two runs of the same version with the same ticks and decisions therefore give identical files.


The recorder

An EA uses CDecisionRecorder in four steps. The EA adds context lines in OnInit(), calls Begin(), calls Tick() at the top of OnTick(), and calls Record() after each trade request. OnDeinit() or OnTester() calls End(). The recorder sees only these calls. A trade request that the code sends without a Record() call is not in the file, and the comparison cannot see it.

Tick() reads the last tick of the recorded symbol and passes it to AddTick(). AddTick() adds the tick to the hash:

//+------------------------------------------------------------------+
//| CDecisionRecorder::AddTick                                       |
//| Hashes seven fields of one tick: the time in milliseconds, bid,  |
//| ask and last in points, the volume, the real volume in units of  |
//| 1e-8, and the flags. Tick() calls it, tests call it directly.    |
//+------------------------------------------------------------------+
void CDecisionRecorder::AddTick(const MqlTick &t)
  {
   if(m_handle==INVALID_HANDLE)
      return;
   Fold((ulong)t.time_msc);
   Fold((ulong)(long)MathRound(t.bid/m_point));
   Fold((ulong)(long)MathRound(t.ask/m_point));
   Fold((ulong)(long)MathRound(t.last/m_point));
   Fold(t.volume);
   Fold((ulong)(long)MathRound(t.volume_real*1e8));
   Fold((ulong)t.flags);
   m_ticks++;
   m_tick_time=t.time;
  }

Fold() adds the eight bytes of a value to the hash:

//+------------------------------------------------------------------+
//| CDecisionRecorder::Fold                                          |
//| Adds the eight bytes of v to the FNV-1a hash, low byte first.    |
//+------------------------------------------------------------------+
void CDecisionRecorder::Fold(const ulong v)
  {
   for(int i=0; i<8; i++)
     {
      m_hash^=(v>>(8*i))&0xFF;
      m_hash*=GF_FNV_PRIME;
     }
  }

My first version of Record() stamped each row with TimeCurrent(). The demo EA calls Record() after the trade request, because the retcode is known only then. In the real-tick runs with random delay, the first entry was recorded between 1 and 11 seconds after the bar opened, with the same price in every run. The time that Record() read was later than the tick that led to the decision, by an amount in the range of the tester delay. The comparer reported each of those rows as one MISSING and one EXTRA decision. The time of a decision is the time of the tick that led to it, so Record() now takes the time of the last tick that Tick() saw:

//+------------------------------------------------------------------+
//| CDecisionRecorder::Record                                        |
//| Writes a decision with the time of the last tick that Tick()     |
//| hashed, the tick that led to the decision. TimeCurrent() is used |
//| only before the first tick. After a trade request in the tester  |
//| with execution delay, TimeCurrent() has already moved on by the  |
//| delay, so it is not the time of the decision.                    |
//+------------------------------------------------------------------+
bool CDecisionRecorder::Record(const string kind,const string symbol,const double volume,const double price,
                               const double sl,const double tp,const long ret,const string note="")
  {
   datetime when=(m_tick_time>0) ? m_tick_time : TimeCurrent();
   return(RecordAt(when,kind,symbol,volume,price,sl,tp,ret,note));
  }

RecordAt() takes an explicit time. Tests use RecordAt(), and an EA can use it when its decision belongs to a bar time rather than to a tick. Before it writes a row, RecordAt() applies the row checks of the reader. The function refuses a time of 0 or a time earlier than the last row, a kind with characters other than A-Z, 0-9, and the underscore, and an empty symbol. RecordAt() also refuses numbers that cannot be printed as plain decimals, such as NaN, and numbers longer than 32 characters:

//+------------------------------------------------------------------+
//| CDecisionRecorder::RecordAt                                      |
//| Writes a decision with an explicit time. Prices are printed with |
//| the symbol's digits and the volume with the digits of its step,  |
//| so the same decision always gives the same text. A row that the  |
//| row checks of CGfFile::Load() would refuse is not written: a     |
//| time before the last row or not after 1970, an invalid kind, an  |
//| empty symbol, or a number that does not print as a plain decimal |
//| (NaN, infinity, more than 32 characters).                        |
//+------------------------------------------------------------------+
bool CDecisionRecorder::RecordAt(const datetime time,const string kind,const string symbol,const double volume,
                                 const double price,const double sl,const double tp,const long ret,
                                 const string note="")
  {
   if(m_handle==INVALID_HANDLE || m_failed)
     {
      m_error=m_failed ? m_error : "Record() before Begin() or after End()";
      return(false);
     }
   if(!GfIsKind(kind))
     {
      m_error="kind '"+kind+"' is not 1 to 16 characters of A-Z, 0-9 and _";
      return(false);
     }
   if(time<=0 || !GfIsTime(TimeToString(time,TIME_DATE|TIME_SECONDS)))
     {
      m_error="time "+TimeToString(time,TIME_DATE|TIME_SECONDS)+" cannot be read back";
      return(false);
     }
   if(m_rows>0 && time<m_last)
     {
      m_error="time "+TimeToString(time,TIME_DATE|TIME_SECONDS)+" is earlier than the last row";
      return(false);
     }
   string sym=GfClean(symbol);
   if(sym=="")
     {
      m_error="symbol is empty";
      return(false);
     }
   Digits(symbol);
   string num[4];
   num[0]=DoubleToString(volume,m_vdigits);
   num[1]=DoubleToString(price,m_pdigits);
   num[2]=DoubleToString(sl,m_pdigits);
   num[3]=DoubleToString(tp,m_pdigits);
   string names[4]={"volume","price","sl","tp"};
   for(int k=0; k<4; k++)
      if(!GfIsNumber(num[k]))
        {
         m_error=names[k]+" '"+num[k]+"' is not a plain decimal number";
         return(false);
        }
   int seq=(m_rows>0 && time==m_last) ? m_seq+1 : 0;
   string row=StringFormat("%s,%d,%s,%s,%s,%s,%s,%s,%I64d,%s\n",TimeToString(time,TIME_DATE|TIME_SECONDS),seq,kind,
                           sym,num[0],num[1],num[2],num[3],ret,GfClean(note));
   if(!Write(row))
      return(false);
   m_seq=seq;
   m_last=time;
   m_rows++;
   return(true);
  }

A row that RecordAt() writes therefore passes the row checks of CGfFile::Load(). The whole file can still be refused. A run that never calls End() leaves no #end line. A failed write has the same effect, because Write() stops all later writes, and End() then closes the file without the #end line:

//+------------------------------------------------------------------+
//| CDecisionRecorder::Write                                         |
//| Writes text to the file. A failed write is kept in m_failed, and |
//| every later write and End() then leave the file without #end, so |
//| the reader refuses the file instead of comparing part of it.     |
//+------------------------------------------------------------------+
bool CDecisionRecorder::Write(const string text)
  {
   if(m_failed)
      return(false);
   ResetLastError();
   if(FileWriteString(m_handle,text)==0)
     {
      m_failed=true;
      m_error=StringFormat("write to %s failed, error %d",m_file,GetLastError());
      return(false);
     }
   return(true);
  }

In both cases, the reader refuses the file instead of comparing part of it. I did not cause a failed write in my tests, so this path is not tested. A file that is edited by hand or damaged on disk can break any rule of the strict reader described below, and the reader then refuses it. A hand edit that keeps every rule still loads, because the reader cannot tell who wrote a file.

The seq column counts the rows inside one second, starting at 0. A close and a new entry on the same bar share a second, and seq keeps their order.


Reading a file strictly

A golden file can be wrong in quiet ways. A tester run can stop before OnDeinit(), and an edited file can lose a column. CGfFile::Load() refuses each of the following cases with a FORMAT message and the line number:

  • the first line is not the format line of version 1
  • a #context or #info line appears after the column line, or a key appears twice
  • a required column is missing, or a column appears twice
  • a row has a different number of fields than the column line
  • a time, number, kind, or retcode does not have the expected form
  • a row is earlier than the row before it, or seq does not grow inside one second
  • the #end line is missing, its row count differs from the rows read, or text follows it

Columns are found by name, so a file whose columns are in another order still loads. The seq and note columns may be absent. Blank lines are ignored. The end of Load() holds the checks that need the whole file:

   if(state<2)
      return(Fail(0,"the file ends before its column line"));
   if(state==2)
      return(Fail(0,"the file has no #end line, so the run did not finish or the file was cut"));
   if(end_rows!=nrows)
      return(Fail(0,StringFormat("#end says %I64d rows, the file holds %d",end_rows,nrows)));


Pairing rows and the verdict

A plain line diff compares line 1 with line 1, line 2 with line 2, and so on. One extra order in the new file then shifts every later line, and every later line looks different. CGoldenCompare walks both files in time order instead. For each second, it pairs every golden row with an unused new row of the same kind and symbol. The comparer first looks for a new row with no field difference, and then takes the first remaining row in file order. A pair whose fields differ is CHANGED. A golden row without a partner is MISSING, and a new row without a partner is EXTRA.

//+------------------------------------------------------------------+
//| CGoldenCompare::CompareRows                                      |
//| Walks both files in time order. Inside each second a golden row  |
//| is paired with an unused new row of the same kind and symbol:    |
//| first with a row that has no field difference, then with the     |
//| first such row in file order. Unpaired golden rows are MISSING,  |
//| unpaired new rows are EXTRA, and a pair with a field outside     |
//| tolerance is CHANGED. When the paired rows come in another order |
//| of kinds, the second gets one ORDER difference.                  |
//+------------------------------------------------------------------+
void CGoldenCompare::CompareRows(void)
  {
   int ng=m_golden.Rows(),nn=m_new.Rows();
   int i=0,j=0;
   SGfRow g,n;
   while(i<ng || j<nn)
     {
      //--- the earliest second that is still open in either file
      datetime t=0;
      if(i<ng)
        {
         m_golden.Row(i,g);
         t=g.time;
        }
      if(j<nn)
        {
         m_new.Row(j,n);
         if(i>=ng || n.time<t)
            t=n.time;
        }
      int ge=i,ne=j;
      while(ge<ng && m_golden.Row(ge,g) && g.time==t)
         ge++;
      while(ne<nn && m_new.Row(ne,n) && n.time==t)
         ne++;
      //--- first pass: pairs without a field difference
      bool used[];
      int  partner[];
      ArrayResize(used,ne-j);
      ArrayInitialize(used,false);
      ArrayResize(partner,ge-i);
      ArrayInitialize(partner,-1);
      for(int a=i; a<ge; a++)
        {
         m_golden.Row(a,g);
         for(int b=j; b<ne; b++)
            if(!used[b-j] && m_new.Row(b,n) && Pairable(g,n) && Fields(g,n)=="")
              {
               partner[a-i]=b;
               used[b-j]=true;
               break;
              }
        }
      //--- second pass: the rest in file order
      for(int a=i; a<ge; a++)
        {
         if(partner[a-i]>=0)
            continue;
         m_golden.Row(a,g);
         for(int b=j; b<ne; b++)
            if(!used[b-j] && m_new.Row(b,n) && Pairable(g,n))
              {
               partner[a-i]=b;
               used[b-j]=true;
               break;
              }
        }
      //--- the differences of this second
      string gorder="",norder="";
      for(int a=i; a<ge; a++)
        {
         m_golden.Row(a,g);
         if(partner[a-i]<0)
           {
            AddDiff(GF_MISSING,g,g.line,0,Whole(g));
            continue;
           }
         gorder+=" "+g.kind+" "+g.symbol;
         m_new.Row(partner[a-i],n);
         string f=Fields(g,n);
         if(f=="")
            m_same++;
         else
            AddDiff(GF_CHANGED,g,g.line,n.line,f);
        }
      for(int b=j; b<ne; b++)
         if(m_new.Row(b,n))
           {
            if(used[b-j])
               norder+=" "+n.kind+" "+n.symbol;
            else
               AddDiff(GF_EXTRA,n,0,n.line,Whole(n));
           }
      if(m_order && gorder!=norder)
        {
         m_golden.Row(i,g);
         m_new.Row(j,n);
         AddDiff(GF_ORDER,g,g.line,n.line,"golden order"+gorder+" | new order"+norder);
        }
      i=ge;
      j=ne;
     }
  }

The pairing rule has three consequences that the unit checks cover. A decision whose kind changed, a buy that became a sell, gives one MISSING and one EXTRA row, not one CHANGED row. A row inserted in front of an equal row of the same kind in the same second gives one EXTRA row, because equal rows are paired first. When the paired rows of one second come in another order of kinds, the comparer adds one ORDER difference for that second. A close and an entry that swap places are an example, and for an EA this can be a real change of behavior. CompareOrder(false) turns this check off.

One case stays ambiguous. When two rows of the same kind and symbol in one second both change, the comparer pairs them in file order. The two CHANGED rows can then list field changes between rows that do not belong together. The seq column keeps the order of the rows, but it is not a key that identifies a decision across two runs.

Fig. 2 shows what the pairing did for version 2 of the demo. The version 2 file has seven extra rows, and each extra row moves the later rows of version 2 one place further from the line with the same number in the golden file.

How the rows of version 2 were paired

Offset between a golden row and the version 2 row paired with it

The offset is 0 until June and grows in steps to 7 by August, one step for each extra row. A plain line diff assumes an offset of 0 everywhere

Fig. 2. The offset is 0 until June and grows in steps to 7 by August, one step for each extra row. A plain line diff assumes an offset of 0 everywhere

The Python script counts the differences that three methods report for the same pairs of files:

rows golden=111 new=118 | position by position: 89 | difflib blocks: 71 | paired by time: 71

For version 2, a position-by-position comparison reports 89 differences and the pairing reports 71. The difflib module of Python also realigns the lines and reports 71 changed lines, but as blocks of text without the field names. For two runs of version 1 on different tick models, the pairing reports more differences than difflib, 139 against 103. A stop change that moved by a few seconds is one changed line for difflib and one MISSING plus one EXTRA row for the pairing.

Run() loads both files and decides the verdict:

//+------------------------------------------------------------------+
//| CGoldenCompare::Run                                              |
//| Loads both files and compares them. FORMAT: a file could not be  |
//| read. CONTEXT: a context value differs, rows are not compared.   |
//| DATA: the tick count or data hash differs. Rows are compared and |
//| counted, and the message names their count, but a difference     |
//| may come from the received ticks. DIFF: rows differ with equal   |
//| context and ticks. PASS: nothing differs.                        |
//+------------------------------------------------------------------+
ENUM_GF_VERDICT CGoldenCompare::Run(const string golden,const string fresh,const bool common=true)
  {
   ArrayResize(m_diffs,0);
   m_same=0;
   m_message="";
   m_golden_name=golden;
   m_new_name=fresh;
   m_verdict=GF_FORMAT;
   if(!m_golden.Load(golden,common))
     {
      m_message="golden file: "+m_golden.Error();
      return(m_verdict);
     }
   if(!m_new.Load(fresh,common))
     {
      m_message="new file: "+m_new.Error();
      return(m_verdict);
     }
   string ctx=CheckContext();
   if(ctx!="")
     {
      m_message="context differs: "+ctx;
      m_verdict=GF_CONTEXT;
      return(m_verdict);
     }
   CompareRows();
   bool same_data=(m_golden.Ticks()==m_new.Ticks() && m_golden.DataHash()==m_new.DataHash());
   if(!same_data)
     {
      m_message=StringFormat("tick data differs: golden %I64d ticks hash %s, new %I64d ticks hash %s | %s",
                             m_golden.Ticks(),m_golden.DataHash(),m_new.Ticks(),m_new.DataHash(),
                             GfCount(ArraySize(m_diffs),"row difference"));
      m_verdict=GF_DATA;
     }
   else
      m_verdict=(ArraySize(m_diffs)>0) ? GF_DIFF : GF_PASS;
   return(m_verdict);
  }

The verdicts are ordered by how serious they are, and Run() returns the most serious condition it finds.

Verdict Condition Rows compared
FORMAT A file is missing, truncated, or malformed No
CONTEXT A context value differs, or a context key exists in one file only No
DATA Context is equal, but the tick count or the data hash differs Yes, listed and counted in the message
DIFF Context and received ticks are equal, and at least one row differs Yes
PASS Nothing differs Yes

A verdict narrows down where to look, but the verdict alone does not name the cause. DIFF says that the decisions differ while the compared context and the received ticks are equal. The cause is often the code, but it can also be a setting outside the context, such as the commission or the execution delay. The cause can also be a file or a global variable of the terminal that the EA reads, or a change in the terminal that the build number does not show.

DATA says that the EA received other ticks. In my runs with the same history and tick model, this happened only with an execution delay. With a delay, the EA received fewer ticks, and the execution delay results explain why the number it missed may depend on its own trade requests. If so, a change of the code can change the received ticks too. A DATA verdict can therefore hide a change of behavior. For this reason, Run() still compares the rows under DATA, Differences() returns their count, and the message names it:

GOLDEN verdict DATA | golden GoldenFile\v1_ticks_r1.csv | new GoldenFile\v1_ticks_fix_r1.csv
GOLDEN tick data differs: golden 36657217 ticks hash 4D728E903928E4F8, new 36656913 ticks hash A2093A276879F146 | 63 row differences

A CONTEXT verdict skips the rows on purpose. Two runs with different inputs are expected to differ, and a list of their differences would only hide the reason. When a new version adds an input whose default keeps the old behavior, IgnoreContext() lets the comparison go ahead.

Prices and volumes are equal when they differ by no more than a tolerance, 0 by default. The note field is compared only when CompareNotes(true) is set. The retcode and the order of kinds are compared by default, and CompareRetcode(false) and CompareOrder(false) turn them off.


Using the recorder in an EA

The demo EA, GoldenDemo_v1.mq5, trades a crossover of two EMAs with a stop and a target in ATR units, a risk of 1% per trade, and a breakeven move. Its trading logic is only there to produce decisions. OnInit() of the demo prepares the recorder with the following lines:

   if(InpRecord)
     {
      //--- every input that changes a decision is context, file names are not
      g_rec.Context("InpFast",IntegerToString(InpFast));
      g_rec.Context("InpSlow",IntegerToString(InpSlow));
      g_rec.Context("InpAtr",IntegerToString(InpAtr));
      g_rec.Context("InpSlAtr",DoubleToString(InpSlAtr,4));
      g_rec.Context("InpTpAtr",DoubleToString(InpTpAtr,4));
      g_rec.Context("InpBreakevenAtr",DoubleToString(InpBreakevenAtr,4));
      g_rec.Context("InpRiskPct",DoubleToString(InpRiskPct,4));
      g_rec.Context("InpStartHour",IntegerToString(InpStartHour));
      g_rec.Context("InpEndHour",IntegerToString(InpEndHour));
      g_rec.Context("InpMagic",IntegerToString(InpMagic));
      g_rec.Info("version","1.00");
      if(!g_rec.Begin(InpRecordFile))
        {
         Print("recorder: ",g_rec.Error());
         return(INIT_FAILED);
        }
     }

File names are not context, because the golden run and the new run write different files. OnTick() starts with g_rec.Tick(), and each trade request is followed by a Record() call such as this one:

      g_trade.Buy(lots,_Symbol,px,sl,tp);
      g_rec.Record("BUY",_Symbol,lots,px,sl,tp,g_trade.ResultRetcode(),Filled(note));

The Filled() function puts the fill price and the filled volume of the trade result in front of the note:

//+------------------------------------------------------------------+
//| Filled                                                           |
//| The note with the price and volume of the last trade result in   |
//| front, so a fill that differs can be read in the decision file.  |
//| Notes are not compared unless CompareNotes(true) is set.         |
//+------------------------------------------------------------------+
string Filled(const string note)
  {
   return(StringFormat("fill %s %s %s",DoubleToString(g_trade.ResultPrice(),_Digits),
                       DoubleToString(g_trade.ResultVolume(),2),note));
  }

When the input InpGoldenFile names a file, OnTester() closes the decision file and compares it with the golden file at the end of the Strategy Tester run:

//+------------------------------------------------------------------+
//| OnTester                                                         |
//| Closes the decision file and, when a golden file is named,       |
//| compares the run with it. Returns the number of differences, or  |
//| -1 when the verdict is CONTEXT or FORMAT.                        |
//+------------------------------------------------------------------+
double OnTester(void)
  {
   g_rec.End();
   if(!InpRecord || InpGoldenFile=="")
      return(0.0);
   CGoldenCompare cmp;
   ENUM_GF_VERDICT v=cmp.Run(InpGoldenFile,InpRecordFile);
   cmp.Report(20);
   if(v==GF_CONTEXT || v==GF_FORMAT)
      return(-1.0);
   return((double)cmp.Differences());
  }

The return value of OnTester() is the number of differences, or -1 for CONTEXT and FORMAT. The verdict and the first differences go to the tester journal. The script CompareDecisions.mq5 does the same comparison for any two files and writes all differences to a diff CSV file. Its inputs are the two file names, the folder, and the price and volume tolerances. Three switches turn the comparison of notes, retcodes, and order on or off. Further inputs set the context keys to ignore, the number of differences to print, and the name of the diff file.

The workflow I use with these tools has five steps:

  1. Run the accepted version in the tester without execution delay and keep its decision file as the golden file.
  2. Change the code.
  3. Run the new version with the same symbol, timeframe, deposit, and inputs, and set InpGoldenFile. Also keep the test dates, the tick model, and the delay setting the same, because they are not part of the context.
  4. Read the verdict. For DIFF, start at the first difference and look for a pattern in the kinds and fields that changed.
  5. When every difference is intended, make the new file the golden file and write down why it changed.


Testing the module

Unit checks

TestGoldenFile.mq5 writes small decision files with fixed rows and fixed ticks into MQL5\Files\GoldenFile\test and runs 88 checks on them. The last line of the run:

TEST 88 passed, 0 failed
Group Checks What they cover
Recorder 39 Refused calls and refused rows, the hash of fixed ticks against values computed in Python, number formats, note cleaning, seq, the time stamp of Record(), and the header with the context keys of the symbol and the account
Loader 17 Every FORMAT rule of the strict reader, columns in another order, and files without the optional columns
Comparer 32 Each kind of difference including ORDER, pairing inside a busy second, tolerances, the switches for notes, retcodes, and order, context, data, the order of verdicts, empty files, and the diff CSV

Begin() writes the deposit and the margin mode of the account as context. In one of my runs, the first test file had a deposit of 0.00 and another margin mode than the later files. The comparisons stopped with CONTEXT, and 26 checks failed. These values suggest that the script started before the terminal had logged in to the account. The script now waits until the terminal is connected and the account values stay the same for one second, and the later runs passed.

Mutation runs

A test suite should fail when the code under test is wrong. The script mutate.py puts one defect at a time into the terminal's copy of an include file. The script compiles TestGoldenFile.mq5 with MetaEditor, runs it, prints the checks that failed, and restores the file. The script is in the archive, in MQL5\Files\GoldenFile. The script needs the path of the terminal data folder, and the terminal must be closed while it runs.

Mutant Defect Checks that failed
A Tolerance compared without the small relative margin 1
B Rows paired by time and symbol only, the kind ignored 1
C Tick count and data hash not compared 4
D A file without the #end line accepted 2
E No first pass for equal rows, pairing in file order only 1
F Order of kinds inside a second not checked 2
G Numbers written without the check that the reader applies 5

The run of the unmodified files after the last mutant reported 88 passed checks. Mutant A survived the first time. My tolerance check used the prices 1.04123 and 1.04124. In double precision their difference is 9.999999999843467e-06, below one point, so the comparison without a margin also passed. For 1.04301 and 1.04302 the difference is 1.0000000000065512e-05, above one point. I added a check with that pair, and the second mutation run caught mutant A.

Python consistency check

The script golden_check.py reads the decision files and the diff CSV of CompareDecisions.mq5 and pairs the rows again with its own code. For each comparison, the script prints its own verdict and counts, and then whether they match the MQL5 result. For version 2, the script printed:

python verdict DIFF | rows golden=111 new=118 same=47 changed=64 missing=0 extra=7 order=0
mql5   verdict DIFF | differences 71
verdicts equal: True | difference rows that do not match: 0

I ran the script on all 63 comparisons of the tester results. In every one, the verdict and the list of differences matched the MQL5 result.

The script also computes the FNV-1a hash of the fixed test ticks. Its values are the constants that the unit checks expect. The script implements the same rules as the MQL5 code, so it finds a slip in one implementation, not an error in the rules themselves. The agreement shows that the two implementations agree. The agreement does not show that pairing by second, kind, and symbol is the right model of a change of decisions.


Results in the Strategy Tester

All runs used EURUSD H1 from 2026.01.01 to 2026.10.01 on MetaQuotes-Demo, with build 6230. The deposit was 10,000 USD, and the leverage was 1:100. The demo EA ran with its default inputs, except the runs with a risk of 2% described under the test setup mistake below. Every run passed all inputs in its tester configuration file, for a reason explained under the test setup mistake below. The only exception is the second run described there, which leaves inputs out on purpose.

The same code twice

Three runs of version 1 with 1-minute OHLC and no delay wrote byte-identical files: 111 rows, 1,107,179 ticks, and the same SHA-256 checksum. Two runs with real ticks and no delay also wrote identical files, with 116 rows and 36,657,217 ticks. The comparison of the two models gave DATA, as it should, because the tick count and the hash differ:

GOLDEN verdict DATA | golden GoldenFile\v1_r1.csv | new GoldenFile\v1_ticks_r1.csv
GOLDEN tick data differs: golden 1107179 ticks hash 30522FC18AC41632, new 36657217 ticks hash 4D728E903928E4F8 | 139 row differences
GOLDEN rows golden=111 new=116 same=13 changed=62 missing=36 extra=41 order=0

Version 2 of the demo

The comparison of version 2 with the golden file of version 1 starts with these lines:

GOLDEN verdict DIFF | golden GoldenFile\v1_r1.csv | new GoldenFile\v2_r1.csv
GOLDEN rows golden=111 new=118 same=47 changed=64 missing=0 extra=7 order=0
GOLDEN 71 differences, the first 12 shown
GOLDEN CHANGED 2026.01.02 09:00:00 SELL golden line 39 new line 39: volume 0.88 -> 0.89
GOLDEN CHANGED 2026.01.02 09:31:40 MODIFY golden line 40 new line 40: volume 0.88 -> 0.89
GOLDEN CHANGED 2026.01.06 15:00:00 SELL golden line 41 new line 41: volume 0.60 -> 0.61

The 71 differences fall into two groups. All 64 CHANGED rows differ in the volume only, and always by one volume step: 50 rows by +0.01 lots and 14 by -0.01 lots. A difference of exactly one step in the volume and nothing else points at rounding in the lot calculation. The rows with -0.01 lots come later in the year. On the same bar both versions use the same stop distance, so a smaller lot in version 2 means a lower balance. By then MathRound() on the lower balance of version 2 gave one step less than MathFloor() on the balance of version 1. The seven EXTRA rows are four entries and three stop changes that belong to those entries. All four entries open at 20:00:

EXTRA,2026.06.02 20:00:00,SELL,0,104,SELL EURUSD 0.79 at 1.16283 sl 1.16417 tp 1.16061 ret 10009
EXTRA,2026.06.02 21:09:40,MODIFY,0,105,MODIFY EURUSD 0.79 at 1.16186 sl 1.16283 tp 1.16061 ret 10009
EXTRA,2026.07.07 20:00:00,SELL,0,124,SELL EURUSD 0.68 at 1.14235 sl 1.14383 tp 1.13988 ret 10009
EXTRA,2026.07.07 22:11:40,MODIFY,0,125,MODIFY EURUSD 0.68 at 1.14125 sl 1.14235 tp 1.13988 ret 10009
EXTRA,2026.08.06 20:00:00,SELL,0,134,SELL EURUSD 0.80 at 1.15207 sl 1.15332 tp 1.14998 ret 10009
EXTRA,2026.08.12 20:00:00,SELL,0,137,SELL EURUSD 0.62 at 1.15281 sl 1.15438 tp 1.15020 ret 10009
EXTRA,2026.08.13 07:20:40,MODIFY,0,138,MODIFY EURUSD 0.62 at 1.15205 sl 1.15281 tp 1.15020 ret 10009

Version 1 stops entries at 20:00, so an entry at 20:00 is outside its session. That pattern points at the session check. Fig. 3 shows where the differences fall in the test period.

Differences of version 2 against the golden file

One mark per decision, by type of difference

The volume changes are spread over the whole period, while the extra rows start in June

Fig. 3. The volume changes are spread over the whole period, while the extra rows start in June

Both planted changes were found from the report alone. Version 3 is version 2 with MathFloor() and "<" restored. Version 3 gave PASS against the golden file with all 111 rows paired.

Execution delay

The tester can add a delay between a trade request and its execution. The Strategy Tester help describes the random delay as 0 to 8 seconds in 90% of cases and 9 to 18 seconds in the other 10%. I ran version 1 with random delay 40 times on 1-minute OHLC and 10 times on real ticks. I also ran it twice with a fixed delay of 200 milliseconds on each model. Each run was compared with the run without delay on the same model.

Delay Model Runs Same ticks and decisions as without delay Same decisions, fewer ticks Different decisions
Fixed, 200 milliseconds 1-minute OHLC 2 2 0 0
Fixed, 200 milliseconds Real ticks 2 0 0 2
Random 1-minute OHLC 40 35 0 5
Random Real ticks 10 0 0 10

On 1-minute OHLC, the fixed delay changed nothing in these runs. Both runs received the same 1,107,179 ticks and wrote the same file as the run without delay. With random delay, 35 of the 40 runs did the same. In the other five runs, the EA received one tick fewer, and the comparer returned DATA with one CHANGED row. In all five, this row is the entry of 2026.07.14 at 17:00, with a volume one step lower.

On real ticks, the two runs with the fixed delay were identical to each other. Both received 304 ticks fewer than the run without delay and had 63 differences against it. Every run with random delay had 79 to 126 differences against the run without delay. I also paired the 10 random-delay runs with each other. None of the 45 pairs had the same decisions, and a pair had 51 to 133 differences:

files 10 | pairs 45 | pairs with no row difference 0 | differences per pair min 51 max 133

Differences per run with random delay

Each run against the run without delay on the same tick model

On 1-minute OHLC, 35 of the 40 runs show no difference and five runs show one difference. On real ticks, every run shows between 79 and 126 differences

Fig. 4. On 1-minute OHLC, 35 of the 40 runs show no difference and five runs show one difference. On real ticks, every run shows between 79 and 126 differences

The tick count in the #end line shows that the EA received fewer ticks in the runs with delay. The OnTick reference states that a NewTick event is not added to the queue while another one waits or is being processed. My explanation is that a trade request waiting for its delay keeps OnTick() busy, so the ticks that arrive in that time are not delivered. If this is right, the number of missed ticks depends on the trade requests of the EA. My runs show only that the delay and the lower tick count occur together. They do not show the mechanism, and I did not test it with a separate experiment.

Ticks the EA did not receive

Real ticks, against the 36,657,217 ticks of the run without delay

The 10 random-delay runs received between 3,421 and 4,291 ticks fewer than the run without delay, and both fixed-delay runs received 304 ticks fewer

Fig. 5. The 10 random-delay runs received between 3,421 and 4,291 ticks fewer than the run without delay, and both fixed-delay runs received 304 ticks fewer

Fig. 6 shows when the differences of the real-tick runs appear. In the fixed-delay run and in nine of the 10 random-delay runs, the first difference is the first stop change, on 2026.01.02 at 09:31:32. In the remaining random-delay run, it is the stop change of 2026.01.06. In the run with the fixed delay, the stop moved to 1.17432 instead of 1.17436, and 13 seconds later:

GOLDEN MISSING 2026.01.02 09:31:32 MODIFY golden line 40 new line 0: MODIFY EURUSD 0.88 at 1.17360 sl 1.17436 tp 1.17248 ret 10009
GOLDEN EXTRA 2026.01.02 09:31:45 MODIFY golden line 0 new line 40: MODIFY EURUSD 0.88 at 1.17356 sl 1.17432 tp 1.17248 ret 10009

The stop change is only the first effect. Its cause is the fill of the entry before it, and the fill is not a compared field. With CompareNotes(true), the comparer also compares the notes, where Filled() wrote the fill price. The first difference is then the entry itself, which filled at 1.17432 instead of 1.17436:

GOLDEN tick data differs: golden 36657217 ticks hash 4D728E903928E4F8, new 36656913 ticks hash A2093A276879F146 | 93 row differences
GOLDEN rows golden=116 new=115 same=36 changed=66 missing=14 extra=13 order=0
GOLDEN 93 differences, the first 12 shown
GOLDEN CHANGED 2026.01.02 09:00:00 SELL golden line 39 new line 39: note fill 1.17436 0.88 fast 1.17510 slow 1.17512 atr 0.00075 -> fill 1.17432 0.88 fast 1.17510 slow 1.17512 atr 0.00075

With notes compared, the count grows from 63 to 93. The 30 added rows differ only in the fill price in the note. From the first stop change on, the differences grow through the whole period.

Differences accumulated over the test period

Real ticks, each delay run against the run without delay

All 11 lines start with a stop change in January and rise through the period. The fixed-delay run ends at 63 differences, and the random-delay runs end between 79 and 126

Fig. 6. All 11 lines start with a stop change in January and rise through the period. The fixed-delay run ends at 63 differences, and the random-delay runs end between 79 and 126

These results come from one server, one build, one symbol and timeframe, and one demo EA. In these runs, no execution delay gave repeatable files on both models, and two runs with the same fixed delay were identical to each other. Random delay gave repeatable files on 1-minute OHLC in 35 of 40 runs, and on real ticks in none. For my own golden-file tests, I therefore record without delay or with one fixed delay. On another server, build, symbol, or EA, two runs with the chosen setting show whether it is repeatable there. A random delay remains useful for testing an EA under delay, but not for a comparison with a golden file. A model with fewer ticks, such as 1-minute OHLC, hid most effects of the delay in these runs. Such a model also tests less of what a delay does to an EA.

A test setup mistake that the context lines caught

My first batch of runs included one run of version 1 with InpRiskPct set to 2.0, a run meant to produce a CONTEXT verdict. My tester configuration files listed only the inputs that a run changed. In my runs, the tester kept the value of an input that the configuration file did not list from the previous run of the same EA. Every later run of version 1 in that batch therefore traded with a risk of 2%. I did not notice until the comparisons of the delay runs came back with CONTEXT instead of PASS or DATA.

The logs of that batch are gone, so I reproduced the leak with two runs. The first run lists every input and sets InpRiskPct to 2.0. The configuration file of the second run lists only InpRecordFile. The journal of the second run shows the leaked value among its inputs:

  InpRiskPct=2.0

The comparison of the second run with the golden file gives:

GOLDEN verdict CONTEXT | golden GoldenFile\v1_r1.csv | new GoldenFile\leak_step2_partial.csv
GOLDEN context differs: InpRiskPct 1.0000 -> 2.0000

Without context lines, the comparer would have compared the rows. The intended 2% run, compared with the golden file with its context ignored, has all 111 rows CHANGED:

context and data ignored | rows golden=111 new=111 same=0 changed=111 missing=0 extra=0 order=0

In the delay runs, differences like these would have looked like an effect of the delay. Since then, my run script passes every input on every run.

Cost

BenchRecorder.mq5 times the recorder and the comparer outside the tester, as the median of five rounds:

BENCH 5 rounds | AddTick 35.3 ns per tick | RecordAt 3693 ns per row | compare of 2 files with 100000 rows 1661 ms
BENCH file size of 100000 rows: 7600843 bytes

At about 35 nanoseconds per tick for seven fields, hashing the 36,657,217 real ticks of the test period costs about 1.3 seconds of processor time. A row costs a few microseconds, and the demo wrote 116 rows on real ticks in nine months. A file of 100,000 rows takes 7.6 MB, and comparing two such files took 1.7 seconds.

I also timed three tester runs on real ticks with the recorder and three without it, in alternating order. The runs with the recorder took 8.1 to 9.2 seconds, and the runs without it took 6.2 to 7.1 seconds. The medians differ by about 2 seconds, which is more than the hash cost above. Tick() also calls SymbolInfoTick() on every tick, and BenchRecorder does not time that call. With three runs per side and a spread of about one second within each side, this is a rough estimate of the cost, not a precise measurement.


Limitations

All numbers come from one server, one terminal build, one symbol, one timeframe, and one demo EA. Other servers, tick histories, and builds may give other results, in particular for the execution delay.

The recorder covers the decisions that the EA passes to Record(). A trade request that the code sends without a Record() call is invisible to the comparison. A row holds the request and the retcode, but not the fill, so a difference of execution shows up only through the later decisions that depend on it. The hash covers seven fields of the ticks of one symbol that the EA received in OnTick(). A multi-symbol EA needs the ticks of every symbol it trades, and the module does not provide that today.

The context covers the inputs that the EA lists and the account and symbol values that Begin() adds. Four settings are not in the context: the tick model, the execution delay, the test dates, and the commission. I found no MQL5 function that returns them. An input left out of the context, a global variable of the terminal, a file that the EA reads, or the history of indicators before the start date can also change decisions without a CONTEXT verdict.

The time of a row has a resolution of one second. Inside one second, rows are paired by kind and symbol, equal rows first. When two rows of the same kind and symbol in one second both change, the pairing in file order can attach the changes to the wrong pair.

A tester run in which OnDeinit() and OnTester() are not reached leaves a file without the #end line, and the comparer refuses it. The comparer does not rebuild such a file. Begin() refuses to record in optimization, and I did not test the module with remote agents.

FNV-1a is a fast hash, not a cryptographic one. The hash detects accidental changes of the received ticks with a high probability, not with certainty. The hash is not meant to detect a deliberate edit of a file.


What the checks do not cover

The checks do not show that a golden file holds correct decisions. A golden file only freezes the behavior of the version you accepted, defects included. The checks do not cover live trading. In live trading, ticks and fills differ from run to run by nature. They do not cover other execution modes of the tester, custom symbols, exchange symbols, remote agents, or optimization. A failed write was never caused in a test. The mutation runs cover seven defects that I chose, so a defect of another kind may pass the unit checks. The Python script repeats the pairing rule, so it cannot detect a wrong rule.


Conclusion

CDecisionRecorder and CGoldenCompare turn a tester run into a list of recorded decisions that can be compared with an accepted run. On the demo EA, the comparison found two planted changes through the patterns of its report: a volume change of one step pointed at rounding, and entries at 20:00 pointed at the session hour. The context lines found two mistakes in my own test setup, and the tick hash showed when the EA had received other ticks. A verdict narrows down where to look, while the cause still has to be found in the report.

On MetaQuotes-Demo, with build 6230, EURUSD H1, and the demo EA, runs without execution delay were repeatable. Two runs with the same fixed delay were also identical to each other. With random delay on real ticks, no two of the 10 runs gave the same decisions. If you use the module, record a golden run of your EA without delay and check with a second run that your setup repeats. List every input that changes a decision as context, and compare every new version before you look at its profit.

Attached files

File Location Contents
DecisionFile.mqh MQL5/Include/GoldenFile/ The row structure, the format checks, and CGfFile, the strict reader of decision files
DecisionRecorder.mqh MQL5/Include/GoldenFile/ CDecisionRecorder, which writes decision files and hashes ticks
GoldenCompare.mqh MQL5/Include/GoldenFile/ CGoldenCompare, the verdict and difference types, and the report and diff CSV
CompareDecisions.mq5 MQL5/Scripts/GoldenFile/ Compares two decision files and writes the diff CSV
TestGoldenFile.mq5 MQL5/Scripts/GoldenFile/ 88 unit checks of the three include files
BenchRecorder.mq5 MQL5/Scripts/GoldenFile/ Times AddTick(), RecordAt(), and a comparison
GoldenDemo_v1.mq5 MQL5/Experts/GoldenFile/ Demo EA, version 1, the accepted behavior
GoldenDemo_v2.mq5 MQL5/Experts/GoldenFile/ Demo EA, version 2, a refactor with the two planted changes
GoldenDemo_v3.mq5 MQL5/Experts/GoldenFile/ Demo EA, version 3, version 2 with both changes undone
golden_check.py MQL5/Files/GoldenFile/ Python consistency check of the pairing, the verdicts, and the tick hash
mutate.py MQL5/Files/GoldenFile/ Python script for the mutation runs described in the module tests
MQL5.zip Attachment All files above, with the folder structure of the terminal
Attached files |
DecisionFile.mqh (18.02 KB)
GoldenCompare.mqh (20.08 KB)
TestGoldenFile.mq5 (25.84 KB)
BenchRecorder.mq5 (3.65 KB)
GoldenDemo_v1.mq5 (10.29 KB)
GoldenDemo_v2.mq5 (12.73 KB)
GoldenDemo_v3.mq5 (12.7 KB)
golden_check.py (12.18 KB)
mutate.py (5.1 KB)
MQL5.zip (39.02 KB)
Gating Trades with the Wald-Wolfowitz Runs Test: An O(1) Randomness Filter for Bar Direction Gating Trades with the Wald-Wolfowitz Runs Test: An O(1) Randomness Filter for Bar Direction
A rolling Wald–Wolfowitz runs-test engine classifies recent bar direction as persistent, alternating, or indistinguishable from noise before any entry logic is applied. The package includes full MQL5 source, a chart indicator, a three-mode Expert Advisor (Gated, No gate, Placebo), validation scripts, and an audit log. An 18‑run Strategy Tester matrix with fixed window and critical value, plus a null‑rate calibration on real history, shows how a regime gate changes trade frequency and drawdown.
Neural Networks in Trading: Difference-Based Modeling of Market Microstructure (Conclusion) Neural Networks in Trading: Difference-Based Modeling of Market Microstructure (Conclusion)
The article provides a detailed analysis of the practical implementation of the EDCFlow framework's concepts using MQL5 and their validation using real historical data. It demonstrates how a neural network model forms an internal representation of the market environment, processes correlations among features, and makes trading decisions without hand-crafted rules. The test results reveal not only the approach's potential but also its weaknesses, honestly identifying its limitations and areas for further development.
Volatility Sizing Under Controlled Stress in MQL5 (Part 2): Heavy Tails, Outliers, and Risk Recovery Volatility Sizing Under Controlled Stress in MQL5 (Part 2): Heavy Tails, Outliers, and Risk Recovery
We study how additive, transient outliers affect volatility estimates and next‑bar sizing when the Part 1 rules remain fixed. Using standardized Student‑t returns and paired stress paths, we evaluate capped exposure under both base and complete‑return conditional risk. The article provides an MQL5 script and a CSV audit to reproduce decisions and verify results.
Your Take Profit Is a Guess Until You Log MFE: Building an Excursion Recorder in MQL5 Your Take Profit Is a Guess Until You Log MFE: Building an Excursion Recorder in MQL5
A compact MFE/MAE recorder in pure MQL5 samples excursion while a position is open and writes one CSV row per closed position, measured in R and frozen at entry. A companion script prints a reach-rate table per asset class: the share of trades that ever reached each level. In a 226-position sample, three of the four classes never reached the 3R target the system was using. Use it to test whether a target is reachable before trusting it.