PlaySound not playing sound.

 
//+------------------------------------------------------------------+
//|                                                  Trade_Alert.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
/*
enum choice
  {
   thisOne,
   orThisOne,
   ornoThisOne
  };*/

input int             tickCount = 10; //Check every number of ticks
sinput string group1 = "Message Box";
input string increaseTradeCount = "a New Trade has been Opened."; //when less trades since prev Count
input string decreaseTradeCount = "a Trade has been Closed."; //when more trades open prev Count
string incCntComment = increaseTradeCount;
string decCntComment = decreaseTradeCount;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   static int prevCount;
   static uint prevTickCount;
   int newCount = PositionsTotal();
   uint newtickCount = GetTickCount();
   if(newCount<1 || newtickCount<prevTickCount+10)
      return;
   if(newCount>=1 && prevCount==newCount)
      return;
   if(newCount>prevCount)
      myAlert();
   else
      myAlert(true);
   prevCount=newCount;
   prevTickCount=newtickCount;
   return;
  }
//+------------------------------------------------------------------+
bool myAlert(bool closed = false)
  {
   if(closed)
     {
      string sound = "news.wav";
      PlaySound(sound);
//      Alert(decCntComment);
     }
   else
      Alert(incCntComment);
   return false;
  }
//+------------------------------------------------------------------+

The sound is not playing when closed is true. But Alert does if i remove my //.

I have a portable mt5 terminal. all sounds work on the terminal otherwise.

I have checked the resouces page in help documents. nothing jumps out at me.

 
Michael Charles Schefe:

The sound is not playing when closed is true. But Alert does if i remove my //.

I have a portable mt5 terminal. all sounds work on the terminal otherwise.

I have checked the resouces page in help documents. nothing jumps out at me.

check you have put the sound file in the Sounds folder

 
string sound = "news.wav" ;

is available on both machines?

 
Paul Anscombe #:

check you have put the sound file in the Sounds folder

yes it is there. and i have heard news.wav when news occurs in calendar.

Gerard William G J B M Dinh Sy #:

is available on both machines?

explain "both machines".

 
Michael Charles Schefe # :
explain "both machines".

The sound file is present in the same directories on both machines? The one that works and the one that doesn't?

 
Gerard William G J B M Dinh Sy #:

The sound file is present in the same directories on both machines? The one that works and the one that doesn't?

it is single machine. the terminal isnt normal installed, but "portable version", ie the 3 exe files were placed into a custom folder, sounds folder copied into same custom folder, and shortcuts to terminal exe was added suffex to commend line /portable.

PS. It made sense to me that just using "blah" would mean that the ea might look for the sound file in same folder as the ea, just as I do with my custom include files. So -- i have the news sound working now, but I had to copy the wav file and put it in experts folder.

But in the mql document help page it clearly shows the filename in 2x ".

But thanks for the suggestions.

Documentation on MQL5: Common Functions / PlaySound
Documentation on MQL5: Common Functions / PlaySound
  • www.mql5.com
It plays a sound file. Parameters filename [in]  Path to a sound file. If filename=NULL, the playback is stopped. Return Value true – if the...