Bland-Altman Analysis for MQL5: Agreement Between Strategy Tester Modes (Real Ticks vs 1 Minute OHLC).
Contents
- Introduction
- What Bland-Altman Actually Checks
- The Statistics Engine
- Pairing Trades: the Logging EA
- Reading the Agreement: the Dashboard
- Logging and Pairing Pitfalls
- Results Across Four Symbols
- Reading the Numbers Honestly
- Limitations and What This Data Can't Tell You
- Conclusion
Introduction
Every EA developer goes through the same ritual. Build a strategy, backtest it, get attached to the equity curve, then watch the numbers move once you change how the tester models execution. Most of us assess that drift visually, shrug at a slightly lower win rate or a smaller average trade, and move on. The problem is that a visual read throws away the one question that matters: is that drift just noise, or is it telling you something real about how sensitive your results are to execution-model assumptions?
Bland-Altman analysis was introduced in 1986 in a different field, but the same setup applies here: medical researchers needed a way to compare two measurement devices when neither one could serve as the "true" reference value, and this article uses the same method to compare two MetaTrader 5 Strategy Tester execution models, "Every tick based on real ticks" and "1 Minute OHLC", run on the same strategy, symbol and date range (the full tester configuration is listed in the Results Across Four Symbols section). Neither model is ground truth; both are trying to approximate what really would have happened, from two different simulation assumptions. What the method gives you is a bias estimate, a spread estimate, and a pair of limits telling you how far apart the two models' readings can land on any single trade.
Scope note: everything in this article, including the four result sets below, comes from Strategy Tester runs. None of it is a live account, a demo account, or a broker's real order execution. The two tester modes disagree with each other for the same reasons any two simulation assumptions can disagree: tick generation, stop-fill rules, spread modeling. That gap is worth measuring before you ever risk real money. It is not, on its own, evidence of what a live broker would do, and live-versus-backtest agreement is not something this article measures.
This article builds that analysis directly in MQL5, with nothing borrowed from an external stats library. There are three files: a statistics engine, an EA that generates the paired dataset by logging trades under each tester mode, and a dashboard that reads the result back and shows the verdict on the chart. Every number quoted later comes from real Strategy Tester runs across four symbol/timeframe combinations (3,595, 403, 289 and 272 matched trades), with the trade direction logged on every row and every unmatched trade counted. The tester settings and EA inputs are listed in full in the Pairing Trades and Results Across Four Symbols sections; spread and commission were not recorded, which the Limitations section covers.
What Bland-Altman Actually Checks
Take two measurements of the same quantity. Compute their mean and their difference, then plot difference against mean for every pair you have. If the two systems agree, the differences should scatter randomly around zero with no relationship to how big the underlying quantity is. Three numbers describe that scatter:
// bias: mean(B - A) -- systematic over/under-estimate of A by B // SD: stdev(B - A) -- spread of the disagreement // LoA: bias +/- 1.96 * SD -- approximate 95% limits of agreement
A near-zero bias with a tight LoA band means the two sources are numerically close, trade by trade, within whatever tolerance you decide matters. A near-zero bias with a wide LoA band is a different case. The XAUUSD results look like this: the averages look fine, but individual trades can differ by almost a full R. A plain win-rate or average-R comparison cannot see that gap, which is the whole reason this method earns a place here. A tight LoA band does not make two systems "interchangeable" on its own either. That word only means something once you have picked a tolerance band and shown both limits sit inside it. Reading the Numbers Honestly below sets out one way to pick that number.
One more check: does the disagreement get bigger as the trade size grows? That is proportional bias. It is tested by regressing the difference on the mean and reporting the slope's standard error, so you can judge whether the slope is distinguishable from zero.
The Statistics Engine
SBAPair holds one matched observation. Its fields are named a_val / b_val rather than "backtest" and "live" on purpose. The class makes no assumption about what the two paired sources are; the caller decides that, and here it is the two tester execution modes:
//+------------------------------------------------------------------+ //| BlandAltmanCore.mqh | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2026, ADEWUMI GBADEBO BABATUNDE" #property link "https://www.mql5.com" //--- 95% normal-approximation multiplier used throughout this file. //--- This is an approximation of the Student-t 0.975 quantile; its //--- accuracy improves as sample size grows; for small n (see //--- EURUSD, n=26, in the article) it understates interval width //--- slightly. #define BA_Z95 1.96 //--- initial array capacity, grown in blocks as pairs accumulate #define BA_INITIAL_CAP 256 //--- hard ceiling so a runaway session can't exhaust memory #define BA_MAX_SAMPLES 20000 //+------------------------------------------------------------------+ //| One matched observation between two paired result sources | //+------------------------------------------------------------------+ struct SBAPair { string signal_id; // links source-A leg to its source-B leg datetime signal_time; // bar time the setup fired on double a_val; // System A value (e.g. tick-model R) double b_val; // System B value (e.g. OHLC-model R) double mean_val; // (a_val + b_val) / 2 double diff_val; // b_val - a_val };
Mean and variance update online through Welford's algorithm, and AddPair() computes mean_val and diff_val once at insertion time:
//+------------------------------------------------------------------+ //| Register one matched observation between the two sources | //+------------------------------------------------------------------+ bool CBlandAltman::AddPair(const string signal_id, const datetime signal_time, const double a_val, const double b_val) { if(m_pair_count >= BA_MAX_SAMPLES) return(false); GrowIfNeeded(); SBAPair p; p.signal_id = signal_id; p.signal_time = signal_time; p.a_val = a_val; p.b_val = b_val; p.mean_val = (a_val + b_val) / 2.0; p.diff_val = b_val - a_val; m_pairs[m_pair_count] = p; m_pair_count++; m_diff_stats.Update(p.diff_val); return(true); }
Once bias and SD exist, the limits of agreement come down to two one-line functions:
//+------------------------------------------------------------------+ //| Upper 95% limit of agreement: bias + 1.96 * SD | //+------------------------------------------------------------------+ double CBlandAltman::UpperLoA(void) const { return(Bias() + BA_Z95 * StdDevDiff()); } //+------------------------------------------------------------------+ //| Lower 95% limit of agreement: bias - 1.96 * SD | //+------------------------------------------------------------------+ double CBlandAltman::LowerLoA(void) const { return(Bias() - BA_Z95 * StdDevDiff()); }
Neither of those numbers means much without some sense of how much sampling noise they carry. SE_Bias() and SE_LoA() supply that, the second one following the large-sample approximation from Bland & Altman's original 1986 paper:
//+------------------------------------------------------------------+ //| Standard error of the bias estimate: SD / sqrt(n) | //+------------------------------------------------------------------+ double CBlandAltman::SE_Bias(void) const { if(m_pair_count < 2) return(0.0); return(StdDevDiff() / MathSqrt((double)m_pair_count)); } //+------------------------------------------------------------------+ //| Approximate standard error of each limit of agreement, per the | //| Bland & Altman (1986) large-sample approximation: | //| SE(LoA) = SD * sqrt(3 / n). Treated as approximate, not exact — | //| see LoA_CI95() for the caveat this carries at small n. | //+------------------------------------------------------------------+ double CBlandAltman::SE_LoA(void) const { if(m_pair_count < 2) return(0.0); return(StdDevDiff() * MathSqrt(3.0 / (double)m_pair_count)); }
LoA_CI95() turns those standard errors into an actual interval around each limit, with the header comment spelling out where the approximation gets shakier, which is at small samples:
//+------------------------------------------------------------------+ //| 95% confidence interval for each limit of agreement, using the | //| normal approximation z=1.96 rather than the exact Student-t | //| quantile for n-1 degrees of freedom. That approximation is | //| looser than reality at small n (fewer than ~30 pairs) -- the | //| interval this returns is therefore a lower bound on how wide the | //| true 95% CI would be for a small sample. | //+------------------------------------------------------------------+ void CBlandAltman::LoA_CI95(double &upper_lo, double &upper_hi, double &lower_lo, double &lower_hi) const { double se = SE_LoA(); upper_lo = UpperLoA() - BA_Z95 * se; upper_hi = UpperLoA() + BA_Z95 * se; lower_lo = LowerLoA() - BA_Z95 * se; lower_hi = LowerLoA() + BA_Z95 * se; }
The bias ± 1.96 × SD formula only behaves the way people expect it to when the differences are roughly symmetric around the mean. Skewness() is a cheap, one-number diagnostic for that assumption. It is no substitute for a real normality test, but it flags a clear violation, and that matters for every symbol in this dataset (see Results Across Four Symbols):
//+------------------------------------------------------------------+ //| Sample skewness of the differences: a rough, one-number check | //| on whether the bias +/- 1.96*SD assumption (which presumes an | //| approximately symmetric distribution) is reasonable here. This | //| is a diagnostic, not a formal normality test -- values near 0 | //| are consistent with symmetry, but this alone does not establish | //| normality or independence of the underlying observations. | //+------------------------------------------------------------------+ double CBlandAltman::Skewness(void) const { if(m_pair_count < 3) return(0.0); double mean = Bias(); double sd = StdDevDiff(); if(sd < 1e-12) return(0.0); double sum_cubed = 0.0; for(int i = 0; i < m_pair_count; i++) { double dev = m_pairs[i].diff_val - mean; sum_cubed += dev * dev * dev; } double n = (double)m_pair_count; return((sum_cubed / n) / (sd * sd * sd)); }
Proportional bias is still an OLS regression of diff_val on mean_val, but it also returns the slope's standard error, computed from the residual variance in a second pass over the stored pairs. That lets the caller judge whether a slope is distinguishable from zero (slope / slope_se behaves like an approximate t-statistic) instead of relying on "looks close to flat":
//+------------------------------------------------------------------+ //| Regress diff_val on mean_val to test for proportional bias, and | //| return the slope's standard error so the caller can judge | //| whether the slope is distinguishable from zero (slope / slope_se | //| is an approximate t-statistic against the null of no | //| proportional bias). | //+------------------------------------------------------------------+ bool CBlandAltman::ProportionalBias(double &slope, double &intercept, double &slope_se) const { slope = 0.0; intercept = 0.0; slope_se = 0.0; if(m_pair_count < 4) // need n-2 >= 2 residual degrees of freedom return(false); double sum_x = 0.0, sum_y = 0.0, sum_xy = 0.0, sum_xx = 0.0; for(int i = 0; i < m_pair_count; i++) { sum_x += m_pairs[i].mean_val; sum_y += m_pairs[i].diff_val; sum_xy += m_pairs[i].mean_val * m_pairs[i].diff_val; sum_xx += m_pairs[i].mean_val * m_pairs[i].mean_val; } double n = (double)m_pair_count; double denom = (n * sum_xx) - (sum_x * sum_x); if(MathAbs(denom) < 1e-12) return(false); // mean_val has no spread, slope undefined slope = ((n * sum_xy) - (sum_x * sum_y)) / denom; intercept = (sum_y - slope * sum_x) / n; //--- second pass: residual sum of squares, needed for SE(slope) double sse = 0.0; double xbar = sum_x / n; double sxx = sum_xx - n * xbar * xbar; for(int i = 0; i < m_pair_count; i++) { double fitted = intercept + slope * m_pairs[i].mean_val; double resid = m_pairs[i].diff_val - fitted; sse += resid * resid; } double residual_variance = sse / (n - 2.0); if(sxx > 1e-12) slope_se = MathSqrt(residual_variance / sxx); return(true); }
And the verdict the dashboard shows, agreement or not, still comes down to comparing both limits against a tolerance band the caller supplies. The class does not pick that number. The trader does, based on what a discrepancy of that size would cost. Reading the Numbers Honestly walks through one way to arrive at a concrete value instead of leaving it as an unexplained input:
//+------------------------------------------------------------------+ //| Agreement holds when both limits of agreement fall inside the | //| trader-defined tolerance band around zero. m_tolerance_band is | //| set by the caller; this class does not pick a value for you -- | //| see the article for how to choose one for a specific strategy. | //+------------------------------------------------------------------+ bool CBlandAltman::IsInAgreement(void) const { if(m_pair_count < 2) return(false); return(UpperLoA() <= m_tolerance_band && LowerLoA() >= -m_tolerance_band); }
Pairing Trades: the Logging EA
BlandAltmanAgreement_EA.mq5 isn't trying to be a clever strategy. It's a plain fast/slow MA cross, kept deliberately simple so the article can stay focused on the agreement statistics instead of the signal generating them. What it needs to do is produce two comparable trade logs: run it once under "Every tick based on real ticks" and once under "1 Minute OHLC", with the same symbol, date range and inputs, and each closed trade's realized R-multiple gets written to its own CSV, tagged with a signal_id built from the bar time and symbol so the same setup can be matched across both runs later. Every input the trades depend on is listed below. The EA has no entry or exit filters, opens at most one position per symbol and magic number, and attaches one stop and one target to every order.
| Input | Value | Meaning |
|---|---|---|
| InpFastPeriod | 10 | Fast moving-average period |
| InpSlowPeriod | 30 | Slow moving-average period |
| InpMAMethod | MODE_SMA | Simple moving average |
| InpAppliedPrice | PRICE_CLOSE | Price series for both averages |
| InpLots | 0.10 | Fixed volume; the R-multiple does not depend on it |
| InpSLPoints | 300 | Stop loss, and the risk used as 1R |
| InpTPPoints | 600 | Take profit, so a full target is +2R |
| InpMagic | 20260916 | Magic number used to filter positions and deals |
| InpRunLabel | TickModel / OHLCModel | File label for the run, one per tester mode: TickModel or OHLCModel |
These are the values used for the four runs in the Results Across Four Symbols section. They match the EA's defaults, and the risk_points column of every saved log reads 300.0, which confirms the 300-point stop on all four symbols. Note that 300 points is a different price distance on each instrument, so the same input is not the same risk in price terms.
OnInit() builds the CSV filename from the symbol and timeframe, and truncates the file on every run rather than appending to it:
//+------------------------------------------------------------------+ //| (Re)create this run's CSV from scratch and write its header row. | //| The file is truncated rather than appended to, so re-running the | //| same symbol/timeframe/label combination twice in a row cannot | //| duplicate rows from the previous run -- the symbol/timeframe in | //| the filename only stops different instruments from mixing; this | //| truncate step is what stops a repeated run from doubling up. | //+------------------------------------------------------------------+ bool PrepareCSV(void) { int handle = FileOpen(g_csv_filename, FILE_WRITE | FILE_CSV | FILE_COMMON, ','); if(handle == INVALID_HANDLE) { Print("BlandAltmanAgreement_EA: FileOpen failed, error ", GetLastError()); return(false); } FileWrite(handle, "signal_id", "signal_time", "direction", "entry_price", "exit_price", "risk_points", "r_multiple"); FileClose(handle); return(true); }
The gate that decides whether a new signal is even allowed needs to be scoped carefully. A bare PositionsTotal() == 0 check is account-wide, so a position on any other symbol or opened by any other EA on the same account would silently block this strategy's own signals. CountOwnPositions() avoids that with an explicit filter on symbol and magic number:
//+------------------------------------------------------------------+ //| Count our own open positions on this symbol, filtered by magic | //| number, so other symbols or other EAs never block a new signal | //+------------------------------------------------------------------+ int CountOwnPositions(void) { int count = 0; for(int i = 0; i < PositionsTotal(); i++) { ulong ticket = PositionGetTicket(i); if(ticket == 0) continue; if(PositionGetString(POSITION_SYMBOL) != _Symbol) continue; if(PositionGetInteger(POSITION_MAGIC) != (long)InpMagic) continue; count++; } return(count); }
OnTick() also deserves care around an off-by-one. The cross itself is confirmed on the two most recently closed bars, read with CopyBuffer(..., 1, 2,...) at shift 1 and 2, so the timestamp recorded as signal_time needs to be the closed bar the cross completed on, iTime(_Symbol, _Period, 1), not the bar that has just started forming at shift 0. OnTick() passes that closed bar's own time through to OpenSignal():
//+------------------------------------------------------------------+ //| Expert tick function | //| Fires its cross check once per new bar (not once per closed bar | //| -- the bar that has just closed is read from the series with | //| shift 1/2 a few lines below, which is what actually gives us | //| closed-bar values). | //+------------------------------------------------------------------+ void OnTick(void) { datetime this_bar_time = iTime(_Symbol, _Period, 0); if(this_bar_time == g_last_bar_time) return; // only act once per new bar g_last_bar_time = this_bar_time; //--- the bar that just closed and produced this new-bar event datetime closed_bar_time = iTime(_Symbol, _Period, 1); double fast[], slow[]; ArraySetAsSeries(fast, true); ArraySetAsSeries(slow, true); if(CopyBuffer(g_fast_handle, 0, 1, 2, fast) < 2) return; if(CopyBuffer(g_slow_handle, 0, 1, 2, slow) < 2) return; bool cross_up = (fast[1] <= slow[1]) && (fast[0] > slow[0]); bool cross_down = (fast[1] >= slow[1]) && (fast[0] < slow[0]); if(CountOwnPositions() == 0) { if(cross_up) OpenSignal(ORDER_TYPE_BUY, closed_bar_time); else if(cross_down) OpenSignal(ORDER_TYPE_SELL, closed_bar_time); } }
The most consequential detail is in OnTradeTransaction(). A tempting shortcut for the R-multiple sign is sign = (exit_price > entry_price)? 1.0: -1.0, which is correct for a buy but backwards for a sell: a sell profits when price falls, so that formula flips a real winning sell into a reported loss and vice versa. Getting this right means storing each signal's direction and branching on it. The same handler also has to know when a position is really finished, and for that the signal must be stored under the right key. OpenSignal() records the position identifier read from the opening deal, not the order ticket, because every closing deal reports that identifier in DEAL_POSITION_ID, on hedging and netting accounts alike:
//+------------------------------------------------------------------+ //| Send a market order for the crossed direction and remember its | //| signal -- keyed on the closed bar the cross actually fired on - | //| so the matching exit can be logged later | //+------------------------------------------------------------------+ void OpenSignal(const ENUM_ORDER_TYPE direction, const datetime signal_bar_time) { double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT); double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); double price = (direction == ORDER_TYPE_BUY) ? ask : bid; double sl = (direction == ORDER_TYPE_BUY) ? price - InpSLPoints * point : price + InpSLPoints * point; double tp = (direction == ORDER_TYPE_BUY) ? price + InpTPPoints * point : price - InpTPPoints * point; bool sent = (direction == ORDER_TYPE_BUY) ? g_trade.Buy(InpLots, _Symbol, price, sl, tp) : g_trade.Sell(InpLots, _Symbol, price, sl, tp); if(!sent) { Print("BlandAltmanAgreement_EA: order send failed, error ", GetLastError()); return; } //--- key the signal on the position identifier, not the order ticket: //--- it is the value every later closing deal reports in DEAL_POSITION_ID ulong deal_ticket = g_trade.ResultDeal(); ulong position_id = (deal_ticket > 0 && HistoryDealSelect(deal_ticket)) ? (ulong)HistoryDealGetInteger(deal_ticket, DEAL_POSITION_ID) : g_trade.ResultOrder(); int n = ArraySize(g_open_signals); ArrayResize(g_open_signals, n + 1); g_open_signals[n].position_id = position_id; g_open_signals[n].signal_id = TimeToString(signal_bar_time, TIME_DATE | TIME_MINUTES) + "_" + _Symbol; g_open_signals[n].signal_time = signal_bar_time; g_open_signals[n].entry_price = price; g_open_signals[n].risk_points = InpSLPoints; g_open_signals[n].direction = direction; g_open_signals[n].closed_volume = 0.0; g_open_signals[n].exit_value = 0.0; }
IsPositionOpen() answers the only question the handler needs: is any volume still open under this identifier? It walks the open positions and compares POSITION_IDENTIFIER, instead of selecting by a ticket that may not be the identifier:
//+------------------------------------------------------------------+ //| True while a position with this identifier still has volume | //| open, matched on POSITION_IDENTIFIER, not on the ticket | //+------------------------------------------------------------------+ bool IsPositionOpen(const ulong position_id) { for(int i = 0; i < PositionsTotal(); i++) { if(PositionGetTicket(i) == 0) continue; if(PositionGetInteger(POSITION_IDENTIFIER) == (long)position_id) return(true); } return(false); }
OnTradeTransaction() adds each closing deal's volume and price to the tracked signal and logs only once IsPositionOpen() reports nothing left. The logged exit is the volume-weighted average over all closing deals, so a position closed in several pieces still produces one row with its full realized R. This EA uses a fixed lot with a single stop and target and never scales out, so in the runs below every position closed in one deal and the accumulation path was never needed; it matters if a broker fills a close in pieces, or if the EA is extended with partial exits:
//+------------------------------------------------------------------+ //| Trade transaction handler | //| Catches the closing deal(s) of a position we opened. Each | //| closing deal adds its volume and price to the tracked signal, | //| so a position closed in several parts is logged once, with | //| the volume-weighted average exit and its realized R-multiple. | //+------------------------------------------------------------------+ void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result) { if(trans.type != TRADE_TRANSACTION_DEAL_ADD) return; if(!HistoryDealSelect(trans.deal)) return; if(HistoryDealGetInteger(trans.deal, DEAL_MAGIC) != (long)InpMagic) return; if(HistoryDealGetInteger(trans.deal, DEAL_ENTRY) != DEAL_ENTRY_OUT) return; // only a closing leg is logged ulong position_id = HistoryDealGetInteger(trans.deal, DEAL_POSITION_ID); int index = FindOpenSignal(position_id); if(index < 0) return; // opened before this run started //--- add this closing deal to the running totals for the position double deal_volume = HistoryDealGetDouble(trans.deal, DEAL_VOLUME); double deal_price = HistoryDealGetDouble(trans.deal, DEAL_PRICE); g_open_signals[index].closed_volume += deal_volume; g_open_signals[index].exit_value += deal_volume * deal_price; //--- any volume still open under this position identifier means the //--- deal was a partial close, so nothing is logged yet if(IsPositionOpen(position_id)) return; //--- fully closed: the exit is the volume-weighted average price over //--- every closing deal, which equals the single price when there was one double exit_price = g_open_signals[index].exit_value / g_open_signals[index].closed_volume; double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT); double entry_price = g_open_signals[index].entry_price; double risk_points = g_open_signals[index].risk_points; ENUM_ORDER_TYPE direction = g_open_signals[index].direction; double move_points = MathAbs(exit_price - entry_price) / point; //--- direction-aware sign: a buy profits above entry, a sell profits //--- below entry, so the two directions need opposite comparisons double sign = (direction == ORDER_TYPE_BUY) ? ((exit_price > entry_price) ? 1.0 : -1.0) : ((exit_price < entry_price) ? 1.0 : -1.0); double r_multiple = sign * move_points / risk_points; LogClosedTrade(g_open_signals[index], exit_price, direction, r_multiple); RemoveOpenSignal(index); }
This matters beyond the code itself. The direction column is what makes the sign calculation auditable after the fact: with it, any row can be checked as a buy or a sell. All eight logs used in the Results Across Four Symbols section carry it, and every row's R-multiple was recomputed from its direction and prices as a check.
Reading the Agreement: the Dashboard
BlandAltmanDashboard.mq5 handles the actual pairing. It reloads both CSVs on a timer, matches rows by signal_id, and feeds every match into a fresh CBlandAltman instance. You could pass TimeCurrent() into AddPair() here, since the summary statistics never touch signal_time, but that would leave the paired dataset's own timestamps meaningless to anyone who tries to inspect it directly, so RefreshEngine() forwards the real value read from each CSV row instead:
//+------------------------------------------------------------------+ //| Re-read both CSVs, re-match pairs, refresh the dashboard | //+------------------------------------------------------------------+ void RefreshEngine(void) { SCsvRow rows_a[]; SCsvRow rows_b[]; if(!LoadCsv(InpFileA, rows_a) || !LoadCsv(InpFileB, rows_b)) { UpdateLabel("BA_status", "Waiting for both CSV files..."); g_last_refresh = TimeCurrent(); return; } g_engine.Reset(); g_matched = 0; for(int i = 0; i < ArraySize(rows_a); i++) { int j = FindRow(rows_b, rows_a[i].signal_id); if(j >= 0) { g_engine.AddPair(rows_a[i].signal_id, rows_a[i].signal_time, rows_a[i].r_multiple, rows_b[j].r_multiple); g_matched++; } } //--- every row left out of the statistics is counted, never dropped //--- silently: loaded rows minus matched rows, per file g_rows_a = ArraySize(rows_a); g_rows_b = ArraySize(rows_b); DrawDashboard(); g_last_refresh = TimeCurrent(); }
Pairing by signal_id silently drops any row that exists in only one file, so RefreshEngine() also counts them. The dashboard shows rows loaded from file A, rows loaded from file B, the matched count, and the A-only and B-only remainders next to the statistics. A run with unmatched rows is never presented as if every trade had been paired.
LoadCsv() has to get two things right. First, the header skip: a CSV read field by field needs one FileReadString() call per column, so with seven header columns (the export includes a direction field) it must read seven fields, because skipping only one would shift every subsequent read by six fields and corrupt the first data row. Second, it must detect a duplicate signal_id, since duplicated rows from a re-run are a real, not theoretical, risk. The loader below does both, and prints a warning on any duplicate rather than silently overwriting it:
//+------------------------------------------------------------------+ //| Parse a run's CSV into rows, skipping the full header row | //| row (7 fields: signal_id, signal_time, direction, entry_price, | //| exit_price, risk_points, r_multiple) and warning on any repeated | //| signal_id, since a duplicate here would silently corrupt pairing | //+------------------------------------------------------------------+ bool LoadCsv(const string filename, SCsvRow &rows[]) { ArrayResize(rows, 0); if(!FileIsExist(filename, FILE_COMMON)) return(false); int handle = FileOpen(filename, FILE_READ | FILE_CSV | FILE_COMMON, ','); if(handle == INVALID_HANDLE) return(false); //--- skip every field of the header row written by the logging EA -- //--- FileReadString() consumes one field per call, so a 7-column //--- header needs 7 calls, not one for(int h = 0; h < 7 && !FileIsEnding(handle); h++) FileReadString(handle); while(!FileIsEnding(handle)) { string signal_id = FileReadString(handle); if(signal_id == "") break; datetime signal_time = StringToTime(FileReadString(handle)); string direction = FileReadString(handle); FileReadString(handle); // entry_price, unused here FileReadString(handle); // exit_price, unused here FileReadString(handle); // risk_points, unused here double r_multiple = StringToDouble(FileReadString(handle)); if(FindRow(rows, signal_id) >= 0) { Print("BlandAltmanDashboard: duplicate signal_id \"", signal_id, "\" in ", filename, " -- keeping the first occurrence, " "check the source EA for a re-run that wasn't truncated"); continue; } int n = ArraySize(rows); ArrayResize(rows, n + 1); rows[n].signal_id = signal_id; rows[n].signal_time = signal_time; rows[n].direction = direction; rows[n].r_multiple = r_multiple; } FileClose(handle); return(true); }
One structural note: signal_id here is built from bar time plus symbol alone. That is enough to disambiguate pairs within a single-position, one-signal-per-bar EA like this one, but it would not be enough on its own for a strategy that can open more than one signal on the same bar, or across multiple magic numbers and run IDs. The Limitations section comes back to this.
Logging and Pairing Pitfalls
A logging EA that writes the same CSV pair for every symbol and appends on every run has two failure modes. With a plain BlandAltman_Backtest.csv and BlandAltman_Live.csv, testing XAUUSD, then EURUSD, then GBPUSD without clearing the files leaves all three symbols stacked in one CSV, and a repeated run after a recompile appends the same rows twice.
Folding the symbol and timeframe into the filename, shown in the Pairing Trades section, stops different instruments from mixing, but on its own it does not stop a second run of the same symbol and timeframe from doubling up, since an append-mode file keeps growing across runs. PrepareCSV() therefore truncates the file at the start of every run, so running the identical symbol/timeframe/label combination again can only ever produce one copy of each row. Duplicated rows distort the result: they understate the real variance if they reach the analysis unfiltered. The per-symbol files used in the Results Across Four Symbols section contain no duplicate signal_id in either mode.
Beyond the CSV naming, five runtime pitfalls have to be designed out of a logger like this: the R-multiple sign for sell trades and the account-wide position gate described in the Pairing Trades section, the off-by-one between the closed bar and the recorded signal_time, the CSV header skip and duplicate detection in the dashboard described in the Reading the Agreement section, and a partial close that would otherwise be logged as a final exit. All five are handled in the source shown above and in the accompanying files, and the runs in the Results Across Four Symbols section were checked for exactly these problems before any statistics were computed.
Results Across Four Symbols
How to read this section. Each symbol was run twice on the same strategy with the same inputs: once under "Every tick based on real ticks" (System A, tick model) and once under "1 Minute OHLC" (System B, OHLC model). Trades are matched by signal_id, and the difference is B minus A, as in BlandAltmanCore.mqh. Every row in all eight CSV files carries the trade direction. The file names use the run labels TickModel and OHLCModel, one per mode. Nothing here involves a live or demo account: it is two tester modes compared with each other, on one strategy, over one test period.
Before any statistics, three integrity checks were run on all eight files. No signal_id repeats within a file. The R-multiple of every row was recomputed from its direction, entry price, exit price and risk, and it matched the logged value on every row, so the sell-side sign is correct throughout. And no matched pair disagrees about direction. The tester configuration is in the first table; the second table accounts for every logged row.
| Setting | Value |
|---|---|
| Platform | MetaTrader 5 Strategy Tester, local agents, cloud servers off; terminal version 5.00, build 6285 (25 Oct 2026) |
| Account / server | MetaQuotes-Demo, hedging account |
| Quote source | MetaQuotes-Demo server history and ticks, as downloaded by the tester |
| Modes compared | System A: "Every tick based on real ticks"; System B: "1 Minute OHLC" |
| Test period | 2024.01.01 to 2025.10.28, custom period; first and last logged signals fall between 2024.01.02 and 2025.10.27 |
| Deposit / leverage | 10 000 USD, 1:100 |
| Execution delay | 5 ms |
| Forward test / optimization | None / disabled |
| Profit in pips | Enabled (the EA logs prices and R-multiples, so this has no effect on the CSV) |
| Symbols / timeframes | XAUUSD M5, EURUSD M15, GBPUSD H1, AUDUSD M15; settings above identical for all four |
| Spread / commission | Server symbol specification, not changed. No commission was charged (in the AUDUSD tester report, net profit equals gross profit plus gross loss exactly); spread values are not recorded in the logs |
| EA inputs | As listed in the Pairing Trades section, identical for both modes in every run |
| Run | Rows A (tick) | Rows B (OHLC) | Matched | A-only | B-only | Unmatched / distinct trades |
|---|---|---|---|---|---|---|
| XAUUSD M5 | 3598 | 3596 | 3595 | 3 | 1 | 4 of 3599 (0.1%) |
| EURUSD M15 | 410 | 405 | 403 | 7 | 2 | 9 of 412 (2.2%) |
| GBPUSD H1 | 293 | 294 | 289 | 4 | 5 | 9 of 298 (3.0%) |
| AUDUSD M15 | 275 | 273 | 272 | 3 | 1 | 4 of 276 (1.4%) |
Unmatched trades. The statistics below use the matched trades only. Across the four runs 17 trades appear only in the tick log and 9 only in the OHLC log, 26 in total, between 0.1% and 3.0% of the distinct trades in any one run. The EA opens a signal only when it is flat, so a trade that closes at a different time in one mode can suppress or admit the next signal in that mode. Four A-only/B-only couples sit exactly one bar apart with the same direction (XAUUSD one, GBPUSD two, AUDUSD one), which fits that explanation, although the logs do not prove it. All 26 unmatched trades closed at an R of 1.0 or more in absolute value, so they are full stop- or target-sized outcomes, not near-zero differences waiting to be paired. Excluding them therefore makes the limits below look somewhat tighter than the full picture. As a rough size of the effect, suppose each unmatched trade had instead been a matched pair differing by 1R: the half-width of the limits would grow from ±0.45R to ±0.52R for EURUSD, from ±0.40R to ±0.51R for GBPUSD, while the XAUUSD limits would barely move (±0.295R to ±0.302R), and AUDUSD would go from ±0.12R to ±0.26R. AUDUSD moves most because its matched differences are so small that even four unmatched trades matter. Every conclusion in this section is limited to the matched subset.

Fig. 1. XAUUSD, M5: Bland-Altman plot, 3595 matched pairs
The solid line marks the bias, +0.008R, and the dashed lines the approximate 95% limits of agreement, +0.303R and −0.287R (95% CI on each limit about ±0.009R). The bias is small but, with 3,595 pairs, distinguishable from zero. Most pairs are nearly identical: 3,285 of them (91.4%) differ by no more than 0.05R and 802 are exactly equal. The plot shows why the limits are wider than that suggests. A few trades sit far from the cloud, the largest being a tick-model result of −2.04R against +2.00R in OHLC mode on 2025.07.03 02:20, and a second sign flip, −1.01R against +2.00R, on 2025.09.10 18:05. In both the tick model recorded a stop-out where the OHLC model recorded the take-profit. One further pair has the tick model at +4.96R against +2.00R, which is a win past the target rather than a flip.

Fig. 2. EURUSD, M15: Bland-Altman plot, 403 matched pairs
EURUSD has 403 matched pairs and a bias of +0.016R. Its limits, +0.462R and −0.429R, are the widest of the four runs, which looks odd next to the cloud: 385 of 403 pairs (95.5%) are within 0.05R of each other. The two pairs at the top of the plot explain it. On 2024.09.23 16:15 and 2025.05.09 02:00 the tick model closed at −1.00R and the OHLC model at +2.00R, a 3R gap each. Two trades out of 403 are enough to set the standard deviation, and they are also why its skewness is the second highest in the table.

