Alert only work on mouse move.

 
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.
 
Do you have it inside of a method that triggers on mouse movement?
 
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... (?)

 
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.
 
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 ?

 

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.

 

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...
 
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.
 
Hi again,
I really need some help to do my timer please....
I didn't succed.

It's always playing sound at each tick...And i need it to play sound each 3 seconds.

here is my attempt
double TLR_Alert_Higher_Level =  ObjectGet( "TLR_Alert_Lines_Higher", OBJPROP_PRICE1);
if (Bid > TLR_Alert_Higher_Level && TLR_Alert_Higher_Level>0)
                        {

                                          if ( PlaySound(TLR_Alert_Higher_Sound) )
                                                {
                                                      Sleep(3000); // sleep for X milliseconds
                                                }
                                                
                                          // PlaySound(TLR_Alert_Higher_Sound);
                                          Alert(Symbol(), " Forever TLR Alert Higher.");
                        }
 

Bonjour 

Please declare a boolean flag in the global scope,

bool direction;

Then oscillate between high and low with if and else if:

if(direction==0)
{
 if(something>high)
  {
   Alert("something is high");
   direction=1;
  }
}

else if(direction==1)
{
 if(something<low)
  {
   Alert("something is low");
   direction=0;
  }
}
 
Thierry Ramaniraka:
Hi again,
I really need some help to do my timer please....
I didn't succed.

It's always playing sound at each tick...And i need it to play sound each 3 seconds.

here is my attempt

You should be running this portion of your code from the OnTimer event. Here is an example. 

int OnInit()
{
   EventSetTimer(3);
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   EventKillTimer();   
}
//+------------------------------------------------------------------+
void OnTick(){}
//+------------------------------------------------------------------+
void OnTimer()
{
   MqlTick tick;
   SymbolInfoTick(_Symbol, tick);
   double alert_level = tick.ask;
   if(tick.bid < alert_level)
      Alert("TEST ALERT");
}
//+------------------------------------------------------------------+


 

Reason: