Request for help.
How to write an alertif so that it can simultaneously send an alert to defined e-mails and hear an audible alert.
Entering type 1 for buy causes only the first line of alertif to work (in this case, sending an email without a sound)
and entering a different type causes repeated alerts with the same date / time.
IMPORTANT: AlertIf is not mindless function, it contains internal logic (aka. finite state machine). For full understanding how AlertIf function works and how to use it, you need to read Tutorial: Using formula-based alerts.
if( LastValue( Buy ) )
{
// mindless sending of emails and playing sound each time formula is executed
// and Buy signal is present on last bar
// (that is NOT what AlertIf is meant to do)
SendEmail("subject", "message");
PlaySound("C:\\Windows\\Media\\muzyka\\SALSATRONIC.WAV");
}
When switching type from 1 to 5, it generates a lot of email.
How to write the code so that there is 1 e-mail and 1 signal to one event from the minute candle.
Re-read (possibly several times) what I wrote previously, including all references to the Users' Manual. All the information needed is ALREADY there.
The User manual says (as I already wrote in previous reply):
Alertif function implements internal logic in the form of finite state machine that prevents repeated signals of the SAME type from occuring
Now you are getting repeated signals BECAUSE you are using different type. You wanted TWO alerts from same event (buy). TWO is more than one. TWO is repetition.
Either you use SAME type and mechanism that PREVENTS repeated alerts (so you can only have ONE non-repeated alert). Or you don't use this mechanism and you get repeated alerts.
You can't have a cake and eat it too.
I also gave you solution to this "paradox". As I wrote previously, you can use AlertIf() for email and PlaySound for sound. That way you would have non-repeated alert and repeated sound. You could also suppress repeated sound if you use static variables. Lots of such examples can be found on the forum. USE SEARCH.
As I explained already in the other post, this LastValue(Buy) is NOT needed and NOT present in original Knowledge Base Article. Now you have doubled the same condition (AlertIF(Buy) already contains "if( Buy )" logic). Again, correct code is in the original KB article, not on forum: AmiBroker Knowledge Base ยป How to execute part of the formula only when new bar is added
This code starts the music every time the timestamp changes, i.e. a new minute starts.
I did a lot of rehearsals and I have run out of ideas.
None of the conditions entered in the code worked as expected. In your example when starting Playsound, the code is to know whether it should run on buy or sell condition. I read the instructions over and over again and found no answer.
If it is so obvious, please help me, because for me it is not simple and obvious.