Single alert in study script

Enter and exit position explanation and code

When you create a strategy script in Trading View the strategy accounts for a single entry in your strategy (unless you specify otherwise). And when you transform your strategy script into the study your entry conditions could be met several times during the same trade. A similar scenario can happen to your exit signals. Therefore, TradingView alert will constantly send you similar signals in the same direction, which may lead to incorrect execution.

strategy in TradingView

In order to sort this problem you will have to specify the piece of code in the pine script to tell TradingView not to repeat the signal if the previous one was the same.

isEntry_Long = false
isEntry_Long := nz(isEntry_Long[1], false)
isExit_Long = false
isExit_Long := nz(isExit_Long[1], false)
entry_long = not isEntry_Long and *** INSERT YOUR ENTRY CONDITIONS ***
exit_long = not isExit_Long and *** INSER YOUR EXIT CONDITIONS ***
if (entry_long)
isEntry_Long := true
isExit_Long := false
if (exit_long)
isEntry_Long := false
isExit_Long := true

Introducing these additional criteria in your study script would monitor that there will be a single entry and exit point for your strategy and secondary exit will not occur before the exit signal.

Study in TradingView

Note

You need a TradingView Pro subscription to be able to receive Webhook notifications on Wunderbit. Sign up to TradingView now.