Download MetaTrader 5

Alert only work on mouse move.

To add comments, please log in or register
Thierry Ramaniraka
422
Thierry Ramaniraka  
Hi there,
I have created this simple alert function :
double Alert_Higher_Level =  ObjectGet( "Alert_Lines_Higher", OBJPROP_PRICE1);
                  if (Bid > Alert_Higher_Level && Alert_Higher_Level>0)
                        {
                              PlaySound(Alert_Higher_Sound);
                              Alert("Alert_Higher_Sound");
                        }
And the problem is, it only plays sound and displays alert when the mouse in moving over the chart.
I need to fix this from there to "plays sound on every tick", then i can go away from my chart until the alert is displayed.

Can you please help me to fix this ?

Regards.
Matthew Colter
1167
Matthew Colter  
Do you have it inside of a method that triggers on mouse movement?
Thierry Ramaniraka
422
Thierry Ramaniraka  
Matthew Colter:
Do you have it inside of a method that triggers on mouse movement?

No....that's why i didn't understood the mouse mouvement reaction... (?)

Matthew Colter
1167
Matthew Colter  
Thierry Ramaniraka:

No....that's why i didn't understood the mouse mouvement reaction... (?)

Yes, that sounds very odd. Try to make the simplest expert where all it does is run this function on ticks. See if you still have the issue then.
Thierry Ramaniraka
422
Thierry Ramaniraka  
Matthew Colter:
Yes, that sounds very odd. Try to make the simplest expert where all it does is run this function on ticks. See if you still have the issue then.

Finally, you lead me on the good path....
I have placed my function in "OnChartEvent" instead of "OnCalculate".
Thank you.

Now, the soud is played on tick event, but maybe too much, not like the built-in alert.
How can i do it the same way please ?

Matthew Colter
1167
Matthew Colter  

Yes, on chart event would wait for a mouse move or click. The oncalculate would trigger whenever a new tick comes into the indicator. You could create a boolean variable in the top of your program and set it to true. Then when the alert and sound are triggered set it to false. Before you trigger the alert and sound, check if the value is true. The sound and alert would only happen one time this way, and you would have to reload the indicator to be able to hear the sound again.


If you want it to sound more than one time, you could create another datetime variable at the top of your program and store Time[0] in it right away. Then every time the alert and sound are made, update the datetime variable to be Time[0]. Add some code at the top of your oncalculate method that will change the boolean to true if enough time has passed between the datetime variable value and Time[0]. You can check how many seconds have passed between two datetime by subtracting the older one from the newer one.

kypa
933
kypa  

https://www.mql5.com/en/docs/basis/function/events#ontimer


You can set and kill the timer either in Init/Deinit or on alarm event creation/expiry.

Documentation on MQL5: Language Basics / Functions / Event Handling Functions
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
The MQL5 language provides processing of some predefined events. Functions for handling these events must be defined in a MQL5 program; function name, return type, composition of parameters (if there are any) and their types must strictly conform to the description of the event handler function. The event handler of the client terminal...
Thierry Ramaniraka
422
Thierry Ramaniraka  
Ok.
I have another idea to do it....so i will work on it and maybe let you know if i am lost.

thank you.
To add comments, please log in or register