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?
if(spread_1 > 0 && spread_2 < 0 && spread_3 < 0 && gatilho_tendencia == time_wait)
tendencia = "BUY";
while(gatilho_tendencia <= time_wait);
You need to use the ontimer event handler instead.
Why? Nothing is changing on the chart. Return and wait for a new call to OnTick.