WhatsAppFast quote
strategy.exit · Pine Script

TradingView Pine Script v5 strategy.exit Stop Limit Syntax — What It Really Means

This keyword usually hides one big confusion: in strategy.exit, stop and limit are usually being used to define bracket exits, not a single stop-limit entry concept.

Pine Script Strategy April 17, 2026 10 min read Updated April 9, 2026
Syntax plus behavior The real problem is usually the runtime meaning, not the keyword alone
v6 examples Shown in current Pine Script style
Backtest-aware Exit logic should survive both the tester and the live chart
TradingView Pine Script v5 strategy.exit stop limit syntax article cover
Quick summary

This keyword usually hides one big confusion: in strategy.exit, stop and limit are usually being used to define bracket exits, not a single stop-limit entry concept.

Keyword trap Stop + limit wording is often misunderstood
Best answer Know what the order function actually creates
Useful next step Validate the exit logic with a small template first
About the author

Jayadev Rana has been building Pine Script systems since 2017 and writes these guides from the perspective of someone who has to make live behavior, alerts, and execution logic make sense together. If you want to check the public side of that work first, use the Work section, the Proof Hub, and the linked TradingView releases before you decide anything.

tradingview pine script v5 strategy.exit stop limit syntax

This article is written for traders who want the idea explained clearly enough to use, test, or challenge in real conditions.

Want examples before you message?

Use the Proof Hub and Work section if you want to see public examples first. If your main question is about your own setup, go straight to WhatsApp.

What strategy.exit is really doing here

For a query like tradingview pine script v5 strategy.exit stop limit syntax, the biggest confusion is usually around meaning, not raw syntax. In Pine Script, strategy.exit() is how you define exit orders for an open position. The interesting part is whether you are defining a stop-loss, a take-profit, a trailing behavior, or a bracket that combines both stop and limit levels.

That distinction matters because a lot of traders use the words “stop limit” loosely when they really mean “I want both a stop-loss and a target on the same position.” Those are not the same thing conceptually, and they should not be documented as if they were.

  • use stop when you mean the loss-protection price
  • use limit when you mean the take-profit price
  • do not assume stop + limit means one combined entry order
  • always check how the strategy tester is interpreting the exits

The clean pattern most traders should start with

A basic bracket exit is usually the best starting point: one entry, one stop price, one target price. That keeps the logic inspectable before you add partial exits, trailing behavior, or stateful management.

If the simple bracket is unclear, the complicated version will not become clearer later.

Copyable Pine Script v6 syntax reality check
//@version=6
strategy("Exit syntax reality check", overlay = true)

if ta.crossover(ta.ema(close, 20), ta.ema(close, 50))
    strategy.entry("L", strategy.long)

if strategy.position_size > 0
    stopPrice  = strategy.position_avg_price * 0.99
    limitPrice = strategy.position_avg_price * 1.02

    // In strategy.exit(), stop + limit creates a stop-loss and take-profit bracket.
    // It is not a single stop-limit entry order.
    strategy.exit("Bracket", "L", stop = stopPrice, limit = limitPrice)
The example uses v6 syntax because that is the clearer way to write the concept now, even if the search term still says v5.

Common mistakes that make the syntax look broken

Many complaints about strategy.exit are really design complaints. The code may compile, but the trader expected behavior the function was never meant to provide. The most common example is expecting a single stop-limit style object when the code is actually defining two separate exit thresholds for a bracket.

  • placing exit logic without checking whether the position is open
  • mixing percentage thinking with raw price levels carelessly
  • treating a target and a stop as if they were one concept
  • building the complex version before the simple bracket has been tested

How I check whether the exit logic is trustworthy

I want the exit logic to answer three questions cleanly. When does the trade become invalid? When is profit good enough to take? And does the tester behave the same way the author thinks the code behaves? If those answers are muddy, the exit block is not ready yet.

Need the strategy exit block reviewed?

If the exit syntax is compiling but the behavior still feels wrong, send the relevant block on WhatsApp. I usually check whether the levels, order timing, and expectations are aligned before changing anything else.

WhatsApp for a 3-minute quote

What to read next

If this topic is part of a bigger TradingView or Pine Script workflow for you, these are the most useful follow-up guides on the site.

Want a second pair of eyes on your setup?

Send the chart idea, broker, market, and goal on WhatsApp. I can usually tell you quickly whether it needs a custom indicator, a strategy audit, an alert fix, or a broker-ready automation layer.


Frequently asked questions

Can strategy.exit use stop and limit together?

Yes. That is the normal way to create a bracket exit with a stop-loss and take-profit level for an open position.

Is stop plus limit in strategy.exit the same as a stop-limit entry order?

No. In strategy.exit, those parameters define exit thresholds for an existing position. They are not the same thing as a single stop-limit entry concept.

Why does my strategy.exit block compile but behave strangely?

Usually because the trader expectation and the actual order behavior are not aligned. The issue is often the logic around the function, not the function name itself.

Should I use raw price levels or percentage offsets?

Either can work, but the safer choice is whichever makes the exit logic easiest to inspect and explain for that specific strategy.

If you want this built properly

I take on Pine Script indicators, TradingView automation layers, strategy audits, and broker-aware execution workflows when the goal is clear and the live behavior actually matters.