TradingView
ZenAndTheArtOfTrading
21 de Dic. de 2021 2:37

Trailing Stop Alerts 

EUR/USDOANDA

Descripción

This script is designed as an ATR-based trailing stop tool to assist in managing open positions.

Once you're involved in a profitable trade, if you add this script to your chart you'll be prompted to select a bar to begin trailing from.

You can then adjust the candle lookback distance for swing high/lows (7 by default), the ATR multiplier (1.0 by default), and the direction to trail (Long/Short).

You can also adjust the ATR period in the settings menu if you want to (14 period by default).

Once the script is added to your chart, it will begin drawing your trailing stop and you can then set up alerts.

Alert Options:
Any alert() function call: Will trigger an alert for both conditions (trailing stop updated, trailing stop hit)
Alert Conditions: Trailing Stop Update will trigger whenever the stop is updated, Trailing Stop Hit will trigger whenever the stop is hit.

Note: the alerts will only fire once per bar close and the trailing stop will not update on realtime bars.
Comentarios
Salem_e99
thank you for your awesome script, can i use it with Supertrend indicator? if yes please help me to change the code to get signal buy/sell instead of time
if time >= barTime and barstate.isconfirmed
timgason
Thank you so much! I've learnt so much from you!
ZenAndTheArtOfTrading
@timgason, That's awesome to hear! You're most welcome, and good luck with your trading & coding my friend :)
chrisfaron
Thanks for sharing
ZenAndTheArtOfTrading
@chrisfaron, you're most welcome mate, good luck with your trading in 2022 :)
SlikRain
Well done mate... !
ZenAndTheArtOfTrading
@SlikRain, Thank you my friend, good luck with your trading :)
kenmaxnejp
Hi I tried to extend your code demo to multiple trailing stop events and not only one, it turns out that plot is an endless line. At the moment another trailing stop will be opened, a plot line will be drawn from the close of earlier trailing stop scenario to the start of the new one. I tried to add something like "if strategy.position_size == 0, then trailPrice := na" but it didn't work. Any ideas ?
Sventastic
hi Matt,
I'm new to pine script, watched some of your youtube videos and found this script.
could you please explain the followings column?

t_trailPrice = trailType == "Long" ? ta.lowest(low, structureLookback) - atr : ta.highest(high, structureLookback) + atr

Is this like a case? when type is long do the first thing, else (represented by ":" ) do the other stuff?
maybe part of your mastery, but maybe you can help me anyway ;-)
ZenAndTheArtOfTrading
@Sventastic, yes that's exactly right, it's called a ternary operator and is just a way to write an if/else statement on one line as a single expression :)
Más