Technical analysis

Strategy Tester: What It Does, the Main Platforms and What to Check

What a strategy tester simulates, how TradingView and MetaTrader 5 fill orders on past bars, what TrendSpider offers, the settings to change before trusting a report, and a checklist for judging any tester.

· Founder of PatternsWizard
Checked 10 min read
Sell limitsells at this price or higherBuy stopbuys if the price rises to hereBuy limitbuys at this price or lowerSell stopsells if the price falls to hereCurrent pricea market order fills here, nowAbove the priceBelow the price
On this page
  1. What a strategy tester simulates
  2. The main strategy testers
  3. Setting up the TradingView strategy tester
  4. Setting up the MetaTrader 5 strategy tester
  5. What to check in any strategy tester
  6. Frequently asked questions

A strategy tester is the part of a trading platform that runs a rule, written as code or set up in a form, over historical prices and shows the trades it would have produced: entries, exits, profit and loss, drawdown and statistics such as the win rate. It answers one question, what would this rule have done in the past, and only under the assumptions it was given. This page covers the tool itself: how the main testers work and which settings matter. The method, from writing the rule to the biases that inflate a result, is in our guide to backtesting.

Where each order type sits relative to the price

Sell limitsells at this price or higherBuy stopbuys if the price rises to hereBuy limitbuys at this price or lowerSell stopsells if the price falls to hereCurrent pricea market order fills here, nowAbove the priceBelow the price
Schematic, not market data.A strategy tester has to decide when each of these orders would have filled on past bars: a market order at the next price, a limit at its price or better, a stop once the price trades through it.

What a strategy tester simulates

The tester reads the bars one at a time. At each bar, the rule decides whether to place, change or cancel orders, and a simulated broker decides whether and at what price they fill: a market order at the next available price, a limit order at its price or better, a stop order once the price trades through it. The fill is where the simulation departs from reality. A bar records four prices, the open, high, low and close, but not the order in which they came. On a daily bar where both a stop and a target were within reach, a tester that only knows the four prices has to guess which one came first. A finer mode, minute bars or real ticks, removes much of that guess.

Inside one bar: which order fills first

TargetStopOpen nearer the highTarget fills firstOpen nearer the lowStop fills first
Schematic, not market data. The path order is the default assumption of TradingView's broker emulator; finer data replaces the guess.With a stop and a target inside the same bar, the assumed order of the high and the low decides which one the test fills.

TradingView documents its default guess: when the open is closer to the high, its broker emulator assumes the price went open, high, low, close; when the open is closer to the low, open, low, high, close. It also assumes no gaps inside a bar. On a wide bar that touched both a stop and a target, that rule alone decides whether the test books a win or a loss, which is why the bar detail setting below matters most for strategies with tight stops and targets.

The main strategy testers

PlatformHow it runs a test
TradingView (Pine Script strategies)A broker emulator that uses only the chart's data by default, assuming the price went from the open to the nearer of the high or the low, then to the other, then to the close. An order created on a bar's close fills at the earliest at the open of the next bar. Premium and Ultimate plans can use more detailed intrabar data.
MetaTrader 5 Strategy TesterTests Expert Advisors with ticks generated or recorded in one of four modes, described below, and can insert a network delay between a trade request and its execution.
TrendSpider Strategy TesterStrategies built from entry and exit conditions, built-in scripts or saved scripts, without coding, according to the platform.

TradingView keeps detailed data for up to the latest 9,000 trades, and its Deep Backtesting, on Premium and higher plans, runs the strategy on the symbol's entire available dataset. MetaTrader 5 adds optimization over parameter sets, forward testing on a part of the period kept apart, multi-currency tests, visual testing, remote agents and the MQL5 Cloud Network. On TrendSpider, long and short strategies cannot be tested at the same time, and an AI Explain button comments on the results (more in our TrendSpider review).

Setting up the TradingView strategy tester

These settings are in the strategy's "Settings/Properties" tab, and a script can set its own defaults in strategy(). The defaults are those of TradingView's Pine Script documentation.

Setting and defaultWhy it matters
Commission: noneA flat fee per order, a fee per contract or share, or a percentage of the trade value; without it every trade is free.
Slippage: 0 ticksEach order fills that many ticks beyond the intended price, against the trader. The documentation warns that too much slippage can fill orders outside the candle and make results unrealistically worse.
Order execution delay: an order created on a bar's close fills at the next bar's openRemoving the delay fills at the same close. TradingView's FAQ notes that, live, an order sent at the close of a session's last bar fills only on the next trading day, so backtest and live results can differ.
Bar detalization: chart data onlyThe "High" option, on Premium and Ultimate plans, reads bars from a lower timeframe to place fills inside each bar more precisely.
Limit order execution: fills as soon as the price touches the limitRequiring a move of one tick or more beyond the limit is closer to real trading, where a touched limit does not always fill.
Heikin Ashi mode: chart barsOn Heikin Ashi charts, fills at actual prices instead of computed ones; results on non-standard charts do not reflect actual market conditions by default.

In the strategy() declaration, the matching parameters are commission_type and commission_value, slippage, process_orders_on_close, use_bar_magnifier, backtest_fill_limits_assumption and fill_orders_on_standard_ohlc.

Setting up the MetaTrader 5 strategy tester

The MetaTrader 5 tester runs Expert Advisors, the platform's trading programs; its tick generation mode decides how much of the path inside each bar the test sees. The documentation lists five modes; four of them replay prices:

ModeWhat the documentation says
Every tickThe most accurate but the slowest of the simulated modes: all ticks are simulated.
Every tick based on real ticksUses the real ticks of the instrument accumulated by brokers, with no simulation; the first download can take a long time.
1 minute OHLCOnly the open, high, low and close of each minute bar are emulated.
Open prices onlyOnly the open price of each bar is used.
Math calculationsNo price history and no ticks: the tester only calls the program's initialization, test and shutdown functions, for mathematical calculations that need a parameter search, not for testing trades.

Three other settings change the result. The execution delay can be set to none, which the documentation calls "ideal" conditions, to a fixed delay such as the measured ping to the trade server, or to a random delay, 0 to 8 seconds 90% of the time and 9 to 18 seconds otherwise. The forward option splits the period into a back test, used for tuning, and a forward test, a half, a third, a quarter or a custom part of the period, always taken at its end, on which the chosen parameters are checked. Profit calculated in pips speeds up a test but leaves out swaps, commissions and margin control, and the documentation advises using it only for a rough estimate. The tester also loads at least 100 bars of history before the start date, so a test that starts close to the beginning of the data is shifted later.

A test period split into a back test and a forward test

Back test: tune the parametersForward test: check themlast 1/2last 1/3last 1/4Start of the periodEnd
The forward option keeps the last part of the period for the forward test; only that part was not used to choose the parameters.

What to check in any strategy tester

  • When orders fill. An order triggered by a bar's close should fill on the next bar at the earliest; a test that fills at the signal bar's close knows that close in advance.
  • What it assumes inside a bar. Find out how the tester orders the high and the low, and whether a finer mode, lower timeframe bars or real ticks, is available.
  • Costs. Commissions, spreads and slippage are often zero by default; set them, then rerun with higher costs than you expect.
  • Limit order fills. A limit touched by one tick is not always filled in real trading.
  • Chart type. Heikin Ashi, Renko and other non-standard charts show computed prices; run the test on standard candles.
  • Data. How far back the history goes, and whether it includes delisted securities. A test on today's list of stocks leaves out the companies that failed: in a study of US common stock funds, published in 1996, Elton, Gruber and Blake measured the gap between the surviving funds and all funds at about 0.9% a year (working paper version).
  • Out-of-sample testing. A forward period, or a part of the data kept out of the tuning, is the only part of a report that was not fitted.
  • The report. The number of trades, the largest drawdown and the list of trades, not just the net profit.

When an order triggered at the close can fill

Signal barNext barFill at the next open:the first price a tradercould actually getFill at the signal close:a price known onlyonce the bar is over
Schematic, not market data. The gap is drawn for clarity; the next open can also be lower than the close.The first check in the list: a test that fills at the signal bar's close uses a price no trader could have acted on.

The pitfalls behind these checks, look-ahead bias, overfitting, selection bias and survivorship bias, are explained with a worked example in our backtesting guide. TradingView's documentation adds that an overfit strategy often fails on new, unseen data, and that slippage is dynamic and unpredictable, impossible to simulate precisely.

The chart pattern figures on this site come from our own test bench, built with these checks in mind: a pattern is recorded on the bar where a trader could have seen it, and everything measured afterward starts on the next bar. One limit remains: on stocks, most companies that were delisted after a bankruptcy or a merger are missing from our data, a serious survivorship bias that we have not measured; stock results lean bullish, and the methodology says so. The full method is in our methodology.

More guides are in technical analysis.

Frequently asked questions

What is a strategy tester?

A tool that runs a trading rule over historical prices and reports the trades it would have made, with their profit, loss and drawdown. TradingView, MetaTrader 5 and TrendSpider all include one.

Is the TradingView strategy tester accurate?

It is as accurate as its settings. By default it uses only the chart's bars, applies no commission and no slippage, and fills limit orders as soon as the price touches them. Setting costs, using the next bar's open and, on Premium and Ultimate plans, setting bar detalization to High make it closer to real trading.

Which MetaTrader 5 testing mode should I use?

The MetaTrader 5 documentation calls Every tick the most accurate simulated mode and says Every tick based on real ticks, which replays the ticks recorded by brokers, provides conditions close to real ones; the first download of those ticks can take a long time. Open prices only is the fastest and suits only rules that act on the open of each bar. The fifth mode, math calculations, uses no prices at all.

Can TrendSpider backtest without coding?

Yes, according to the platform: strategies are built from entry and exit conditions or from built-in and saved scripts. Long and short strategies cannot be tested at the same time.

What is the difference between backtesting and forward testing?

A backtest runs on past data that was available while the rule was designed. A forward test runs on data the rule has never seen, either a part of history kept apart, as in MetaTrader 5's forward option, or new data as it arrives. Our backtesting guide covers both.

Which strategy tester should I use?

The one that runs on the market and data you trade, lets you set costs and slippage, fills orders at prices you could have obtained and lets you test outside the tuning sample. Check how it handles fills inside a bar before trusting its results.

Sources

  1. TradingView, Pine Script User Manual, Strategies
  2. TradingView, Pine Script User Manual, FAQ: Strategies
  3. MetaTrader 5 Help, Strategy Testing
  4. TrendSpider Help, What is the Strategy Tester
  5. Elton, Gruber and Blake, Survivor Bias and Mutual Fund Performance, Review of Financial Studies 9(4), 1996
  6. Elton, Gruber and Blake, Survivorship Bias and Mutual Fund Performance, NYU working paper, revised March 1995
, Founder of PatternsWizard

Passionate about finance, quantitative trading and data analysis. Amaury built the PatternsWizard test bench, which detects each pattern on full price history and measures what happened next against random entries.

PatternsWizard tests chart and candlestick patterns on full market history, against random entries. How we test patterns.

179 patterns testedRandom-walk self-test passed

All technical analysis articles