A clean Pine Script strategy exit should make the stop, target, and trailing behavior easy to explain. If the exit logic cannot be explained, the backtest should not be trusted yet.
Exit logic is where many promising strategies become confusing. A trader adds a stop loss, then a target, then a trailing stop, and suddenly the backtest becomes hard to explain. My rule is simple: exits must be readable before they are optimized.

Start with one job per exit
Before writing code, decide what each exit is supposed to do. The fixed stop protects the trade. The target defines the planned reward. The trailing logic protects open profit after the trade has moved. If those roles overlap too much, the strategy may look active but become difficult to trust.
//@version=6
strategy("ATR stop + target + trailing example", overlay = true, pyramiding = 0)
fast = ta.ema(close, 20)
slow = ta.ema(close, 50)
atr = ta.atr(14)
longSignal = ta.crossover(fast, slow) and barstate.isconfirmed
if longSignal
strategy.entry("Long", strategy.long)
entry = strategy.position_avg_price
fixedStop = entry - atr * 1.5
fixedTarget = entry + atr * 3.0
trailOffset = atr * 1.2
if strategy.position_size > 0
strategy.exit("Long exit", "Long", stop = fixedStop, limit = fixedTarget, trail_offset = trailOffset)
plot(fast, "Fast EMA", color = color.teal)
plot(slow, "Slow EMA", color = color.orange)
What I check before delivery
- Does the stop use the real average entry price?
- Does the target make sense after commission and slippage?
- Does the trailing stop activate in a way the trader can explain?
- Does the result change heavily between historical and realtime candles?
- Does the alert message match the exit path shown on the chart?

How Jayadev Rana can help
If your current script has exits but the behavior feels random, I can usually identify whether the issue is position state, order ID naming, strategy.exit arguments, or unrealistic assumptions in the backtest.
Send your exit logic for a fixed-price review
Read next: Pine Script alerts by Jayadev Rana or see public examples in the Work section.
Send the chart idea, market, timeframe, and goal on WhatsApp. I can usually tell you quickly whether the next step is a custom Pine Script build, a strategy audit, or a broker-ready automation layer.
Related services
Frequently asked questions
Can Jayadev review my existing script?
Yes. Send the current Pine Script, a chart screenshot, and what you expected it to do live.
Will the code be Pine Script v6?
For new TradingView work, I prefer Pine Script v6 unless the client has a strong reason to maintain an older version.
How fast can I get a quote?
For clear requirements, I can usually give a fixed-price quote within 24 hours.
Primary sources and references
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.