About the Backtesting Calculator
Backtest a simple trading rule on your own price data. Paste daily closing prices or load a CSV export from Yahoo Finance, MetaTrader or Investing.com, pick a moving average crossover, an RSI oversold and overbought rule or a MACD signal-line cross, and see how the rule would have done against simply buying and holding.
The results show the strategy's return and final balance, the number of trades and the win rate, the average trade, the maximum drawdown, the time spent in the market and the fees paid, with a chart of both balances and a list of the trades.
How it works
The rule is checked at the close of every bar. A moving average crossover buys when the fast average closes above the slow one after being at or below it, and sells on the opposite cross. The RSI rule buys when RSI falls below the oversold level and sells when it rises above the overbought level. The MACD rule uses the MACD line crossing its signal line.
Each trade uses the whole balance at that bar's closing price. A trade of value V costs V times the fee rate, so a buy spends the balance divided by one plus the fee and a sale receives the value minus the fee. With shorts turned on, a sell signal also opens a short and a buy signal closes it and goes long.
Buy and hold buys on the first bar with the same fee. A position still open on the last bar is valued at the last close. The calculations are checked against an independent backtester written separately in Python.
Assumptions and limits
- Orders fill exactly at the close of the signal bar, with no slippage or spread.
- Fractional quantities are allowed, so the whole balance is always invested.
- Indicators use the textbook definitions: Wilder's RSI and EMAs started from a simple average.
Worked examples
A crossover on 9 prices
Closes 10, 9, 8, 9, 11, 12, 10, 8, 9 with a 1-bar and 2-bar average and 900 to start: buy at 9, sell at 10 for +11.11%, then buy again at 9, while buy and hold loses 10%.
The same with a 1% fee
The fee on both sides cuts the first trade's profit from 100 to 80.20 and the balance at the end to 970.49.
Going short too
With shorts on, the sell at 10 also opens a short that is closed at 9, ending at 1,100 (+22.22%).
How to use the Backtesting Calculator
- Paste the price history. Closing prices or a CSV file, oldest first.
- Pick a rule and its settings. Crossover, RSI or MACD, with fees and shorts.
- Compare with buy and hold. Return, drawdown, win rate and every trade.
Frequently asked questions
What is backtesting in trading?
Backtesting runs a trading rule over past prices to see what it would have done: when it would have bought and sold, how much it would have made or lost and how deep the falls were. It tests an idea before you risk money on it.
Does a good backtest mean the strategy will work?
No. Markets change, and a rule tuned to fit one stretch of history often fails on the next. Test on several markets and periods, keep the rules simple, and treat a result that looks too good as a warning sign.
Why compare with buy and hold?
Buy and hold is what you would get by doing nothing. A strategy that trades often but returns less than simply holding, or returns the same with bigger drawdowns, isn't adding value once your time and risk are counted.
How are fees and shorts handled?
Every buy and sale is charged the fee rate on its value, so frequent trading costs more. With shorts turned on, the backtest is always in the market after the first signal, flipping between long and short on each signal.
Where can I get price data for a backtest?
Download daily history as a CSV from Yahoo Finance, Investing.com or your broker's platform, such as the MetaTrader history centre, and load the file. The page finds the close column and puts newest-first files into date order.
This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.