Get the App

Home / Tools / Backtest Demo

Backtest Demo: Test a Trading Strategy on Past Prices

This demo replays a simple rule on prices that already happened. It does not say what happens next. You paste a price series, pick one rule, and see the return, the drawdown, and the trades next to buy and hold, with fees. It is illustrative. It is not a profit claim.

Illustrative demo. The sample prices are made up. Results describe that series only.

Synthetic example prices, not real market data. Oldest price first. Dates, if you paste them, are labels only and are not checked.

Matches a 0.75% fee; set your own.

Runs in your browser. Nothing you enter is sent or stored.

Turn on JavaScript to calculate. The worked example below uses made-up numbers.

No AI can predict markets. A backtest shows how a rule would have done on past prices, not how it will do next.

Educational tool, not financial advice. Results are arithmetic on the numbers you enter.

How it works

The demo is long only, one position at a time, with no leverage and no shorting. A moving-average signal at a row compares that close with the average of the previous N closes, then fills at that close. That is the lookahead check: the average does not include the current close, and no later close is used. Buy with all cash when the close is above the average and you are out. Sell all when the close is below the average and you are in. Buy and hold buys at the first row and sells at the last, with the fee on both sides. Fixed-amount buying spends the amount every N rows until cash cannot cover another buy, then keeps the position through the last price. The comparison for every rule is the same cash invested at the first row and sold at the last. RSI uses Wilder smoothing. A buy is a cross below the low level while you are out. A sell is a cross above the high level while you are in. The signal uses only earlier closes.

Buy units = cash x (1 - fee) / price. Sell cash = units x price x (1 - fee). Total return = final equity / starting cash - 1.

Things this demo leaves out

Worked example

Example, made-up numbers. Sample closes, moving average length 3, cash $1,000, fee 0.75% per side, no slippage. Rows are numbered from 0.

RowClosePrior-3 averageActionResult
3105101.00Close above average: buy9.4524 units after fee
6104107.67Below: sellcash 975.67
9109102.00Above: buy8.8840 units after fee
11107108.00Below: sellcash 943.46

Summary: 2 closed trades, 0 winners (win rate 0%), final equity $943.46 (-5.65%), max drawdown -9.26% (peak $1,039.76 at row 4). Buy and hold on the same series with fees on both sides: 1,000 x 1.07 x 0.9925 x 0.9925 = $1,054.01 (+5.40%).

A rule that sounds sensible lost to buy and hold on this series. One series proves nothing either way. A backtest is a way to ask questions about the past.

Equity table for the sample (text fallback)
RowCloseWhat the rule did
0 to 2100, 102, 101No signal yet. Cash stays $1,000.00.
3105Buy. About 9.4524 units. Equity is the units marked at 105, after the fee.
4110Still in. This is the equity peak, about $1,039.76.
6104Sell. Cash about $975.67.
9109Buy again. About 8.8840 units.
11107Sell. Cash $943.46. Drawdown from the peak is -9.26%.

Edge cases and limits

Frequently asked questions

What is backtesting a trading strategy?

Backtesting trading strategies means applying fixed rules to past prices and reading what would have happened. You bring the prices, the rule, and the fees. The result is a return, a drawdown, and a list of trades for that series.

Can a backtest tell you later returns?

No. Markets change. No AI can predict markets. A backtest describes the past under the assumptions you enter.

What is lookahead bias and how does this demo avoid it?

Lookahead bias is using information that was not known yet. In this demo a moving-average signal compares the current close with the average of earlier closes only, and the fill is at that same close.

Why include fees and slippage?

Fees and slippage turn many small apparent winners into losers. A tight rule can look fine before costs and poor after them. The trading fee calculator is the dollar view of the same idea.

What is overfitting?

Overfitting is tuning a rule until it fits one history. Try other periods and other series. One result is not evidence.

For how AI tools relate to backtesting, see backtesting with AI.

Related tools

Price a fee on the trading fee calculator and a target on the risk reward calculator. The wider frame is risk management for trading.

Try it with a Moby Agent

A backtest does not trade for you. If you want an agent to act inside limits you set, Moby Agents trade on Solana, paid in USDC. You set your agent's per-trade and daily spending limits and market-cap range; Moby blocks red-rated tokens.

Moby Agents · Agentic trading