简体   繁体   中英

Use Take Profit and Stop Loss Alerts in TradingView

I have followed the answer Here to implement a Stop-Loss and Take-Profit by percentage in one script as a strategy as the code is shown.

However, now I wanna convert this strategy into an indicator v5 (study v4) adding alert functionality to it.

I used this code to trigger an alert once the enterLong condition is met however how to set the TP and SL with the same alert?

Is it possible to create one alert with TP and SL avoiding multiple alerts per trading pair, especially since TradingView's maximum allowed alerts are 400 which will be fully consumed?

Remark I'm using TP% and SL% and might include leverage not only spot trading.

alertcondition(enterLong, title="LONG", message = "long sl=SLPerc tp=TP1Perc")

If you want to use dynamic messages, I suggest you use the alert() function.

So, you can do something like this:

s = "Entry price: " + str.tostring(entryPrice) + " Stop loss: " + str.tostring(SLPerc) + " Take profit: " + str.tostring(TP1Perc)

if your_condition
    alert(s, alert.freq_once_per_bar_close)

alertcondition() does not support what you are trying to do. If you really want to use the alertcondition() , you should plot those values and use the {{plot_x}} placeholders as described here .

I intend to trigger the alert immediatly when the stop loss is hit. But as the logic is only executed when the bar is colosed, this would trigger it too late (eg if your strategy works on the 1h...). Also the "calc_on_every_tick" does not work for my strategy... How can a Stop loss alert be triggered immediatly with a message?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM