Questions from Beginners MQL5 MT5 MetaTrader 5 - page 667

 
Leo59:
Unfortunately, it doesn't work.

init();
if(IsTradeAllowed()) Print("Trade is allowed");
if(!IsTradeAllowed()) Print("Trade is NOT allowed");


It says: "Trading authorised"

There's got to be another way. How?

Try it like this:

starttime=(int)TimeCurrent()+sec; // например +5 секунд. Эту строку в OnInit

if(TimeCurrent()>starttime) {
...
}

I think the principle is clear, and as long as there is no tick,TimeCurrent will not change

 
Vitaly Muzichenko:

Try it this way:

starttime=(int)TimeCurrent()+sec; // например +5 секунд

if(TimeCurrent()>starttime) {
...
}

I think the principle is clear, and as long as there is no tick,TimeCurrent will not change

Yes, for Forex it's good, because ticks come often. What if it is not for Forex ?
 
Leo59:
Yes, for forex it's good because the ticks come often. What if it's not for Forex ?
The point is that during initialisation the variable "starttime" will be a few seconds longer than server time. So,when the ticks come at market opening, thenTimeCurrentwill always be more thanstarttime, and the ticks do not matter - the condition is fulfilled and will be fulfilled until the next reinitialization, for example, by switching timeframes, or reloading of the terminal.
 
Vitaly Muzichenko:
The point is that during initialisation the "starttime" variable time will be a few seconds longer than the server time.
I need to process the information now, before the first tick arrives, so that when the new (first) tick arrives, everything is ready to work.
 
Leo59:
It isn't. Check it now, if you don't mind). But, that's not the point. I need to process the information now, before the first tick arrives, so that when the new (first) tick arrives, everything is ready to go.
I've been using this for several years, but I don't need to process anything until there is no tick. You need another solution, and the link I gave you should be
 
Vitaly Muzichenko:
I've been using this for a few years, but I don't need to process anything as long as there are no ticks. You need another solution, and from the link you gave it should be
You're right, "starttime=(int)TimeCurrent()+sec; // e.g. +5 seconds", of course, is larger than TimeCurrent(). I overreacted, my brain seems to be completely melted ))
The link I gave there says only TimeLocal() but I wanted to avoid it.
 
Leo59:
You are right, "starttime=(int)TimeCurrent()+sec; // for example, +5 seconds", of course, is larger than TimeCurrent(). I overreacted, my brain seems to be completely melted ))
The link leads only to TimeLocal() and I wanted to avoid it.

Depending on the task, you can try to use a combination ofTimeCurrent()+OnTimer(), or TimeCurrent()+TimeGMT()+TimeGMTOffset()

You can do all the conditions by timer and trade byTimeCurrent() There are many solutions, but the choice is up to you for your individual task.

 
Vitaly Muzichenko:

Depending on the task, you can try to use a combination ofTimeCurrent()+OnTimer(), or TimeCurrent()+TimeGMT()+TimeGMTOffset()

You can execute all the conditions by timer and trade byTimeCurrent() There are many solutions, but the choice is up to you for your individual task.

And how, in my question, can OnTimer() be applied?
 
Leo59:
And how, in my question, can OnTimer() be applied ?
Keep the inhibit flag on until everything has been calculated, for example...
 
Artyom Trishkin:
Hold the no-work flag until everything has been calculated, for example...
Artyom, the question was about how to define a day off programmatically without resorting to TimeLocal(). ))