Pausing email on startup until loaded

 

Hi.. Newby to MQL4 trading and alerts,  and a mass of code I will work through in time but need a safe and quick solution.

I have an indicator I added an email alert to using a copied code:-

if (EmailON) SendMail("message", "message, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());

All good there hopefully... but on loading this loops for all the prior alerts..... (I have placed this after the code for if(displayAlert == true) so that it sends when the alert is triggered.

This creates two issues, one of the not enough space that I'm not bothered as it can be cleared, and it causes a spam issue which causes servers to block in some way returning the message "too many messages" (code I cant recall) and can cause it to block normal emails via email clients like outlook also for the server used. The spaming issue makes trial and eror a bit impractical. Takes a while to resolve each time.

Now I'd rather not wait a year for a solution trawling through code, but will if need be, but more specifically losing my email server constantly isnt an option....

If someone could help it would be appreciated greatly. I want it for one indicator only really at mo, and can get around it by using emailon=false and then enabling once loaded, then no probs it just sends an email when an alert is triggered,  but for profile changes with many pairs monitoring its not practical, or even one pair over a few timeframes as it creates the spam problem on the servers....

Any help with code to tell the indicator to ignore "emailon" on startup only would be appreciated.

I have tried a few things, but not familiar with coding yet. Some suggested code has stopped the indicator loading at all or caused it to ignor all prior signals so not loading anything on the indicator on startup... (Close but not really whats wanted)

Any help greatly appreciated... The code tried out has been placed in the:-

 int start()

  {
   int countedBars = IndicatorCounted();
   if(countedBars < 0)
       countedBars = 0;
   CalculateIndicator(countedBars);
//----

   return(0);

//-- 

Entered after the CalculateIndicator(countedBars);

Help Help Help.. and cheers in advance for any aspiring coders out there.... I know the solution is a simple coding issue and I may find it eventually as I notice that you only get the last alerts on startup on these indicators, so the coding is there for me to decipher..... Its just a bit cloudy fo rme at the mo... Cheers....

 
Philstrading:


Any help greatly appreciated... The code tried out has been placed in the:-

int start()

  {
   int countedBars = IndicatorCounted();
   if(countedBars < 0)
       countedBars = 0;
   CalculateIndicator(countedBars);
//---- 

   return(0);

//-- 


Please read some other posts before posting . . .

Please   edit   your post . . .    please use the   SRC   button to post code: How to use the   SRC   button. 

 
Philstrading:

Hi.. Newby to MQL4 trading and alerts,  and a mass of code I will work through in time but need a safe and quick solution.

I have an indicator I added an email alert to using a copied code:- if (EmailON) SendMail("message", "message, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());

All good there hopefully... but on loading this loops for all the prior alerts..... (I have placed this after the code for if(displayAlert == true) so that it sends when the alert is triggered.

This creates two issues, one of the not enough space that I'm not bothered as it can be cleared, and it causes a spam issue which causes servers to block in some way returning the message "too many messages" (code I cant recall) and can cause it to block normal emails via email clients like outlook also for the server used. The spaming issue makes trial and eror a bit impractical. Takes a while to resolve each time.

Just check the bar number the indicator is working on,  if it's greater than 5 ( or other low number of your choice )  don't sent emails.
 

Humm, not sure exactly what you're looking for. However a simple solution would be creating a variable which checks for first_run. if( _1st_run_completed == false ){ email_on=false; }else{ email_on=true; }

You can then turn _1st into true at the end of start. You could also just turn email_on at the end of start. Or when indicator_counted == bars. You have allot of options to choose from like time_lapse would be another example. Or you can also make use of the init() function.

 
RaptorUK:
Just check the bar number the indicator is working on,  if it's greater than 5 ( or other low number of your choice )  don't sent emails.

Cheers, but will need to decipher that. Have noted the SRC button and other buttons thanks...


My initial quick work around just thought about now whilst relaxing before my scans which I don't know whether it will work until the markets live again, as its OK on bootup but dont know if it will send when enabled after program launch of profile change. Is:-


I've removed the EmailOn variable altogether...... and changed the code so that it is as below (in the code quote)

I disable email in options and turn back on when after loading the program or a profile, using different instances of install for higher timeframe monitoring when away.

I stopped spam on trials by putting bogus server data in the options email menu and I try it with internet cable removed first..

I use a testing install of MQ4 for trials only..


This will give me time to do some learning, and if it works give me a work around as I only want it to pick up on divergences for higher timeframes whilst I'm at work so I can take a peak.

Here's the modified code which I hope will work when I enable the email in options:-

if(displayAlert == true)
           DisplayAlert("Reverse bullish divergence on: ", 
                        currentTrough); 
                        if(displayAlert == true)
                        SendMail("Reverse bullish divergence", "Reverse bullish divergence, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());

I load and then enable the email in options. Hopefully then when an alert triggers the email will be run too. Not sure whether I will need to take out the second 

if(displayAlert == true)

however I will be trialing the code above first to see what happens...

The internet book is a bit too assuming and difficult to navigate..... so I'm going to be looking around for some good books.... It looks much like visual basic... but think its not...

Thanks for the response.... I will take a look at what you suggested and see if I can work out what it means... :)

 
ubzen:

Humm, not sure exactly what you're looking for. However a simple solution would be creating a variable which checks for first_run. if( _1st_run_completed == false ){ email_on=false; }else{ email_on=true; }

You can then turn _1st into true at the end of start. You could also just turn email_on at the end of start. Or when indicator_counted == bars. You have allot of options to choose from like time_lapse would be another example. Or you can also make use of the init() function.


Thanks... I will take a look at this too...

Much appreciated...

 

Looped on first indicator alert.... blocked me email for that account again ... will be looking at the code functions suggested ... (and only running through testing install & bogus server till sorted)

Cheers

 
Philstrading:

Looped on first indicator alert.... blocked me email for that account again ... will be looking at the code functions suggested ... (and only running through testing install & bogus server till sorted)

Usually the first time an Indicator runs it runs for ALL bars . . .  you don't want an Alert for bars that occurred 9 months ago or 2 years ago . . .  just enable the Alert for the most recent bars,  to prevent the alert on the same recent bar save the time of the bar you are alerting for to a variable and only Alert of the bar time for the alert is greater than the saved bar time . . .
 
RaptorUK:
Usually the first time an Indicator runs it runs for ALL bars . . .  you don't want an Alert for bars that occurred 9 months ago or 2 years ago . . .  just enable the Alert for the most recent bars,  to prevent the alert on the same recent bar save the time of the bar you are alerting for to a variable and only Alert of the bar time for the alert is greater than the saved bar time . . .


Thanks again RaptorUK...

I'm saving these comments in a file to work the problem.

Taken another look at the online book, starting to make sense now, learned to have to navigate the folders in chm viewer for the downloadable file, but its explaining the expressions and logic well,.

I don't Auto trade but currently use RSI, Stoch and MACD with candles to assess momentum and direction with trend and cycle analysis with Multiple Timeframes.... The MACD divergence indicator is spot on to the candle and can see ddivergences I don't always pick up on with lower timeframes.... This allows me to monitor my main pairs whilst focussing on my favourite AUDUSD.... I want this to use as an email alert whilst at work on the divergences so I might be able to pop and take a sneaky trade, as well as when out and about or otherwise occupied.... 


This will be weekend work for me now as I'm one of these screen watchers for intraday trading....

I look forward to some happy coding...

Cheers....

Reason: