Optimize stop loss and take profit levels with a TradingView backtest
Test stop loss and take profit ranges on your TradingView strategy, then check whether the findings hold up on unseen data.
On this page
- How can you test exit levels on your strategy?
- What must the exit inputs control?
- How do you choose ranges for the stop and target?
- How do you run the combinations by hand?
- What should you compare besides the ranking?
- How do costs and fills affect the comparison?
- How do you inspect nearby combinations?
- How do you check the pair on unseen data?
- When is the test not ready to interpret?
- Sources
Key takeaways
- Test stop loss and take profit values as a pair while keeping the rest of the experiment fixed.
- Check that each input controls the intended exit and uses the expected unit.
- Review nearby combinations and trade details rather than relying on a single ranking.
- Keep later data separate from the search and record the assumptions behind the test.
How can you test exit levels on your strategy?
To test stop loss and take profit levels, make each exit distance an input in your strategy, define a range for each, and compare combinations on the same historical data. Keep the entry rules, position sizing, chart and test assumptions fixed while you search, then check the selected combination on data that was not used to choose it.
A stop loss is an exit intended to limit a loss when price moves against a position, while a take profit is an exit intended to close a position when price reaches a favorable level. Neither label establishes the price at which an actual order would fill, and a historical simulation cannot establish what will happen in a future market.
The question is not simply which pair sits at the top of a report, but whether the test measures the exit rules you intended and whether nearby pairs behave in a consistent way. The guide to choosing parameter ranges covers the broader range design process; here the focus is the interaction between the stop and the target.
Start with a copy of your own strategy and record its current settings before making changes, so you have a reference for the experiment without treating the original settings as a result that the search has to improve. Save the original code or identify its version as well, because a later comparison is hard to interpret if the rules have changed along with the inputs.
What must the exit inputs control?
Each input needs a clear unit and a clear connection to the exit calculation, because values that look similar can represent different quantities in the strategy. A distance expressed in ticks, the smallest price increments for an instrument, is not the same thing as a percentage of entry price or a price level.
TradingView’s strategy FAQ, checked 2026-11-18, says its stop and limit parameters specify exit prices, while loss and profit specify distances in ticks from the entry price. If your script converts a percentage or another distance into an exit price, check the conversion separately for long positions and short positions, including the reference price used by the calculation.
For a long position, the stop would normally sit below the entry reference and the target above it, while for a short position those directions reverse. Inspect the code and plotted levels, if your script provides them, to see whether the calculation follows the intended direction and reference price for each kind of position.
A bracket is a pair of exit orders intended to close a position at either a stop or a target, depending on which condition triggers an exit in the simulation. Check that the bracket is attached to the intended entry, that its quantity matches the position you mean to test, and that another exit rule does not make either input irrelevant.
A trailing stop, which moves according to a rule as price changes, is a different experiment from a fixed stop, so record which behavior your strategy actually uses. If a trailing rule has its own inputs, changing them alongside a fixed target can make the comparison harder to interpret.
TradingView’s input documentation, checked 2026-11-18, says changing an input makes the script run again across available data. Change each exit input and inspect the resulting levels and trades before starting a larger search, since a visible input alone does not establish that it controls the exit you intend to study.
If changing an input does not affect the relevant exit, investigate the script rather than interpreting the unchanged report as evidence about the level. Note any condition that disables an exit or replaces it with another rule, since that condition can also explain why a particular input appears to have no effect.
How do you choose ranges for the stop and target?
A range is the set of values you permit the test to consider, and a step is the spacing between adjacent values in that set. Describe both ranges in the units used by the script, including the lower and upper bounds, before reviewing the search results or selecting a pair for further review.
Use bounds that represent the question you want to investigate rather than a collection of values chosen after seeing a promising report from the same historical period. For example, a test can ask how exits behave across a relatively tight and a relatively wide region, without assuming either region is suitable for actual trading.
The stop and target interact because a change to either can alter which exit is reached and how long a position remains open, potentially changing later entries as well. Testing the stop with a fixed target can be useful for diagnosing that stop, but it does not describe every possible pairing within the ranges you planned.
A joint search asks a different question: how the available stop values behave alongside the available target values under the same strategy rules and test assumptions. Write that question down before the sweep, so the later interpretation does not confuse a limited comparison with a broader search.
A fine step can reveal detail, but it also creates more combinations and gives the search more chances to fit peculiarities of the selected history. A coarse step leaves more of the range untested, so a promising area may need a separate, clearly recorded review rather than an assumption about the values between tested points.
Check that each step makes sense for the instrument’s price increment and for the precision the script actually uses when it calculates an exit price. Keep a note of any invalid or duplicated values created by rounding, since treating identical exit prices as distinct evidence can make a region appear more thoroughly tested than it is.
How do you run the combinations by hand?
For a manual sweep, list the stop values along one side of a worksheet and the target values along the other, using the units recorded in your plan. Each cell represents a pair to enter into the strategy, run on the same chart and record with the report details you chose in advance.
Before the sweep, save the strategy version, symbol, chart timeframe and test period, along with any other settings that could affect the comparison. A timeframe is the duration represented by each chart bar, and it belongs in the record because a different timeframe describes a different test.
Record the cost and fill assumptions as well, because a pair tested under different assumptions is not a direct repeat of the same experiment. Enter a pair, record the settings and relevant report observations, then move to the next pair without changing the entry logic or position sizing.
Continue until the planned combinations are covered, or mark the worksheet clearly if you stop early, so that an empty cell cannot be mistaken for a poor result. If you discover an error during the sweep, record which runs it affected and repeat those comparisons under the corrected setup.
TradingTune is a free Chrome and Brave extension that adds a search panel to TradingView’s strategy dialog. It backtests your input combinations, ranks every run live, and sends the best settings back to your strategy. The ranges and the meaning of the inputs still come from the strategy and the experiment you designed, so they need the same checks as a manual sweep.
Whether the search is manual or automated, keep a record of what was actually tested and distinguish a completed search from one that stopped early. If the method samples combinations rather than covering the full worksheet, note the gaps before making claims about the shape of the whole range.
The method selection guide explains how the search approach relates to the size of the space and the work available for the experiment. Keep the method with the run notes, because a list of tested pairs does not by itself explain how those pairs were chosen.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
What should you compare besides the ranking?
Choose a primary metric, meaning the report measure used to order the combinations, before running the search, and write down why it relates to your research question. Then record the other observations that could change your interpretation, such as the number of closed trades, the length of positions and periods when equity falls from a prior high.
A report can rank a pair highly even when its trade history is too thin to support a useful comparison with other pairs in the search. A different pair may produce a larger set of trades because positions close sooner, leaving the strategy free to enter again when its entry conditions occur.
That comparison does not isolate the exit of every individual trade, so inspect how the trade sequence changed as well as the summary in the report. A later entry may exist under one pair and not another, making the change in the full sequence part of the finding rather than a separate detail to ignore.
Keep the position sizing rule fixed during the sweep, and record whether that rule uses the stop distance when it calculates the size of a position. If the rule changes size in response to the stop distance, changing the stop then changes both the exit and the exposure.
An apparent difference between pairs may reflect that combined design rather than the exit distance alone, so describe the sizing dependency when you write up the comparison. Review examples of trades where the exit changed, including positions that closed at the stop, positions that closed at the target and positions closed by another rule.
Note whether a changed exit also changed later entries because the strategy was no longer in the earlier position, and keep those examples with the run notes. The guide to reading backtest metrics explains what common measures can and cannot describe, including why no single measure tells the whole story.
How do costs and fills affect the comparison?
A fill is the simulated execution of an order at a particular price, as represented by the assumptions used in the historical test. The stop level is an instruction in the test, not proof that a real order would exit at that exact price, especially when prices move quickly or jump across a level.
TradingView’s strategy properties page, checked 2026-11-18, says its slippage setting adds ticks to the fill price of simulated market or stop orders. Slippage is the difference between an expected price and the price used for a fill, so record the assumption without treating it as a complete model of every market condition.
Commission is a trading fee included in the simulation when configured, and pairs that close positions at different frequencies can be affected differently by those costs. Apply the same cost assumptions throughout the initial comparison, and use the cost modeling guide for more detail about the setup.
Chart bars summarize price movement rather than showing every event that happened inside the period, which matters when both exit levels fall within the same bar’s range. If a bar reaches both exit levels, the simulated sequence can depend on the test’s fill assumptions and the detail available to it for that historical period.
Inspect affected trades and document the chart and fill settings rather than assuming the report proves which level was reached first in the market. A separate check under different plausible assumptions can show whether the comparison is sensitive to the model, although it cannot recreate every possible execution condition.
Label that review as a new check, not as another attempt to choose the pair on the original conditions, and preserve the assumptions for each run. If the interpretation changes materially, include that dependence in the conclusion so the selected pair is not presented without the context that shaped its report.
How do you inspect nearby combinations?
A parameter neighborhood is the group of tested pairs close to a particular stop and target pair, based on the steps and ranges used in the search. Looking at that neighborhood helps distinguish a broad area of similar behavior from an isolated result surrounded by very different observations in the same test.
Return to the worksheet and compare adjacent cells, including pairs that vary the stop while holding the target fixed and pairs that vary the target while holding the stop fixed. Also look at diagonal neighbors, where both inputs change, because the interaction may not be visible along either axis alone when the other input stays fixed.
The parameter sensitivity guide describes this kind of review in more depth and explains why a single peak deserves careful interpretation. For the exit test, record whether the nearby cells have enough trades to interpret and whether the same assumptions apply across the neighborhood you are comparing.
A smooth-looking table with missing or invalid cells can hide a very incomplete search, so mark gaps rather than filling them with assumptions. If the top pair lies at a range boundary, the test has not shown what happens beyond that boundary under the same rules.
Expanding the range after seeing the result is a new research decision, so document the change and do not present the original search as though it included the added values. An isolated peak may reflect a feature of the selected history rather than a durable property of the exit rule across different periods.
A broad region is not proof of future behavior either, but it gives you a more informative question to carry into a separate test than a single unexplained cell. Preserve the table with its gaps and notes so another review can see which comparisons support that question and which remain open.
How do you check the pair on unseen data?
Set aside a later period before starting the search, and keep its report out of the selection process while comparing the planned exit pairs. The search period is the historical data used to compare and select pairs, while the held-out period is data reserved for a check after that selection.
The in-sample and out-of-sample guide explains the split and its limits, including why the later period needs to remain separate from selection. Record the selected pair and the reason for selecting it before opening the held-out report, so the choice can be traced back to the original research rules.
Keep the strategy version, sizing rule, cost assumptions and selection criteria fixed for that check, so the later result answers the question you actually asked during the search. Decide how the test treats a position that spans the boundary between periods, and record that choice before inspecting the later trades.
For example, a test may start the held-out period flat, or it may carry an existing position into the later period if the setup allows it. Either choice changes the interpretation, so apply it consistently when comparing pairs and note which trades are affected by the boundary.
Inspect the trade history and the same report measures used in the search, rather than changing the basis of comparison after seeing the later data. A difference between periods can reflect the exit pair, the market conditions, the sample of trades or the test setup, and the report alone may not separate those causes.
The held-out check is evidence about this particular split, not a guarantee that the pair will behave similarly elsewhere or under different assumptions. If you repeatedly change the pair after inspecting the held-out period, that period becomes part of the selection process rather than an independent check.
Record the revision and reserve another untouched period for a later check, if suitable data is available and the revised question still has a clear purpose. When it is not available, describe the remaining uncertainty instead of calling the reused period independent or treating the revised choice as confirmed.
When is the test not ready to interpret?
Pause the comparison if the exit inputs do not control the intended orders, the units are unclear or the report contains too little trade activity to explain the differences between pairs. A search can sort the available observations, but sorting does not repair an unclear rule or create more evidence about a sparse trade history.
Check for changes in the underlying data, strategy code or chart settings before comparing a repeated run with the original, and record any difference that affects the test. Repainting means that a script’s historical and real-time behavior can differ; investigate whether the entry or exit logic depends on values that may change before a bar closes.
The site’s lookahead bias article covers a related problem, using information before it would have been available to the strategy at the time. An exit comparison cannot resolve that issue on its own, so check the underlying logic before drawing a conclusion from the ranked pairs.
Keep the final research note specific, with the ranges, steps, period split, strategy version, cost assumptions, selected pair and reason it was selected. Include missing combinations, boundary results and any trade examples that made the comparison hard to interpret, together with the assumptions used for the separate check.
If the later check differs from the search, preserve that finding rather than changing the story to fit it or quietly repeating the selection. The practical output is a documented test of your own exit rules, with limits that another review can inspect and repeat.
Sources
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.