Sleep without to "PAUSE" EA.

To add comments, please log in or register
Daniyyel Filipe
12
Daniyyel Filipe  

Hello guys;

I started to work with MQL5 in some months, and I have a question about the Sleep function.

I have a EA that needs to evaluate a condition every second during for exemple 1200 seconds, for this I use a while and the Sleep.

The problem is that when a use the while and the Sleep function to wait for some seconds, I can't get some values from the symbol like the bid, ask or volume, because the EA it's like "PAUSED" until the seconds is over.

Even if I put some code inside the while to calculate the prices for exemple this will not work.

There are some way to work around this?

Or maybe another way to make this verification every second?

Thanks. 


do
{
        Sleep(1000);
        if(spread_1 > 0 && spread_2 < 0 && spread_3 < 0 && gatilho_tendencia == time_wait)
        {
                tendencia = "BUY";
                break;
        }
        else
        {
                gatilho_tendencia++;
        }
}
while(gatilho_tendencia <= time_wait);
nicholi shen
2316
nicholi shen  

You need to use the ontimer event handler instead. 

https://www.mql5.com/en/docs/event_handlers/ontimer

Documentation on MQL5: Event Handling / OnTimer
Documentation on MQL5: Event Handling / OnTimer
  • www.mql5.com
//|                                               OnTimer_Sample.mq5 | //|                        Copyright 2018, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | "It is recommended to run the EA at the end of a trading week before the weekend...
whroeder1
17946
whroeder1  
Daniyyel Filipe: I have a EA that needs to evaluate a condition every second

Why? Nothing is changing on the chart. Return and wait for a new call to OnTick.

To add comments, please log in or register