PlaySound and Alert - page 2

 
Thanks Zap,

I really appreciate that. Actually, this is an EA. I am just trying to send an e-mail, or play a sound in the middle of my EA, but looks like it is impossible:) If I write this small program in a script it works fine, but when I write it in an EA, it doesn't work.

Might have something I am missing here. Any clue would be must welcome.

Thanks again folks.
 
Well, keep in mind that EAs run on incoming ticks. Put a counter to a comment, in order to monitor tick flow. There are periods (like US nigth time) when there are no new ticks for 10s of minutes, and there are no ticks on weekends at all.
Init() runs whenever you attach your EA (this is the point of it), but start() will only run first on the first new tick: this is important!
 
Thanks again. I see what is the problem. But how I can fix that?

Let's say I want to send an e-mail every time a new H4 bar starts. That seems very simple, but I have no clue how to do it. Please, which code should I put in my EA? Thanks again all of you folks.


//+------------------------------------------------------------------+
//|                                                    H4 e-mail.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net/"

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
 
CODE FOR SENDING ONE E-MAIL EACH FOUR HOUR AT THE BEGINNING OF A H4 BAR. THANKS 
 
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
Ok.... I would like to say that the e-mail is working properly now. thank you guys for the help.
 
brspMA:
Ok.... I would like to say that the e-mail is working properly now. thank you guys for the help.

How did you get the email to work??? I have yet to see a documented "How to..." for setting up the email function.

 
brspMA:
Let's say I want to send an e-mail every time a new H4 bar starts. That seems very simple, but I have no clue how to do it.
int start(){
   static datetime Time0;    bool new.bar    = Time0 < Time[0];
   if (!new.bar) return;                       Time0 = Time[0];
   ...
or
int start(){
   static datetime Time0;    if (Time0 < Time[0]){  Time0 = Time[0];
      ...
   }
 

I intend create an indicator that plays sound for 10 seconds say and then stop besides creating objects when a criterion presents itself. In the piece of code in src I have tried using either an Alert() with Playsound(NULL) or Playsound(Alert.wav) with  Playsound(null)

The problem I am facing is that once the playsound(Alert.wav) or the Alert() is activated and the sound plays and it doesn't stop at all in both the methods. Apparently the way I have coded and used the Playsound(NULL) along with a timer that I created is not doing what I expect for example <if((int)TimeNow-(int)Time[barind-1]>90000) { PlaySound(NULL); Print(__LINE__," NULL HIT @diff ", (int)TimeNow-(int)Time[barind-1]); }

The second issue is that when the PlaySound(Alert.wav) is activated I intend to create a popup that gives me an option to stop the music being played by clicking a button, or something to that effect that enables a manual close earlier than 10 seconds.

I have used (int) before all time parameters in order for the time to convert into milliseconds. Also, I have modified the Alert.wav file to include 1 hour long jazz music for example.

Any inputs and suggestions would be apppreciated.

if(Time[0]>TimeNow)
     {
      int barind=Bars-barcount-1;
      TimeNow=Time[0];
      TimeNowCT=TimeCurrent();
      while(barind>1)
        {

         
         SMA20_[barind]= iMA(Symbol(),0,20,0,0,1,barind);
         SMA50_[barind]= iMA(Symbol(),0,50,0,0,1,barind);
         double SMA20_b_1 = iMA(Symbol(),0,20,0,MODE_SMA,PRICE_WEIGHTED,barind-1);
         double SMA50_b_1 = iMA(Symbol(),0,50,0,MODE_SMA,PRICE_WEIGHTED,barind-1);
         
         if((ChartSymbol()==Symbol() &&  Close[barind-1]>Open[barind-1] && Close[barind-1]-SMA20_b_1>EPSILON))
           {
            CloseUp[barind-1]=High[barind-1]+0.0007; //Indicator up down arrow plot
            
            //if(TimeNow > Time[0]) PlaySound("Alert.wav"); /* 9 = SND_ASYNC | SND_LOOP */
            //Alert(Symbol(),",",__LINE__," Time ",Time[barind]);
            PlaySound("alert.wav"); 
            if((int)TimeNow-(int)Time[barind-1]>90000) { PlaySound(NULL); Print(__LINE__," NULL HIT @diff ", (int)TimeNow-(int)Time[barind-1]); }
            if((int)TimeCurrent()-(int)Time[barind-1]<10000)
              {
               
               PlaySound("alert.wav"); 
               Print(__LINE__," soundplayed @",Time[barind-1],",t[0],",TimeNow,",TC,",(int)TimeCurrent(),",diff,",(int)TimeCurrent()-(int)Time[barind-

1],",timenowCT,",TimeNowCT);
               
              }
             else{
             PlaySound(NULL); 
             Print(__LINE__," NULL HIT @diff ", (int)TimeCurrent()-(int)Time[barind-1]);}
            
           }
 

You can only use Alert function, no need to use PlaySound function.

- Rename the file 'alert.wav' in folder 'C:\Program Files (x86)\... MetaTrader4\Sounds' to 'temp.wav'

- Copy the sound file '*.wav' to the folder 'C:\Program Files (x86)\... MetaTrader4\Sounds'

- Rename the sound file '*.wav' to 'alert.wav'

Reason: