
Outlier filtering for a backtest comes down to one decision, made over and over: is this price an error, or did the market really do that? Delete errors and keep real events. If you get the split wrong in either direction, the equity curve you are testing is not the one the market produced. The cleanest way to get it right is to start from data that was verified bar by bar and to apply any further filter as a rule you wrote down before you looked at results. That is how we approach minute-bar data at BacktestMarket.
TL;DR
- An outlier is a statistical label, not a verdict. A bad tick should be removed or repaired. A genuine crash bar should stay in.
- Plain standard-deviation thresholds are easily distorted by the very outliers they hunt. A median-based (MAD) rule holds up better on fat-tailed price data.
- Fix the filter, its threshold and the test sample before you run the strategy, and document them. Tuning a filter to improve results is a form of overfitting.
- Starting from data that is already cleaned and documented leaves you far fewer decisions to defend.
Table of Contents
- What counts as an outlier in backtest data
- Why outliers distort backtest results
- Bad tick or genuine move: a practical test
- Choosing a detection rule: why robust beats naive
- Remove, repair, cap or keep
- Keeping your filter honest
- Provenance matters as much as the filter
- A repeatable outlier workflow
- Start from data that has already been cleaned
- Our view: filter less, document more
- FAQ
- Sources
What counts as an outlier in backtest data
In statistics, an outlier is a value far from the rest of the series. In trading data, that label covers two very different things.
Errors. A bad print from a feed, a decimal slip, a stale quote, a price that violates the bid/ask boundary or the instrument's tick size. These never happened in the market, so they inject fake profit or fake loss into your test.
Real extremes. A central bank surprise, a flash crash, a collapse like the one in crypto in November 2022. These are rare, but they happened, and a strategy you plan to run live will meet more of them.
An Oxford doctoral training report on data quality for risk scenarios makes the same point: an outlier may reflect a recording or measurement error, or a rare macro event. Its cleansing process identifies the cause, removes erroneous outliers and keeps those supported by a market event. The same report treats unidentified outliers as a risk-model problem, because models that are not robust to outliers overestimate risk.
So the first question is never "how many standard deviations away is it?" It is "what would have to be true for this price to be real?"
Why outliers distort backtest results
One bad minute bar can do three kinds of damage.
- Fake trades. A spike through your stop or target fills a trade that could not have been filled. A single phantom low can trigger a stop-out, or a phantom high can book a gain.
- Distorted indicators. Volatility bands, ATR and moving averages absorb the spike and then misbehave for the length of their lookback window.
- Wrong risk statistics. Maximum drawdown and Sharpe ratio are extreme-sensitive. One erroneous bar can reshape both.
The opposite error is just as costly. Research on the world's most liquid futures at a 30-second scale found that drawdown distributions have power-law tails whose extreme end is dominated by a few very large "dragon-king" events. The same study notes that the most extreme drawdowns are mostly generated by transient dependence between returns, not by one or a few extreme individual returns, and that they tend to occur fast. If you scrub every violent bar out of your data, your backtest never sees the events that define your real risk.
We cover the downstream audits in more detail in our guide to five audits to run on outlier-handled M1 data.
Bad tick or genuine move: a practical test
No single number separates the two. A useful approach is to ask several independent questions about each flagged bar.
1. Does the move reverse immediately?
A spike that prints far away from both neighbors and returns to the prior level on the next bar is the classic bad-tick signature. A genuine repricing usually leaves the price somewhere new: the bars after it trade around the new level. This is the logic behind a three-condition spike test, which we describe in our post on intraday data cleaning with a spike test.
2. Do related series agree?
A real event usually shows up in correlated instruments at the same minute. A euro move should appear in the other euro crosses, an index shock in related index contracts. A European Central Bank working paper applies a moving-window clustering approach to financial market series on exactly this idea: crosschecking the behavior of different series within a cluster reduces the chance that genuine observations are wrongly flagged.
3. Is the price physically plausible?
Check it against market structure. Does it respect the instrument's tick size? Does the high stay above the open and close, and the low below them? Does the range fit what the instrument can do in one minute? Academic work on ultra-high-frequency data proposes filters that remove records not corresponding to plausible market activity, and then compares ways of aggregating the cleaned data.
4. Is there a known event?
Check the timestamp against economic releases, central bank decisions, market opens and rollovers. A big bar at a scheduled release is far more likely to be real than one at 3:17 a.m. on a quiet Tuesday.
A bar that fails the first three checks and has no event attached is a strong candidate for removal. A bar that passes them stays, however ugly it makes your drawdown.
Choosing a detection rule: why robust beats naive
The textbook rule flags values beyond two or three standard deviations. On financial returns it has a built-in flaw: the outlier itself inflates the standard deviation used to judge it.
The documentation of an open-source signal-processing library shows this on a famous day. On 9 November 2022, when the FTX exchange collapsed, Bitcoin had a log return of about −0.15. The ordinary z-score, which includes that day in its own standard deviation, reported only −4.5, while a median-based robust z-score reported −8.5. Over 2022 to 2026, the ordinary score exceeded 5 once, while the robust one did so 24 times. The naive rule was blind to the very shocks it was supposed to catch.
The robust alternative uses the median absolute deviation (MAD): the median of how far each value sits from the median. Under normality, one standard deviation equals about 1.4826 times the MAD, so you can scale MAD into familiar units. A University of Essex thesis on cleaning ultra-high-frequency data sets its cutoff at 2.9652 times the MAD, which is two scaled standard deviations. The same thesis rejects Grubbs' test, because it assumes normality and examines one observation at a time.

A worked example
Take a series of 1-minute returns where the typical absolute deviation from the median is tiny, say 0.01%. A bar returns 0.40%.
- The MAD of the window is 0.01%.
- Scaled, one robust standard deviation is about 1.4826 × 0.01% = 0.0148%.
- The bar sits roughly 27 robust standard deviations from the median, far past any cutoff.
- A standard-deviation rule calculated over a window that includes the bar may inflate its own yardstick enough to look much less alarming.
The robust rule flags it. Now you apply the questions from the previous section: does it reverse, do related series agree, is there a scheduled event? Only then do you decide.
Two more lessons from the Essex thesis are worth borrowing. First, a good filter has to account for minimum tick size, price level, price volatility and the return distribution, not only returns. Second, its approach discards only observations that are flagged by both a market-structure filter and the MAD test, and it reports that a filter looking only at return distribution can "overscrub": a prior algorithm classified between 13.82% and 24.33% of equity-option trades as outliers. Requiring two independent signals before deletion keeps real events in.

Remove, repair, cap or keep
Once a bar is flagged, you have four options. Each has a place.
| Action | Use when | Watch out for |
|---|---|---|
| Remove | The price is demonstrably impossible (bad tick, broken bar) | Leaves a gap; handle it like any missing value |
| Repair | The error is clear and the true value can be inferred from neighbors | Repair rules must be fixed and documented in advance |
| Cap (winsorize) | You study a statistic, not fills, and want to limit leverage from extremes | The cap level changes results; fix it ahead of time |
| Keep | A market event supports it | It will hurt your metrics, and it should |
The Oxford framework fills removed points the same way missing values are filled, so the gap policy and the outlier policy are really one policy. Decide both together.
Capping deserves special care. Campbell Harvey's research guidance from Duke University says the winsorization level, for example truncating at the 1% or 2% tails, must be chosen before the model is built. A model that works at a 5% cap but fails at 1% is, in his words, a sign of a faulty process.
Keeping your filter honest
The danger in outlier filtering is not the code. It is the temptation to adjust it until the equity curve looks better. Three habits keep that in check.
Decide before you look
The same Harvey guidance says influential observations should not be deleted without a solid economic case made before the data are examined. It also says the test sample must be defined ex ante, and that dropping the global financial crisis, the tech bubble or the 1987 crash because they hurt a model means the model does not work. Write the filter's rule and threshold into your research notes before the first run.
Document every transformation
Harvey's backtesting protocol treats data transformations, such as volatility scaling or standardization, as choices analogous to trying extra variables. They should be documented, decided in advance, and results should stay robust to minor changes in them. In practice, log for each rule: the definition, the threshold, the number of bars affected per instrument and per year, and who or what made the call.
Run a sensitivity check
Re-run your strategy with the threshold nudged, say from 2.9652 to 3.5 scaled units, and with the filter off for the flagged bars. If your edge exists only inside one narrow setting, it is probably a product of the filter. Our post on data snooping bias explains how repeated tweaking quietly leaks the future into your test, and our walkthrough of an in-sample, walk-forward and out-of-sample workflow for MT5 shows where to place the filter decision in that sequence.
Provenance matters as much as the filter
A filter is only as good as what it is given. Harvey's protocol also stresses that data provenance matters: data from neutral, well-documented providers deserves a far higher level of trust than raw data supplied by a broker. If you build your own cleaning pipeline on raw feeds, you inherit every judgment call above, plus the job of defending them.
The less visible problems also sit in the data, not in the outlier step. Weekend bars, per-year gaps and inconsistent adjustments can all distort a test as much as a spike. We cover these in our guides on three ways to remove weekend bars from forex data, a per-year gap audit for MQL4 data prep and five audit checks on clean forex data.
A repeatable outlier workflow
- Define the sample and the rule. Dates, instruments, filter type, threshold, repair policy. Write them down.
- Run structural checks. Tick size, high/low consistency, impossible ranges, duplicate or out-of-order timestamps.
- Run a robust statistical flag. A rolling MAD rule on returns, scaled so the cutoff is interpretable.
- Require a second signal. Reversal on the next bar, disagreement with related series, no matching event.
- Act per the table. Remove, repair, cap or keep, with the reason logged.
- Count and report. Bars flagged and bars changed, per instrument and year. A sudden jump in one year points at a data problem, not a market one.
- Test sensitivity. Vary thresholds slightly and confirm the result does not hinge on them.
Every step is work you must do, and every step can introduce bias if it is improvised. That is the case for beginning from a dataset where the first five have already been done to a documented standard.
Start from data that has already been cleaned
BacktestMarket sells complete, clean minute-bar historical intraday data sets going back to 2014, covering forex, metals, stock indices, bonds and commodities, ready to import directly into MT4 and MT5. Our standard is bar-by-bar verification with documented adjustments, applied for both human and AI-driven backtesting, so your outlier decisions start from a record you can cite instead of one you have to reconstruct. Engineers who collect the data answer support questions.
You can browse the historical data sets, or take the Annual Plan at €119 per year. For futures work, back-adjusted S&P 500 data is available, for example the S&P 500 back-adjusted 30-minute set.
Our view: filter less, document more
Most of the damage we see in backtests does not come from a missing filter. It comes from a filter nobody wrote down.
Our position is simple. The cleaning belongs upstream, once, at a strict standard, so that every trader testing a strategy starts from the same verified bars. That is why we check data bar by bar, document adjustments, and keep the data sets maintained for instant MT4 and MT5 compatibility.
With that foundation in place, your own filtering shrinks to a short, explicit rule: a robust threshold, a second confirming signal and a log. You spend your time on the strategy, not on arguing with a stray print at 3 a.m.
And the extremes that are real stay real. A backtest that has seen the crash bars is a backtest you can trust when the next one arrives.
Start
FAQ
Are outliers 2 or 3 standard deviations from the mean?
Both cutoffs are used, but neither is a rule of nature. Financial returns have fat tails, so a fixed standard-deviation cutoff will flag many real moves while the outlier itself inflates the standard deviation. A median-based rule such as MAD, with a documented threshold, is a sturdier starting point, followed by a check of whether the flagged bar is real.
Should I always remove outliers before a backtest?
No. Remove demonstrable errors, such as impossible prices, and keep moves supported by a market event. Deleting inconvenient crash data makes a strategy look better than it will behave live. Decide the rule before you see results, and log what it changed.
Does outlier filtering cause overfitting?
It can if you tune the threshold to improve performance. Choosing the filter and its parameters in advance, then checking that results survive small changes to them, keeps it a data-quality step instead of another optimization knob.
How do I tell a bad tick from a flash crash?
Look at what happens next and what happens elsewhere. A bad tick snaps back on the following bar and does not appear in related instruments. A flash crash shows up across correlated markets and leaves a trail of elevated volatility. Check timing against scheduled events as well.
Sources
- Clustering techniques applied to outlier detection of financial market series, ECB Working Paper No. 948
- Brownlees and Gallo, Financial econometric analysis at ultra-high frequency
- An improved algorithm for cleaning ultra high frequency data, University of Essex
- Detect outliers robustly, screamer documentation
- Filimonov and Sornette, Power law scaling and dragon-kings in drawdown distributions
- Campbell R. Harvey, research guidance, Duke University
- Campbell R. Harvey, a backtesting protocol, Duke University
- Victor Lay, EPSRC Centre for Doctoral Training final report, University of Oxford
Recommended
- Tick vs Minute Data: Which One Your Backtest Needs
- 5 Audits Quants Must Run on Outlier Handled M1 Data Before MT4/MT5
- Six Bar Aggregation Methods Quants Can Calibrate for ML Backtests
- Quants: Intraday Data Cleaning With a Three Condition Spike Test
Related resources
Explore BacktestMarket's Expert Advisor robots to put the ideas in this article into practice.

