Need time delay to avoiding multiple indicator notification conflict

 

I run 10 currency charts with the same set of custom indicators with multiple alert conditions triggering once every 4 hours.  I send those alerts out through notifications to my mobile.  I am working on a way to stagger the alerts by identifying the currency pair and creating a delay specific  to each pair, to be compliant with the terminal notification limits and to not miss an alert when there is a conflict.  Sleep() would be perfect, but does not work with Custom Indicators.

I next tried a time offset added to the Time[] or iTime alert trigger calculation.  Not sure why this does not work.  My understanding is that I could use a datetime variable that would contain the offset in seconds.  The offsets below are over blown to try and trouble shoot.  But the notifications in the journal do not show these values or the stagger order.

Here are the components I have been playing with, with no luck.


// Init: Set time offset (In order of increasing trade cost)
              if(Symbol()=="EURUSD") delaysec=30;  // 1
         else if(Symbol()=="GBPUSD") delaysec=50; // 2
         else if(Symbol()=="USDCAD") delaysec=70; // 3
         else if(Symbol()=="EURJPY") delaysec=90; // 4
         else if(Symbol()=="USDJPY") delaysec=110; // 5
         else if(Symbol()=="GBPJPY") delaysec=130; // 6
         else if(Symbol()=="EURAUD") delaysec=150; // 7
         else if(Symbol()=="USDCHF") delaysec=170; // 8
         else if(Symbol()=="AUDUSD") delaysec=190; // 9
         else if(Symbol()=="NZDUSD") delaysec=210; // 10
         else if(Symbol()=="EURGBP") delaysec=230; // 11
         else if(Symbol()=="AUDCAD") delaysec=250; // 12
         else if(Symbol()=="USDSEK") delaysec=270; // 13
         else if(Symbol()=="EURSEK") delaysec=290; // 14
         else if(Symbol()=="NZDCHF") delaysec=310; // 15
         else if(Symbol()=="AUDJPY") delaysec=330; // 16
         else delaysec=350; 

// After indicator code updates buffers

  // Tests to see if a new bar has started. Always fires first time through.
if(BarStartTime<(iTime(Symbol(),AlertTimeFrame,0)+delaysec)) //Tests for start of bar to execute adds offset // if(BarStartTime<(Time[0]+delaysec)) //Tried both time functions { BarStartTime=iTime(Symbol(),AlertTimeFrame,0)+delaysec; //Stores the prev bar time + offset for comparison. // BarStartTime=Time[0]+delaysec; //Tried both time functions // Notification code...

Any suggestions would be greatly appreciated.

 
Eric Beeson: Any suggestions would be greatly appreciated.
  1. You are delaying some symbols even if not required.
  2. Use a mutex. 10 calls per minute, means you do not release it until six seconds after the send.
              Prevent EA from opening trades at the same time across two or more pairs? (Steve) - MQL4 and MetaTrader 4 - MQL4 programming forum
 
whroeder1:
  1. You are delaying some symbols even if not required.
  2. Use a mutex. 10 calls per minute, means you do not release it until six seconds after the send.
              Prevent EA from opening trades at the same time across two or more pairs? (Steve) - MQL4 and MetaTrader 4 - MQL4 programming forum

Thanks for your response whroeder1!  Quite helpful. 

I am ok with arbitrary delays for separate symbols.  A few seconds of notification delay on an 4 hour bar alert is not going to be significant. 

Looks to me like the key to the mutex.mqh include function is to be able to use the Sleep() function in an indicator by calling it as an external function.  It is the core capability for creating a programmable delay. If that gets around the use of Sleep() in a custom indicator, then I should be able to generate that by a simpler version of the mutex approach.

 
Indicators can not sleep. Set a static/global variable to TimeCurrent() + 6 and return. Test on the next tick to see if a delay is expired and if true, release the mutex.
 
whroeder1:
Indicators can not sleep. Set a static/global variable to TimeCurrent() + delay(seconds) and return. Test on the next tick to see if a delay is expired.

Will give that a try.  

Reason: