I am attempting to modify an indicator so that it will sound an alert using Playsound with alert2.wav and also have an alert popup. I also need other indicators to still work with alert.wav so I can't disable Tools/Options/Events.
Using Playsound with alert2.wav and having an alert popup, I always get alert and not alert2.
I am told that this can't be done in Empty4.
Does anybody have a workaround for this?
Sound file problem.
-
Radar
- Trader
- Posts: 437
- Joined: Fri Mar 23, 2012 5:39 pm
- Location: Round the bend ;)
Sound file problem.
Hey Barcode,
You could use a MessageBox instead of an alert... You will get a popup box with whatever name you give it, and you can place whatever you like in the box... Box name and contents are parameters of the function call... Here's the link on how to call one...
https://www.mql5.com/en/docs/common/messagebox (it works in mql4 with the same call).
You call PlaySound with your custom sound first, then call MessageBox with the relevant parameters.
If you have multiple alerts that you need to change to message boxes, you can use UserErrors, and pass those to a function that finds the correct error message, like so...
DisplayErrorDialogue would look something like this...
WhatYouScrewUpNow is a function that gets the last error, and returns a message...
When you set UserError to 1, GetLastError returns 65537...
When you set UserError to 2, GetLastError returns 65538, and so on.
I don't think those errors would appear in any of the logs, though, so you may have to use a Print(bugger) statement in WYSUN before the return.
Hope this helps.
Have fun!
Radar =8^)
You could use a MessageBox instead of an alert... You will get a popup box with whatever name you give it, and you can place whatever you like in the box... Box name and contents are parameters of the function call... Here's the link on how to call one...
https://www.mql5.com/en/docs/common/messagebox (it works in mql4 with the same call).
You call PlaySound with your custom sound first, then call MessageBox with the relevant parameters.
If you have multiple alerts that you need to change to message boxes, you can use UserErrors, and pass those to a function that finds the correct error message, like so...
Code: Select all
void SomeFunction()
{
blah;
blah blah;
ResetLastError();
SetUserError(1);
DisplayErrorDialogue("M1", "Enable_M1");
blah blah blah;
}
Code: Select all
void DisplayErrorDialogue(string TF, string Setting)
{
int count;
string message;
string header = StringConcatenate(IndicatorName, " ", Setting);
count++;
if (count <=4)
{
PlaySound(alert2.wav);
MessageBox(WhatYouScrewUpNow(TF), header, MB_ICONERROR | MB_OK);
} // End if (Count <=4)
if (count == 5)
{
message = cat("OK! That's it! You've screwed up 5 settings or more! '\r' '\n'",
" Did you bother to read the documentation at all??'\r' '\n'",
" I will now transfer all of your assets into my name!");
MessageBox(message, header, MB_ICONSTOP | MB_ICONERROR | MB_ICONHAND | MB_ICONQUESTION | MB_ICONEXCLAMATION | MB_OK);
} // End if (count == 5)
return;
} // End void DisplayErrorDialogue(string TF, string Setting)
Code: Select all
string WhatYouScrewUpNow(string TF)
{
int stuffup = 0;
bugger = "";
stuffup = GetLastError();
if (stuffup == 65537) bugger = StringConcatenate("Dude, you screwed up the Enable TimeFrame seting for : ", TF);
if (stuffup == 65538) bugger = StringConcatenate("You have to enter a minimum of 1 at this setting for : ", TF);
return(bugger);
} // End string WhatYouScrewUpNow()When you set UserError to 2, GetLastError returns 65538, and so on.
I don't think those errors would appear in any of the logs, though, so you may have to use a Print(bugger) statement in WYSUN before the return.
Hope this helps.
Have fun!
Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
StackManV2
-
Barcode
Sound file problem.
Fabulous. Thanks very much Radar, very much appreciated.
I'd just about given up
I'd just about given up
-
Barcode
Sound file problem.
Radar. I'm getting the alert2 sound but no popup box. The bools are definitely true.
I notice this in the MQL4 Reference "The function can't be called from custom indicators, because indicators are executed in the interface thread and shouldn't slow it down."
EDIT: Getting error 4055 Custom Indicator Error
I notice this in the MQL4 Reference "The function can't be called from custom indicators, because indicators are executed in the interface thread and shouldn't slow it down."
EDIT: Getting error 4055 Custom Indicator Error
Code: Select all
if (zonealertsounds == true)
PlaySound(SoundFileName);
if (zonealertpopups == true)
{
if (zonetype[i] == ZONE_SUPPORT)
// Alert(Symbol() + TimeFrameToString(TimeFrame) + ": Turncoat Zone Entered"); // Bob
MessageBox(Symbol() + TimeFrameToString(TimeFrame) + " Support"); // Bob
else
// Alert(Symbol() + TimeFrameToString(TimeFrame) + ": Turncoat Zone Entered"); // Bob
MessageBox(Symbol() + TimeFrameToString(TimeFrame) + " Resistance"); // Bob
}
Last edited by Barcode on Tue Mar 01, 2016 5:36 am, edited 1 time in total.
-
Radar
- Trader
- Posts: 437
- Joined: Fri Mar 23, 2012 5:39 pm
- Location: Round the bend ;)
Sound file problem.
Hey Barcode,
I'd forgotten about that tidbit of information
I started playing with MessageBox() a few weeks ago... I'm using it in an EA that has mutually exclusive settings, so didn't take much notice of the write-up.
I reckon the alert function uses PlaySound, too, which would cause it to stop playing your custom sound, and play the standard one, so just move it below the zone check... You'll get the popup alert, but since your call to PlaySound comes straight after it, it should override the original alert sound.
Have fun!
Radar =8^)
I'd forgotten about that tidbit of information
I started playing with MessageBox() a few weeks ago... I'm using it in an EA that has mutually exclusive settings, so didn't take much notice of the write-up.
I reckon the alert function uses PlaySound, too, which would cause it to stop playing your custom sound, and play the standard one, so just move it below the zone check... You'll get the popup alert, but since your call to PlaySound comes straight after it, it should override the original alert sound.
Have fun!
Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
StackManV2
-
Barcode
Sound file problem.
I was getting the alert2 sound just no messagebox. I've moved the playsound below the messagebox but not sure that will help. Just waiting for the right conditions to test it.
-
Radar
- Trader
- Posts: 437
- Joined: Fri Mar 23, 2012 5:39 pm
- Location: Round the bend ;)
Sound file problem.
Hey Barcode,
Get rid of the MessageBox lines, 'cos, as you pointed out, they don't work in indicators...
Just un-comment the alerts, and leave the PlaySound statement below the zone check...
You'll have to wait for the alert to test, though, 'cos PS doesn't work in the tester
Have fun!
Radar =8^)
Get rid of the MessageBox lines, 'cos, as you pointed out, they don't work in indicators...
Just un-comment the alerts, and leave the PlaySound statement below the zone check...
You'll have to wait for the alert to test, though, 'cos PS doesn't work in the tester
Have fun!
Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
StackManV2