2

I am having problem with setting up alerts on an indicator with buy, sell, short, cover lables.

The condition for the signals is a when in trend. But at the moment I get a new alert for every candle my script is in trend. And obviously I only want it on the first bar in trend.

How can I set up my alert() or alertcondition() so it only will trigger once?

1 Answers1

0

You need to have a variable to check if the event is changed.

For example, say you want to trigger an alert when the trend direction changes.

uptrend = ... // Your definition of the uptrend
downtrend = ... // Your definition of the downtrend

is_new_uptrend = not uptrend[1] and uptrend  // It was not an uptrend one bar ago AND it is an uptrend now
is_new_downtrned = not downtrend[1] and downtrend  // It was not a downtrend one bar ago AND it is a downtrend now

alertcondition(is_new_uptrend, "New uptrend")
alertcondition(is_new_downtrend, "New downtrend")
vitruvius
  • 15,740
  • 3
  • 16
  • 26