What is a backtest in simple terms?
Key point
A backtest moves through past price data and applies the same rule each time as if future candles did not yet exist. The method's value lies not in its equity curve, but in the ability to reproduce the test and see every outcome of the rule.
TradingView defines backtesting as recreating a strategy's performance on historical data. The object being tested is not a name such as “trend trading,” but a precise set of instructions: when an entry occurs, the price at which it is considered filled, where the exit is, what position size is used, and when a trade is skipped.
If these rules are executed by a program, that is already part of algorithmic trading; a backtest is responsible only for testing them on the selected historical data.
Consider an educational rule: after a daily candle closes above the high of the previous 20 candles, open a Long position at the next available price; exit at a predefined stop-loss order or when an opposite signal occurs. Testing it also requires a source of price data, a historical period, a method for handling price gaps, a commission, and slippage. Without them, two people will obtain different results and both will call them “the same backtest.”
A backtest has three layers. The first is market data: price, time, available volume, and corporate-action adjustments. The second is the strategy logic. The third is the execution model, which determines when and at what price a simulated order could have been filled. An error in any layer changes the result.
- 1
Idea
An observation without a conclusion about profitability
- 2
Rules
Entry, exit, stop-loss, and skip conditions
- 3
Data
Instrument, timeframe, and period
- 4
Execution
Commission, slippage, and order type
- 5
Run
Every trade, without removing inconvenient cases
- 6
Validation
An untouched data segment and a version log
Diagram 1. A backtest begins before you click “Run”: first, define the version of the idea being tested.
How does a backtest differ from a forward test and a demo account?
Key point
A backtest looks backward, a forward test applies frozen rules to new data in real time, and a demo account additionally simulates order submission. These stages answer different questions and do not replace one another.
Historical testing is convenient because it is fast. In a few minutes, you can examine numerous market episodes, compare periods, and identify an obvious weakness. However, the researcher already knows how the historical period ended and may unknowingly use that knowledge when choosing parameters.
A forward test begins after the rules have been frozen. TradingView describes it as running a strategy in real time as the chart updates. MetaTrader 5 allows the later portion of historical data to be separated for forward validation of optimization results. The general principle is the same: the validation segment must not be used to select parameters.
A demo account tests another layer: the path of a simulated order through the interface and the current price feed. It helps reveal delays, missed orders, and the behavior of different order types, but it does not create a real order queue or fully reproduce real-market liquidity. Moving to a small amount of real risk, if that is planned at all, remains a separate decision.
Historical data
Backtest
Tests the rules on a selected past period
New candles
Forward test
Parameters are frozen before the result appears
Current market
Demo account
Tests the flow of simulated orders
After testing
Decision
Accounts for discrepancies, risk, and an acceptable position size
Diagram 2. Historical data, new data, and a demo account test different causes of discrepancies; success at one stage does not make the others unnecessary.
What makes up a sound backtest: data, rules, costs, and execution
Key point
A sound backtest can be reproduced from its specification. It records the data version, exact strategy conditions, trading costs, and simulated execution rules. An unknown value is marked as unknown, not as zero.
Start with the data. Specify the ticker together with the venue, time zone, timeframe, and start and end dates. For stocks, it is important to know whether the historical data has been adjusted for splits and dividends. For futures, specify how the continuous contract was constructed. For a round-the-clock market, identify the provider from which the candles were obtained. The same symbol may have different highs and lows across data sources.
Next, rewrite the trading strategy in a form that contains no words such as “approximately,” “strong,” or “attractive.” A signal must have a computable threshold. Instead of “buy during strong growth,” write “after a close above the highest value of the previous N closed candles.” Define the exit, stop-loss order, re-entry, simultaneous signals, position size, and what to do when insufficient data is available separately.
Trading costs usually consist of more than one number. A commission may be charged on both entry and exit. The spread separates the buying and selling prices. Slippage reflects the difference between the expected execution price and the actual fill price. For high-frequency rules, even a small cost per trade can change the conclusion more than a new filter.
The execution model determines what happens within a candle. If both the stop-loss and the target were touched during the same bar, OHLC values alone are insufficient to determine which occurred first. TradingView uses a broker emulator and allows users to configure commissions, slippage, limit-order fill strictness, and delay. These settings are not cosmetic: they determine which trades appear in the report.
A minimum test specification looks like this:
- Name and version of the rule.
- Instrument, venue, data source, and time zone.
- Timeframe and exact period boundaries.
- Entry, exit, stop-loss, and skip conditions.
- Position size and re-entry rules.
- Commission, spread, slippage, and order type.
- Calculation timing: within the candle or after it closes.
- Code version or a snapshot of the settings.
If even one field changes, save a new version. Do not overwrite the old report: otherwise, the number of variants tested disappears and the risk of overfitting becomes invisible.
How to backtest manually on a chart: a step-by-step protocol
Key point
A manual test is conducted from left to right, revealing one new candle at a time. Before starting, define the rules and table; during the test, record every signal; afterward, calculate the result without removing inconvenient trades.
Manual testing is useful when a rule cannot yet be expressed in code or when you need to understand how it works. It is slower than automated testing, but it quickly exposes vague wording. If you evaluate two identical patterns differently, formalization is not yet complete.
First, select a portion of historical data and hide the right side of the chart using replay mode. Do not begin at a point you remember as the start of a major move. Record the rule version and all parameters in the table header. Then advance one closed candle at a time and make decisions using only the data visible to the left.
Save the same fields for every signal: date and time, signal price, assumed execution price, direction, stop-loss order, exit, commission, slippage, result after costs, and maximum adverse excursion during the trade. A separate “reason for skipping” column guards against cherry-picking: the absence of a trade also becomes an observation.
Manual test procedure:
- Open the chart before a period whose outcome you do not know and enable candle-by-candle replay.
- Record the instrument, period, timeframe, and rule version.
- On every closed candle, check the entry conditions in the same order.
- If there is a signal, record it before revealing the next candle.
- Apply the predefined execution model, commission, and slippage.
- Follow the trade through to its exit without moving the stop-loss order after the fact.
- Retain profitable, losing, and skipped cases.
- After finishing the segment, lock the table against edits and only then calculate the metrics.
A useful control technique is to repeat part of the sample several days later without looking at the first table. If the trades differ, the cause is usually an ambiguous rule. Clarify the wording and start a new version instead of editing individual rows in the old one.
Suitable for
- Understanding ambiguous parts of a trading rule
- Testing a small set of signals using closed candles
- Collecting examples of errors and reasons for skipping trades
Not suitable for
- Rapidly testing dozens of parameters and markets
- Precisely reconstructing the order of ticks within a candle
- Eliminating human fatigue and subjective selection
Card 1. Manual testing is a tool for formalization; a large, reproducible test is better entrusted to a strategy or testing system.
Which metrics to examine: trades, drawdown, profit factor, and streaks
Key point
First check the completeness of the sample and the number of trades, followed by the result after costs, maximum drawdown, profit factor, and worst losing streak. No single metric demonstrates robustness on its own.
The number of trades is the denominator underlying every other conclusion. Five trades may produce a high success rate by chance. There is no universal “sufficient” number: it depends on the strategy's frequency, the dispersion of results, and the variety of market regimes. This is why the length of the period and the composition of the market must always be shown alongside the number.
The net result is calculated after commissions, spread, and slippage. If some costs are unknown, present separate scenarios, such as a baseline and a more stringent one, instead of using zero. The difference between them is often more informative than one optimistic figure.
Maximum drawdown is the largest decline in capital from a local peak to the subsequent trough. It shows not only the final loss but also the path taken to reach it. Two strategies with the same ending result may require entirely different abilities to withstand a decline.
Profit factor equals the sum of profits from winning trades divided by the absolute sum of losses. A value above one means that gross profit exceeded gross loss in this sample, but it guarantees nothing on new data. If there are no losing trades, the division loses its usual meaning: instead of displaying an attractive infinity symbol, show the number of trades and note that no losses were observed.
The worst losing streak helps assess a regime in which the rule temporarily stops working and the psychological burden this creates. An average result conceals this sequence. It is also worth examining the largest winning trade: if it accounts for most of the total result, robustness depends on a rare event.
Minimum results table:
- number of all signals, executed trades, and skipped trades;
- gross profit, gross loss, and net result after costs;
- maximum drawdown in monetary and percentage terms;
- profit factor with the number of trades shown alongside it;
- percentage of profitable trades, without inferring a future probability;
- average profit, average loss, and their dispersion;
- worst losing streak;
- the largest trade's contribution to the total result.
Compare versions using the same dataset and execution model. If version A uses zero commissions while version B uses real commissions, ranking them is meaningless. Likewise, you cannot compare a daily strategy tested over ten years with a one-minute strategy tested during a single quiet month based only on profit factor.
Overfitting and other mistakes that make a backtest useless
Key point
Overfitting occurs when a rule memorizes the noise in a particular historical dataset. The more variants you review and the more freely you change parameters, the greater the chance of finding a winner that will fail on new data.
Research by Bailey, Borwein, Lopez de Prado, and Zhu formalizes the problem of selecting the best version after running numerous backtests. Even if an individual test appears methodical, a series of parameter searches turns the research into a contest for a randomly attractive result. The log must therefore retain not only the winner but also the number of variants tested.
The most obvious mistake is look-ahead bias. It occurs when a condition uses the high of a candle that has not yet closed, uses the final composition of an index for earlier years, or fills an order at a price that became known only after the signal. A less obvious form is manually choosing the start of the period immediately before a favorable trend.
The second mistake is survivorship bias. A test using today's list of assets omits stocks and funds that closed or were delisted. The result describes winners identified with hindsight. The third mistake is perfect execution: every limit order is treated as filled when touched, while commissions and slippage are set to zero.
The fourth mistake is changing the rules after every failure. An individual change is acceptable as a new hypothesis, but it must not be silently inserted into an old report. Freeze the version, split the data chronologically into a tuning segment and an untouched validation segment, and do not return to adjust the parameters after viewing the validation result.
Rules and costs defined in advance
Parameters selected using the best curve
- 1.One version
- 2.Several versions recorded in the log
- 3.A winner without the search history
Diagram 3. The danger comes not from parameter selection itself, but from a hidden search without independent validation or a record of every attempt.
Signs of a useless backtest:
- the rules cannot be reproduced from the written description;
- the period was selected after viewing the chart;
- trades were removed as “atypical” after the result was known;
- future data or data recalculated after the fact was used;
- commission, spread, and slippage are not specified;
- one bar touches both the stop-loss and the target, but the order of events is always chosen in the strategy's favor;
- only the best of many versions is shown;
- there is no separate validation segment;
- the report gives percentages without the number of trades or the test period.
Protection against these mistakes does not require complex mathematics. What is needed is an immutable version specification, a log of every test run, a reasonable cost model, a chronological split of the data, and a separate forward test. If the result disappears with a slight deterioration in execution or during an adjacent period, that is an important finding, not a reason to hide the test.
Reproducibly testing the same strategy in Midas BackTester
Key point
Midas BackTester lets you transfer formalized conditions into a TradingView bot strategy and obtain chart trades, results, drawdown, percentage of profitable trades, profit factor, and an equity curve. It makes testing faster, but it does not compensate for poor rules or data.
Use the same specification that you used for manual testing. The Midas BackTester guide describes the tool as a bot strategy in TradingView: Long and Short conditions, exits, stop-loss orders, and targets are configured through settings, while TradingView performs the historical calculations. This turns a manual idea into a repeatable configuration without rewriting the rules for every trade.
The procedure remains the same:
- Save the original wording of the entry, exit, and skip conditions.
- Record the instrument, timeframe, period, and price-data source.
- Transfer the rules into the BackTester conditions and save a snapshot of the settings.
- Set the available commission and execution parameters in the TradingView strategy properties.
- Run the test and export the trade table or save the report.
- Compare several cases with the manual log, especially price gaps and bars on which both the stop-loss and the target may have been triggered.
- Record the number of trades, net result, maximum drawdown, profit factor, and worst losing streak.
- Repeat the unchanged configuration on an untouched time period.
If the manual log and automated report differ, do not choose the more favorable result. Check the signal timing, execution price, rounding, commission, re-entries, and the order of events within the candle. No conclusion about the strategy should be drawn until the discrepancy has been explained.
What a backtest does not guarantee: the method's limitations
Key point
A backtest does not predict a future market regime, liquidity, a price gap, or a technical failure. It reduces uncertainty about a particular rule, but it does not turn a historical result into a promise.
Historical data contains only the path that actually occurred. The future may bring different volatility, a different participant structure, different commissions, and different liquidity availability. A strategy that survived a past crisis will not necessarily survive the next one because the mechanism driving the market may be different.
An emulator does not know your position in the limit-order queue or the full available volume at each price. In a thin market, a simulated order may be filled in full where a real order would have been only partially filled. A price gap may carry the price through a stop-loss order. A connection or venue failure is not a property of the trading rule at all and requires separate controls.
A percentage result from one instrument and period cannot be transferred to a user's capital. Position size, account currency, leverage, and broker restrictions change the risk. The conclusion should therefore be narrowly worded: “Version 1.3, tested on data from source X over period Y with costs Z, produced the stated result and passed/failed the untouched validation segment.”
After the backtest, leave the parameters unchanged and collect new signals. Compare trade frequency, average result, drawdown, and streaks with their historical ranges. If behavior diverges significantly, suspend interpretation and determine whether the market, data, code, or execution has changed.
Suitable for
- Testing whether a rule's result is reproducible on recorded data
- Seeing how commissions and slippage change the conclusion
- Running the rule on a segment that was not used for tuning
Not suitable for
- Predicting the future market regime and available liquidity
- Estimating your position in the real order queue at actual volume
- Accounting for price gaps, connection failures, and the restrictions of a particular broker
Card 2. The method's limitations do not negate its usefulness: a backtest reduces uncertainty about the rule, but not about the market itself.
Related rules for managing position size and loss limits are covered in the material on risk management. A good report does not itself determine an acceptable level of risk. This material is educational and does not constitute personalized investment advice.
Sources
- Sources and live pages were checked on September 7, 2026. This material is educational and does not constitute personalized investment advice. Trading in financial markets involves the risk of loss.
Frequently asked questions
What is a trading strategy backtest?
It is the application of predefined entry, exit, and risk rules to historical data. The result applies only to the selected data, settings, costs, and execution model. It helps filter out weak or ambiguous ideas, but it does not guarantee future results.
How do you backtest a strategy manually?
Write down the rules and parameters before viewing the result, hide the future portion of the chart, and advance one closed candle at a time. Record every signal in a table along with the assumed execution price, commission, exit, and outcome. Do not remove losing or inconvenient cases.
How many trades are needed for a backtest?
There is no universal number. It depends on how frequently the rule triggers, the dispersion of trade results, and the variety of market regimes. Always show the number of trades alongside each metric, test several periods, and reserve a separate data segment that was not used for tuning.
Which metrics matter most?
The basic set includes the number of trades, net result after costs, maximum drawdown, profit factor, average profit and loss, and the worst losing streak. Also check whether the entire result was produced by a single large trade.
How does a backtest differ from a forward test?
A backtest uses historical data that is already known. A forward test applies frozen rules to new data that appears after tuning is complete. It reduces the risk of overfitting, but it still does not fully reproduce real execution.
How should commissions and slippage be accounted for?
Set the commission for both sides of the trade according to the venue's current terms, and model the spread and slippage as separate parameters or through a conservative scenario. If the exact value is unknown, show a range. Do not use zero merely because the data is unavailable.
Can a high profit factor prove that a strategy works?
No. Profit factor describes the ratio of gross profit to gross loss in a particular sample. It must be considered together with the number of trades, drawdown, test period, costs, and performance on untouched data.








Comments
Source comments are not translated and are never replaced with Russian text.