Alert at end or start of bar

 

I'm sending myself alerts on certain new bars, when two of my custom functions return a 1 for example, but it seems there's some slowness or lag causing the custom functions to respond to the previous bars value... I want to send the alert 20 or seconds after the new bar has started. What is the best way to do this?

ATM I do as follows, and it's not working:

  if (Seconds() > 20) // idea is to avoid running immediately upon new bar as it seems some calculations lag so we get last periods result, only just.
    {
     if (IsNewCandle())
       {
        int confidence=0;
        confidence = (reversal() + above_below_0());
        if (confidence == 2 || confidence == -2 ) PushOver("this is an alert");
       }
    }

bool IsNewCandle()
  {
   if (NewCandleTime == iTime(Symbol(), 0, 0)) 
     {
      return false;
     }
   else
     {
      NewCandleTime = iTime(Symbol(), 0, 0);
      return true;
     }
  }
 
jepper:

I'm sending myself alerts on certain new bars, when two of my custom functions return a 1 for example, but it seems there's some slowness or lag causing the custom functions to respond to the previous bars value... I want to send the alert 20 or seconds after the new bar has started. What is the best way to do this?

ATM I do as follows, and it's not working:

Have a look at this thread - many solutions in there

https://www.mql5.com/en/forum/429994

For those who would find it useful: Behold the universal "IsNewBarOnTimeframes()" - How to detect ticks in MT4 timeframes?
For those who would find it useful: Behold the universal "IsNewBarOnTimeframes()" - How to detect ticks in MT4 timeframes?
  • 2022.08.03
  • www.mql5.com
Happy using: detecting a new bar without removing ability to detect tick in multiple timeframe - easy trading strategy - mql4 programming forum #8 (20 21. Only observation was that if you switch timeframes on the chart it can return true on the first tick - i had that issue too
Reason: