Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1057

 
Alexey Viktorov:

Just checked, it can be changed. But this change will be for all alerts for the terminal. And if you want to use PlaySound() on each condition, you should use it, but not in someone else's function, and understand how it works yourself.

PlaySound() works independent of alerts.

I tried it, it plays two sounds both Alert and PlaySound(),

 
MakarFX:

Thank you, it worked.

But it does not solve the problem with separation of events

one more time

in the terminal settings disable the alert sound

in MQL-code output a sound using PlaySound() and then call Alert() - so you will get different sounds for different alerts, and you can't just assign a sound to alert and then change it programmatically from MQL-code

 
Igor Makanu:

again

in the terminal settings disable the alert sound

in MQL-code output sound using PlaySound() and then call Alert() - so you will get different sounds for different alerts, and it is not possible to assign any sound to alert and then change it programmatically from MQL-code

Only vice versa, first Alert() then PlaySound(). Otherwise PlaySound() won't even have time to start playing, Alert() will override it.

 
Igor Makanu:

again

in the terminal settings, disable the alert tone


You mean put an empty sound, because if you disable the alert in the settings, it does not work at all

 
Alexey Viktorov:

Only vice versa, first Alert() then PlaySound(). Otherwise PlaySound() won't even have time to start playing, Alert() will kill it.

maybe, haven't checked it.

There's a funny thing about PlaySound(), I think I need to add Sleep(150) between it and Alert, but it's not a big deal

 
Igor Makanu:

maybe, didn't check it

there are some tricks with PlaySound(), I think we need to add Sleep(150) between it and the alert, but it's nothing

Thank you.
 
Igor Makanu:

maybe, didn't check it

PlaySound() is a bit tricky, I think I need to add Sleep(150) between it and the alert, but it's not a big deal

PlaySound() with empty name stops playback of the current sound being played.

 
MakarFX:

You mean put the empty sound, because if you turn off the alert in the settings, it doesn't work at all

It took me a long time to read the code. I'm not a coder really, but of the functions there, note the following at the beginning:

extern bool UseSound = False; // Use sound

Probably need to change the value to True and already attach your sound to this function. It should not be attached together with the alert, but separately from it.

At the end of the code (the one you wrote earlier), there is the following

void Signal(string st) {

if (UseAlert) Alert(st);

if (UseComment) Comment(st);

if (UseSendMail) SendMail(WindowExpertName(), st);

if (UseSendPush) SendNotification(st);

if (UsePrint) Print(st);

if (UseSound) PlaySound(sotFileName);

}


I understand these are variables that are executed by Signal function. Therefore, this Signal function has several options of events in its code. And for each event I need to add necessary value (sound).


Let the programmers correct me if I have completely confused the question :)

 
Vitaliy Maznev:

It took me a long time to read the code. I'm not a coder really, but of the functions there, pay attention to the following at the beginning:


Let the programmers correct me if I have completely confused the question :)

The main question was about using different sounds depending on the event. UseSound only applies to PlaySound function and does not affect Alert's operation

 
MakarFX:

The point of question was, that Alert would be triggered with different sounds depending on event. UseSound refers only to PlaySound function and doesn't affect operation of Alert

So the Alert and Playsound functions are interchangeable in this case, right? Or did I get it wrong? If you can't write variables within Alert function, and you are interested in custom sound, then replace Alert with Playsound ((UseAlert) with(UseSound)) in each required event. And you will get exactly what you need. At least, logically.

Reason: