Home/User Guides/Scripting

How do I backtest a strategy?

Open a strategy in the script editor, for example a starter under Templates > Strategies, and press Backtest. The Strategy Tester under your charts shows profit, win rate, drawdown and every trade. Not on CME futures yet.

Run a strategy script on your chart, and the Strategy Tester shows how it would have traded. The chart marks every entry and exit, and the tester under your charts adds up the results.

Run a strategy

  1. Open the script editor.
  2. In the editor's file list, press the templates button beside New indicator (Browse starter templates) and pick a starter under Strategies, such as Moving-Average Cross or Risk-Sized Reversion. To bring a strategy from TradingView, convert the Pine Script.
  3. Press Backtest. On a strategy it takes the place of Run.

A strip under your charts shows the result: Net, Win, DD and Trades. Click it to open the full Strategy Tester.

Read the results

  • Overview: the equity curve with its drawdown and a buy-and-hold line, plus Net profit, Win rate, Profit factor, Max drawdown, Sharpe and Trades.
  • Performance: returns, risk and trade figures, such as Sharpe / Sortino, Max runup, Avg trade / payoff and Fees paid.
  • Trades: every trade with its entry, exit and result. Hover a row to highlight the trade on the chart.
  • With two or more strategies on the chart, Compare shows them side by side.

How much history it tests

The tester follows your chart: it tests the bars around your view and runs again as you pan.

A strategy that runs in OpenMarket's cloud also has a Chart and Deep switch. Deep tests the full 20,000-bar history up to the latest bar in one run, and the result stays the same while you pan. Deep needs Plus; Chart is free.

CME futures

Custom scripts, strategies included, do not run on CME futures yet, so Backtest is paused on a CME chart. Switch the chart to another market to backtest. Can I run my own scripts on CME futures? explains why. To practice CME futures trades by hand, use paper trading.