Fig. 3. GBPUSD, H1: Bland-Altman plot, 289 matched pairs
The GBPUSD difference distribution is asymmetric in a way the limits cannot show. The central 95% of the differences runs from −0.036 to +0.357, so almost all the spread is on the upside, where the tick model recorded losses beyond the stop: −2.00R against −1.00R on 2025.04.16 23:00, −1.67R on 2025.01.15 01:00, and −1.59R twice. One pair, 2024.10.17 19:00, is a full flip, −1.00R in tick mode and +2.00R in OHLC mode. In the tick log 97 GBPUSD trades closed beyond −1.005R; in the OHLC log none did. That fits the idea that the tick model fills a stop at the first available price after the level, while the OHLC model fills at the level itself. That is a hypothesis from the pattern; it was not checked against the tick data.

Fig. 4. AUDUSD, M15: Bland-Altman plot, 272 matched pairs
AUDUSD is the tightest run: bias +0.006R, limits +0.125R and −0.113R, no sign flips, and a largest single difference of 0.71R (−1.71R against −1.00R on 2025.06.19 21:15). 97.4% of the 272 pairs are within 0.05R. It is also the run most exposed to the unmatched-trade question above, since four unmatched trades are large next to such small differences.

Fig. 5. Bias and 95% limits of agreement across the four runs, with the empirical central 95% of differences beside each
The blue bars are the bias ± 1.96 × SD limits the engine reports. The red bars are the 2.5th and 97.5th percentiles of the same differences, which make no normality assumption. For XAUUSD, EURUSD and AUDUSD the red bar is much narrower than the blue one, because a handful of large differences inflate the standard deviation. GBPUSD's red bar is the only one that is close to the blue one on the upper side.
| Symbol | TF | n | Bias (R) | SE(bias) | Upper LoA [95% CI] | Lower LoA [95% CI] | Skew |
|---|---|---|---|---|---|---|---|
| XAUUSD | M5 | 3,595 | +0.008 | 0.003 | +0.303 [+0.295, +0.312] | −0.287 [−0.295, −0.278] | +7.38 |
| EURUSD | M15 | 403 | +0.016 | 0.011 | +0.462 [+0.423, +0.500] | −0.429 [−0.468, −0.391] | +10.53 |
| GBPUSD | H1 | 289 | +0.029 | 0.012 | +0.425 [+0.385, +0.465] | −0.367 [−0.408, −0.327] | +11.72 |
| AUDUSD | M15 | 272 | +0.006 | 0.004 | +0.125 [+0.112, +0.137] | −0.113 [−0.125, −0.100] | +4.38 |
The skewness column is large and positive for every symbol, between +4.4 and +11.7, so each difference distribution has a long upper tail. That bears directly on how literally to take the 95% in "95% limits of agreement". The bias ± 1.96 × SD formula assumes something close to a symmetric, well-behaved distribution, and these are not. The true coverage of the normal-theory intervals is not guaranteed to be 95%, and in three of the four runs the empirical central 95% is clearly narrower, as Fig. 5 shows. The Limitations section says what that does and does not invalidate.
A comparison of win rates would have shown none of this, so here is the win-rate table by tester mode, with the proportional-bias slope from regressing the difference on the pair mean:
| Symbol | Win rate, System A (tick) | Win rate, System B (OHLC) | Proportional-bias slope ± SE (t) |
|---|---|---|---|
| XAUUSD | 31.4% (1129/3595) | 31.5% (1131/3595) | −0.0226 ± 0.0017 (t=−12.94) |
| EURUSD | 33.5% (135/403) | 34.0% (137/403) | −0.0093 ± 0.0080 (t=−1.17) |
| GBPUSD | 29.8% (86/289) | 30.1% (87/289) | −0.0144 ± 0.0086 (t=−1.68) |
| AUDUSD | 34.6% (94/272) | 34.6% (94/272) | −0.0092 ± 0.0025 (t=−3.67) |
Win rates differ by 0.5 points or less on every symbol. The slopes are negative for all four, meaning the OHLC result drifts below the tick result as the trade outcome grows, which is what the XAUUSD tick wins beyond the target would produce. Two of the four are statistically distinguishable from zero, XAUUSD with t = −12.9 and AUDUSD with t = −3.7, while EURUSD (t = −1.2) and GBPUSD (t = −1.7) are not. For XAUUSD the slope is small in absolute terms, about 0.02R of drift per 1R of trade size, but at 3,595 pairs it is measured very precisely. The last table of this section shows where the disagreement sits.
| Run | Identical pairs | Within ±0.05R | Win/loss flips | Empirical central 95% of B − A |
|---|---|---|---|---|
| XAUUSD M5 | 802 (22.3%) | 91.4% | 2 | −0.067 to +0.087 |
| EURUSD M15 | 147 (36.5%) | 95.5% | 2 | −0.033 to +0.057 |
| GBPUSD H1 | 111 (38.4%) | 92.4% | 1 | −0.036 to +0.357 |
| AUDUSD M15 | 135 (49.6%) | 97.4% | 0 | −0.021 to +0.042 |
Reading the Numbers Honestly
One pattern holds across all four rows: bias stays close to zero, never above 0.03R in absolute value, while the limits of agreement range from about ±0.12R (AUDUSD) to about ±0.45R (EURUSD). Bias is, by definition, just the average of the paired differences, so "bias is close to zero" and "the average difference is close to zero" are the same statement, not two findings that happen to agree. The useful information in this method is the spread around that average, and, as the last table of the Results Across Four Symbols section shows, how that spread is made up.
The spread is made up of very few trades. Across 4,559 matched pairs there are five win/loss flips: two on XAUUSD, two on EURUSD and one on GBPUSD. In every one of them the tick model recorded a stop-out (−1.00R, −1.01R or −2.04R) and the OHLC model recorded the full +2.00R target. Take out the pairs that differ by 2.5R or more (three on XAUUSD, two on EURUSD, one on GBPUSD) and the limits shrink from ±0.30R to ±0.23R for XAUUSD, from ±0.45R to ±0.17R for EURUSD and from ±0.40R to ±0.20R for GBPUSD. That is a large effect from six trades out of 4,559. One mechanism that would fit is a one-minute bar that contains both the stop and the target. The OHLC model has to decide which was hit first from the bar alone, while real ticks show the actual order. This is a plausible reading, not something the data here confirms; the tick data of those bars was not inspected.
The tolerance band needs a decision too. IsInAgreement() takes a tolerance band as an input and does not pick one for you. One reasonable way to set it: if your risk per trade is fixed and your take-profit is 2R, decide how much of a single-trade R-multiple swing you could live with before it changed a decision you would actually make. For a strategy sized the way this one is, something in the region of 0.3–0.5R is a defensible starting point, tight enough to matter but wide enough not to flag normal execution noise. Because the verdict depends on that number, the table below shows what IsInAgreement() returns for each run at five tolerance bands, using the matched-pair limits from the Results Across Four Symbols section. A run is Within only if both limits fall inside the band.
| Run | Worst |LoA| (R) | ±0.25R | ±0.30R | ±0.50R | ±0.75R | ±1.00R |
|---|---|---|---|---|---|---|
| XAUUSD M5 | 0.303 | Outside | Outside | Within | Within | Within |
| EURUSD M15 | 0.462 | Outside | Outside | Within | Within | Within |
| GBPUSD H1 | 0.425 | Outside | Outside | Within | Within | Within |
| AUDUSD M15 | 0.125 | Within | Within | Within | Within | Within |
Only AUDUSD is inside at every band. XAUUSD misses ±0.30R by 0.003R (upper limit +0.303R) and passes from ±0.50R up, which is where EURUSD (worst limit 0.462R) and GBPUSD (0.425R) also pass. So three of the four runs cannot be called inside tolerance without naming the band. That is the kind of verdict this method is built to produce: not "interchangeable" as an unconditional label, but "within tolerance, given a stated tolerance." There is also a limit to what a band on the limits can tell you. At ±0.50R every run passes, yet the same data contain five trades where one mode lost and the other won. If a single 3R disagreement matters to you, track the flip count next to the verdict. The dashboard's default band of 0.25R is the strictest row of this table.
Limitations and What This Data Can't Tell You
Scope of the comparison. This is two Strategy Tester modes, compared on one strategy, one server and one 22-month period. It says how much the choice of tester mode moves a single trade’s R-multiple for this fast/slow MA cross with a 300-point stop and a 600-point target. It does not say how a live broker would fill the same signals, and it does not rank the two modes: neither is ground truth. The integrity checks in the Results Across Four Symbols section (no duplicate signal_id, every R-multiple recomputed from direction and prices, no direction mismatch in any matched pair) show the logs are internally consistent, not that either mode is right.
The normality assumption, with real numbers behind it. The bias ± 1.96 × SD formula assumes the differences are reasonably close to a symmetric, well-behaved distribution. Skewness is between +4.4 and +11.7 for the four runs, so the assumption does not hold, and for XAUUSD, EURUSD and AUDUSD the empirical central 95% is clearly narrower than the normal-theory limits. A skewness diagnostic is not a formal normality test and does not by itself invalidate the figures, but a reader who needs an exact interval should use the percentile interval shown in Fig. 5 or a bootstrap interval on the limits, rather than the normal approximation. The engine here reports the normal-theory limits only.
A few trades carry the result. The five win/loss flips and the handful of pairs differing by 2.5R or more are what set the standard deviation in three of the four runs. With 272 to 3,595 pairs the confidence intervals on the limits are narrow (at most about ±0.04R), but that interval describes sampling noise around a standard deviation that a few events dominate. A different test period with a different number of such events would give different limits, and this article has one period per symbol.
Unmatched trades. Twenty-six trades appear in only one mode and are excluded from every statistic above. The matched-subset limits do not describe them, and because they are full-size outcomes they would probably have widened the picture, most visibly for AUDUSD, as the 1R stress estimate in the Results Across Four Symbols section shows. A stricter design would generate signals independently of position state, so both modes see the same signals and any difference is a difference in outcome; alternatively the unmatched trades can be analyzed with their own discrepancy metric. This article does neither and limits its conclusions to the matched subset.
The scope of signal_id matching. Matching purely on bar time and symbol works for this EA because it only ever holds one position at a time and only ever opens one signal per bar. It would not be sufficient, unmodified, for a strategy that can fire multiple signals on the same bar, run under multiple magic numbers in parallel, or get re-run under a different EA version without a version tag in the key. Extending SBAPair.signal_id (or adding a separate field) to include a magic number and version string is the straightforward fix if this project is adapted to a less constrained strategy.
Tester configuration. The configuration table in the Results Across Four Symbols section lists every setting the Strategy Tester exposes plus the server and build. Spread and commission were left at the server's symbol specification and are not written to the logs, so a reader reproducing the runs on a different server, or on the same server after its symbol specification changes, should expect different trade counts. The quote history used by each mode is whatever the tester downloaded from the server at run time. The EA writes a row only when a position closes, so a trade still open when the test ends is not logged: the AUDUSD tick-mode report shows 276 trades against 275 logged rows, most likely for that reason, though this was not checked trade by trade.
What this article does and does not demonstrate. It demonstrates that a native-MQL5 Bland-Altman engine can be built, tested and run against real Strategy Tester output, that it counts what it leaves out, and that it separates runs a win-rate comparison treats as equivalent. It does not demonstrate how any of these four instruments would behave against a real broker's live execution. That would require an actual live or demo account run, paired against one of these tester modes the same way the two tester modes were paired against each other here. It is a natural next step but is outside what this article's data can support.
Conclusion
A simple win-rate or average-R comparison would call these four Strategy Tester runs equivalent: win rates within half a point of each other between the two modes, and a bias no larger than 0.03R. Bland-Altman analysis shows more. The agreement limits run from about ±0.12R on AUDUSD to about ±0.45R on EURUSD, five trades finished as a loss in one mode and a win in the other, and the proportional-bias test finds a small but measurable drift on XAUUSD and AUDUSD. Those are properties of these runs on this strategy and this server, not verdicts on the symbols. The supportable claim is the method: a native-MQL5 pipeline for comparing two paired result sources, built and run end to end, that reports individual-trade disagreement and also reports how many trades it had to leave out.
The natural next step is the comparison this article does not make: pair one of these tester modes with real demo-account trades from the same EA and run them through the same statistics engine. The logging EA and the dashboard already support that, since the pairing key does not depend on where the trades came from.
| File | Type | Description |
|---|---|---|
| BlandAltmanCore.mqh | Include | Statistics engine: Welford running mean/SD, bias, 95% limits of agreement with standard errors and confidence intervals, skewness, proportional-bias regression, CSV export. |
| BlandAltmanAgreement_EA.mq5 | Expert Advisor | Fast/slow MA cross that logs each closed trade's R-multiple, direction and signal_id to a CSV; run once per Strategy Tester mode. |
| BlandAltmanDashboard.mq5 | Indicator | Reads the two CSV logs, pairs trades by signal_id and shows bias, limits of agreement and the agreement verdict on the chart. |
Warning: All rights to these materials are reserved by MetaQuotes Ltd. Copying or reprinting of these materials in whole or in part is prohibited.
This article was written by a user of the site and reflects their personal views. MetaQuotes Ltd is not responsible for the accuracy of the information presented, nor for any consequences resulting from the use of the solutions, strategies or recommendations described.