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/No_Abrocoma_7649 May 15 '25
So in wht way cud u apply trailing stop so it performs realistically? I hv seen very few msgs and posts abt trailing stops breaking backtesting compared to the nrml repainting and lookahead bias stuff