SendMail Problem

 
 
And the problem is?
 
gordon:
And the problem is?

Apologies Gordon for not responding, but unfortunately I couldn’t upload text or respond to comments through IE, I’ve had to switch to Firefox.

My problem with Sendmail is similar to another message posted recently in so much that I get multiple mails sent when MetaTrader starts up and when my ind condition is met. I took note of the suggested solution using CLosetime, but this hasn’t resolved the problem.

Any other suggestions ? Unfortunately, I’m not a programmer (only a cut /paste then trial and error) so don’t understand the nuances of coding.

I also have the problem that when I switch chart timeframes and return to the original chart, my arrows have gone. I’ve checked the code but don’t have the ObjectsdeleteAll command.

I’d appreciate any advice on how I can track down the problem or a quick way to code around this ?

Thanks

Sendmail code is below;

static datetime Close_Time;

if (bar1 && bar2 && bar3 && bar4)

{

bearmark[i] = Low[i];

Sound(i, AlertFilename);

if(Email)

if (Close_Time != Time[0])

SendMail(Symbol() + " patt 1 " + ChartPeriod,"Date and Time : "+TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)+"");

}

}

}

//----

return(0);

 

Presumably you mean this ... https://www.mql5.com/en/forum/126903


The key element for the mail is the

static bool mail_flag_up=true;
static bool mail_flag_dn=true;


With a flag that switches on of off inside the condition. The condition itself then has a check if the flag is true before it send the mail. All the close is doing is identifying a new bar and was part of the OP's original code.

      if ({whatever condition} && mail_flag_up )
         {
         SendMail("EUR up", "test" );
         mail_flag_up=false;
         mail_flag_dn=true;
         }

      if ({whatever condition} && mail_flag_dn)
         {
         SendMail("EUR down", "test");
         mail_flag_dn=false;
         mail_flag_up=true;
         }

Hope that helps

V

 
Viffer:

Presumably you mean this ... https://www.mql5.com/en/forum/126903


The key element for the mail is the


With a flag that switches on of off inside the condition. The condition itself then has a check if the flag is true before it send the mail. All the close is doing is identifying a new bar and was part of the OP's original code.

Hope that helps

V


Thank you Viffer for the advice. I can see the logic that switching an e-mail flag on or off would provide the control I need.

To avoid having too many e-mails, I'm only interested in switching the flag on if the trigger condition happened recently.

Is it best to test if the bar is within the last n bars (e.g. is bar is no further than bar -10 from the current bar 0)

or is the better test, the bar time is less than n mins/secs from the current time ?


Could you advise on what would be the best option and most perfomant code ?

Much appreciate your help.


 

Personally, I think it is easier to use https://docs.mql4.com/series/iBarShift to count the bars back but it will be wholly dependent on your conditions

V

Reason: