Page 1 of 1

Pine Script Alert Condition

Posted: Thu Dec 10, 2020 8:56 pm
by trader-ap
I am having problems with random alerts and don't understand where the problem is. The following illustrates my issue. Its a very simple script that I would expect to generate an alert every 2 min on any ticker with real-time data using the option "Once Per Minute" using a 1 minute chart. However on a random basis I get an alert in between the 2 minute window

//@version=4

study("Alert Condition Test Harness")

alertcondition(minute % 2 ? 0 : 1, title="Alert Condition Test", message="Should be every 2 mins")

Here is an example Alert Log fle

Alert ID Ticker Description Time
126037673 FX:EURGBP, 1m Should be every 2 mins 2020-12-10T20:52:00.000Z As Expected
126037673 FX:EURGBP, 1m Should be every 2 mins 2020-12-10T20:51:00.000Z Did not expect
126037673 FX:EURGBP, 1m Should be every 2 mins 2020-12-10T20:50:00.000Z As Expected
126037673 FX:EURGBP, 1m Should be every 2 mins 2020-12-10T20:48:02.000Z As Expected
126037673 FX:EURGBP, 1m Should be every 2 mins 2020-12-10T20:47:01.000Z Did not expect
126037673 FX:EURGBP, 1m Should be every 2 mins 2020-12-10T20:46:01.000Z As Expected
126037673 FX:EURGBP, 1m Should be every 2 mins 2020-12-10T20:44:43.000Z As Expected

Anyone know why this would occur. The condition minute % 2 ? 0 : 1 is only true every even minute.

Re: Pine Script Alert Condition

Posted: Fri Jan 15, 2021 1:22 am
by Matthew
Hmm that's an interesting one, I'm not sure what's causing that to be honest. Try setting the alert using "Once Per Bar" on a 1 minute chart and see if that works

Dealing with time like this in Pine Script can be a bit tricky and I often run into strange issues, it's something I've been meaning to learn more about and get more practice with but because I rarely use time functions in my scripts it hasn't been high on my priority list.

But good luck and let us know if you find a solution :) you might even want to reach out to the TradingView support team, they're usually really helpful with situations like this.