How to backtest a trading strategy without writing code

Backtesting shows how a trading strategy performed on past data before you risk real money. Learn what it is, why it matters and how to do it without code.

Written by
The EdgeLuma team
Published
Updated
Reading time
13 min
Table of contents
  1. What is backtesting?
  2. Why backtest a strategy before trading it live?
  3. How to backtest a trading strategy
  4. How to backtest a strategy in EdgeLuma, without code
  5. Frequently asked questions

Backtesting a trading strategy means running its rules over past market data and recording every trade they would have taken, with the fees and slippage a real trader pays. It’s the cheapest way to test an idea before you risk money on it, and it takes five steps, none of which needs code.

You’ve seen the same setup on the chart a dozen times. Price breaks above the last swing high and keeps going, and you start to think you could trade it. Before you put money on that idea, a backtest can tell you how it traded the last few hundred times it showed up, fees included.

This guide starts with what backtesting is and what it can and can’t tell you, then explains why it’s worth testing an idea before you trade it live. After that comes the method, step by step, beginning with the part most people skip: writing the idea down as objective rules. The last section shows how to do the whole thing in EdgeLuma without writing code.

What is backtesting?

Backtesting is testing a trading strategy on historical market data. You take the strategy’s rules, apply them to past candles one at a time, exactly as written, and record every trade they would have opened and closed. What you get back is a list of trades and a few numbers that sum them up: how many trades there were, what the average trade made or lost, and how deep the worst losing run went.

Picture it as a replay. If your rules trade BTC/USDT Perp on hourly candles, the backtest walks through three years of those candles, one after the other. Each time your entry condition is met, it opens a trade at the price you would have got, charges the exchange’s fee, and closes the trade wherever your stop or your exit says.

A backtest won’t tell you what the market does next. It will tell you how your rules behaved in the markets that already happened, after costs, and that’s enough to rule out most bad ideas. The result is only as good as what goes in, though: vague rules, prices from the wrong market or missing fees all give you a result for a strategy you won’t be trading.

Why backtest a strategy before trading it live?

Because a backtest is the cheapest way to find out that an idea doesn’t work. Trading a new strategy with real money is a test too, but you pay for every losing trade, and it takes a long time to learn anything. A strategy that trades twice a week needs about a year to produce a hundred trades. A backtest can replay years of the same market in a single run.

It also shows you the bad stretches before you live through them. Every strategy has losing streaks, and they’re much easier to sit through when you know they’re coming. Say the history shows your rules once lost eight trades in a row and still came out ahead over the whole test. Then a run of five losses in your live account won’t scare you into quitting. And if you know you couldn’t stomach eight in a row, you’ve learned that too, without paying for it.

A backtest also gives you a baseline. Change one rule, run it again, and you can see whether the change helped or only moved the losses somewhere else.

A good backtest isn’t the last step, though. Most traders then follow the strategy on live prices for a while, on a demo account or with very small size, which is called forward testing or paper trading. The backtest decides which ideas deserve that time.

How to backtest a trading strategy

Backtesting a strategy comes down to five steps:

  1. Write the idea down as objective rules.
  2. Choose the market, the timeframe and the test period.
  3. Include fees and slippage.
  4. Run the backtest and read the results.
  5. Check the final rules on data you didn’t use to build them.

Step 1: Write your idea down as objective rules

Objective rules are trading rules that leave nothing to judgment. Every condition is something you can check on a chart with a plain yes or no: the candle closed above the level, or it didn’t. To check, imagine handing your rules to two traders with the same chart. If the rules are objective, both will take exactly the same trades at the same prices. If they could disagree anywhere, the rules aren’t finished, and a backtest can’t run them the way you meant.

Start with the idea the way you’d say it to a friend:

I buy BTC/USDT Perp on the 1-hour chart when price closes above the last swing high, with a stop under the swing low and a target at twice my risk.

That sentence is already most of a strategy. It names a market, a timeframe, an entry, a stop and a target. But it isn’t objective yet, because two traders could still read it differently. Do you measure the swing high from the candle’s wick or from its body? If price drops back under the swing high and then closes above it again, do you buy a second time? Does the stop go exactly at the swing low or a little below it? Each answer changes the trades, so each one is part of your strategy.

Every complete set of rules answers the same six questions:

PartThe question it answersIn the example
Market and timeframeWhat do you trade, and on which candles?BTC/USDT Perp, 1-hour candles
EntryWhat has to happen, and how do you get in?A 1-hour close above the last swing high, then a market order at the next open
StopWhere is the idea wrong?At the wick of the last swing low candle before the breakout
ExitWhere do you take profit, or give up?A fixed 2R target, twice as far from the entry as the stop
SizeHow much do you risk on each trade?A fixed share of the account, such as 1%
CostsWhat does the exchange charge?Its maker and taker fees, plus slippage

Vague words are where backtests go wrong without telling you. “A strong breakout”, “a pullback”, “close to the level”: each one hides a number you haven’t chosen yet. If you don’t choose it, the software will, and you’ll end up testing its guess instead of your idea.

Step 2: Choose the market, the timeframe and the test period

Test the exact market you’ll trade. BTC/USDT Perp and BTC/USDT Spot move almost together, but they’re different markets. They have different fees and different order books, and only the perpetual pays or receives funding.

Let the timeframe come from your rules. A rule about the daily trend should be tested on daily candles. Run the same rule on 5-minute candles and you have a different strategy, with different trades and costs that take a much bigger bite out of each move.

For the period, use as much history as you can get, and make sure it includes rising, falling and sideways markets. A strategy tested only during the 2021 bull run has never seen a bear market.

What matters most is the number of trades, not the number of years. With 10 or 20 trades, luck can explain almost any result, good or bad. As a rough rule, an average starts to mean something after about 100 trades.

Step 3: Include fees and slippage

Every trade pays a fee to get in and another to get out. On top of that, an order that fills immediately usually gets a slightly worse price than the one on your screen, and that gap is called slippage. On a strategy that trades often and aims for small moves, these costs can turn a profitable backtest into a losing one.

So use the fee schedule of the exchange you’ll trade on, at the fee level your account really pays, and add slippage to every order that fills immediately. Our guide to fees and slippage in a backtest shows how much they take and why tight stops make them hurt more.

Step 4: Run the backtest and read the results

Most people look at the total profit first. It’s the number that tells you the least, because it depends on how much you risked per trade and can come from one or two lucky trades. Results are much easier to read in R.

R is the amount you risk on a single trade: the distance from your entry to your stop, multiplied by your position size. If you risk $100 on a trade, 1R is $100. Before costs, a trade that reaches a target twice as far away as the stop makes +2R. A trade stopped out at its original stop loses one R, written −1R. Since every trade is measured against its own risk, R lets you compare strategies across markets and account sizes.

A trade drawn on candles: an entry, a stop one risk unit below it, and a target two units above it, which the price reaches.Target+2REntry0RStop−1Rthe risk: 1Rthe reward: 2R
One trade measured in R. The stop sits one unit of risk below the entry and the target two units above it, so a stop-out costs 1R and a trade that reaches the target makes 2R, before costs.

Then read these numbers, roughly in this order:

  1. The number of trades is your sample size, and it limits what every other number can tell you.
  2. Expectancy is the average result per trade, in R, after costs. Above zero, the rules made money on average. Below zero, they lost money, however good some of the trades felt.
  3. The win rate only makes sense next to the payoff, the size of the average winner compared with the average loser. A strategy that wins one trade in three can still make money if its winners are three times the size of its losers.
  4. The maximum drawdown is the deepest drop from a peak in your account. It’s the worst stretch you would have had to sit through.
  5. The longest losing streak is how many losses in a row you need to be ready for, in money and in nerves.
  6. Then open the trades themselves. If one or two big trades produce most of the result, take them out and see what’s left.

Step 5: Check the final rules on data you didn’t use

Every time you change a rule after seeing a result, you fit the strategy a little more closely to that particular stretch of history. Do it enough and you’ll have a backtest that looks great on that stretch and falls apart everywhere else. That’s called overfitting, or curve fitting, and it’s one of the most common ways a backtest fools the person who built it.

Two habits keep it in check:

  • Change one thing at a time, and write down why before you run the test.
  • Before you start, set the most recent part of your history aside, for example the last year. Build and tune the rules on everything before it. When you’re done, run the final rules once on the part you held back. If the result falls apart there, the edge came from the tuning and not from the market.
One price history split in two: the rules are tuned on the first part, then run once, unchanged, on the part held back.Tuned herein-sample: the rules are fitted on this partChecked here, onceout-of-sample: never seen
Tune on one part of your history and check on the other. The rules are built on the first part, then run once, unchanged, on the part held back.

Bailey, Borwein, López de Prado and Zhu measured how easily a backtest is overfit when many versions of a strategy are tried, in The Probability of Backtest Overfitting. Harvey and Liu, in a paper simply called Backtesting, show how to discount a result for the number of versions behind it. Our guide to backtest overfitting covers the warning signs and the checks.

How to backtest a strategy in EdgeLuma, without code

EdgeLuma is a backtesting platform for crypto traders where you describe a strategy in your own words instead of writing code. It turns your description into objective rules and tests them on real market data. The five steps above work like this:

  1. Describe the strategy in the System Builder, in everyday language. The EdgeLuma AI assistant turns your description into rules. When something is left open, like which swing high you mean or where exactly the stop goes, it asks you. If it falls back on a default, such as the share of the account risked per trade, it tells you.
  2. Check the rules before you save them. EdgeLuma reads the strategy back to you in plain English, and nothing is saved until you confirm. The saved strategy is called a System.
  3. Pick the market, the timeframe and the period. EdgeLuma offers crypto and gold: spot and USDT perpetual pairs on Binance and Bybit, gold among them, long and short, on candles from 1 minute to 1 week.
  4. Keep the real costs on. An exchange preset charges the fees that exchange publishes for a new account, plus slippage on every order that fills immediately, larger for bigger positions. You can type in your own fees instead, and the report also shows the same backtest before costs, beside the result with them.
  5. Read the report. Every trade is listed and drawn on the equity curve, next to the numbers from step 4 in R. To understand a result, attach the run in the Chat and ask the EdgeLuma AI assistant, for example, why the expectancy is negative. It answers from the run’s own trades, and when you want to change a rule, it sends you back to the System Builder.

Like any backtest, a backtest in EdgeLuma replays the past. It doesn’t tell you what to trade, and nothing in a report is financial advice. What it shows you is how an idea would have done before you risk any money on it.

Test a strategy yourself: start with the Free plan, no card needed.

Key takeaways

  • Backtesting means running a strategy’s rules over past market data and recording every trade they would have taken, with the fees and slippage a real trader pays.
  • Backtest an idea before you trade it live. It’s the cheapest way to find out it doesn’t work, and if it does work, it shows you the losing streaks you’ll have to sit through.
  • A strategy can only be backtested once its rules are objective, which means two traders reading them on the same chart would take exactly the same trades.
  • Judge the result by the number of trades, the expectancy in R, the worst drawdown and the longest losing streak, then rerun the final rules on data you never tuned on.
  • EdgeLuma turns a strategy you describe in your own words into objective rules and backtests it on crypto markets, with no code.

Frequently asked questions

Can you backtest a trading strategy without coding?

Yes. A backtest needs objective rules, historical prices for the market you trade and that market’s costs. Writing the rules used to mean writing code. A tool like EdgeLuma turns a description in everyday language into the same rules, and a good tool also asks what you meant whenever your description is vague, instead of guessing.

What are objective trading rules?

Objective trading rules are rules with no room for interpretation. Every entry, stop and exit condition can be checked on the chart with a yes or a no, so two traders following them on the same chart would take identical trades. “Buy when a 1-hour candle closes above the highest high of the previous 20 candles” is objective. “Buy when the breakout looks strong” is not.

How many trades does a backtest need?

There’s no exact number, but the fewer the trades, the more of the result is luck. Over 10 or 20 trades, even a great average says very little. Around 100 trades, spread over rising, falling and sideways markets, it starts to mean something.

How much historical data should I use for a backtest?

As much as the market has, as long as it covers more than one kind of market. Count trades rather than years: three years that produce 15 trades tell you less than six months that produce 300.

What is the difference between backtesting and paper trading?

A backtest replays past data in one go, so you see years of trades in a single run. Paper trading, also called forward testing, follows the strategy on live prices without real money, so it moves at the speed of the market. Most traders backtest first and paper trade the ideas that survive.

Is a profitable backtest proof that a strategy works?

No. It’s evidence that the rules made money in the past, with the costs you included. A small sample, missing costs or rules tuned until they fit the history can all produce a profitable backtest for a strategy with no edge at all.

Which markets can I backtest on EdgeLuma?

Crypto and gold: spot and USDT perpetual pairs on Binance and Bybit, long and short, on timeframes from 1 minute to 1 week. Gold is there as XAU/USDT Perp and as the gold tokens XAUT and PAXG.

Written by the EdgeLuma teamEdgeLuma is a backtesting platform for crypto traders. Describe a trading strategy in plain words: EdgeLuma turns it into rules, replays them on years of real candles with the exchange's real fees and slippage, and shows every trade and every number, even when the strategy loses.

Every article

Keep reading

What took years of chart-watching now takes seconds.