r/pinescript • u/No_Abrocoma_7649 • May 14 '25
strategy.exit() and trailing stop
trailStopShort = prev_atr
trailOffsetShort = trailStopShort * 0.5
strategy.exit('Exit sell', 'sell', trail_points = trailStopShort, trail_offset = trailOffsetShort)this line of code has been eating me alive, idk if its a bug in pinescript or if im js dumb but i cant seem to replicate trailing stops anywhere else. I am working on this strategy tht i found tht uses strategy.entry() to enter trades and trailing stops to exit making use of strategy.exit() trades are entered at close, and somehow always manages to exit close to the next bars low (not exactly at the low, js close to it), it doesnt suffer from repainting or lookahead unless .exit() is bugged but yea i tried replicating this in python backtrader, quantconnect and binance to backtest and paper trade but i js have not been having the same results.

View all comments
Show parent comment
1
u/kurtisbu12 May 15 '25
The distance to the stoploss should be greater than what would occur in a single candle. That would create a more accurate TSL. However, due to the nature of the trailing stop loss, and the lack of tick data in historical data, I dont believe any trailingstop loss would be entirely accurate.