richmusic
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: September 21st, 2023
Contact: TradingView Profile

Does this exist?

Does anyone know of a script or how to script a way to have Tradingview move the stoploss automatically to break even after price reaches a certain level? I don't want a trailing stop, I just want something that will move the stop to break even after it reachers a certain point. Does that exist, or can someone write the script, or do you know if that's possible? I'm very new to all of this programming. Thank you.

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: Does this exist?

To set the SL to break even simply update the stop value to the entry price of the trade when the RR ratio is met.

e.g. if you had an strategy.exit statement as strategy.exit(id="Long Exit", from_entry="Long", limit=t_target, stop=t_stop) then you save the entry price in a variable when your strateg.entry function is run then set your t_stop variable to that entry price so the next time the strategy.exit statement is read it will be setting the stop as the entry price (break even)

Return to “Pine Script Q&A”