one_monk:
...If the EA starts in Sunday I do not accept data. When the EA is already started - no problems...
if you wanna know whether it's Sunday or not , this could help : [important note : TimeCurrent is called inside OnTick]
bool first_tick_ever = true; // better be a global variable bool Trades_allowed = true; // same recommendation if(first_tick_ever) { MqlDateTime TickTime; TimeToStruct(TimeCurrent(), TickTime); if(TickTime.day_of_week == 0) Trades_allowed = false; first_tick_ever = false; }
I make my own solution. This code must be putted in OnInit function.
datetime Time = TimeCurrent();
for(;;)
{
if(Time == TimeCurrent())
{
Sleep(1000);
}
else
{
break;
}
}
using infinite loops, and TimeCurrent() and Sleep() inside OnInit is not a good choice. your solution attempts all :)
Why? Where is the problem?
which if called outside OnTick, the time returned by TimeCurrent can be for up to two days ago. (or more if terminal is disconnected.)
and OnInit has a limited time window to finish. (5 seconds IIRC) so a possible infinite loop and Sleep function (and now also probably the iTime, iOpen, iHigh.... ) are not good ideas to be used in OnInit.
Ahhhhaaaaaa, I understand. My solution work on backtest but in run mode will crash my EA if it is started in weekend. I simply add a check for mode and I believe now all is ok.
Thanks for explanation Code2219 or probably 2319!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I have a problem when my testing interval starts in Sunday. I used current time for starting point (marked in yellow). If the EA starts in Sunday I do not accept data. When the EA is already started - no problems.
Can somebody gave me a solution?
CopyBuffer(Handler, 0, TimeCurrent(), 100, Array)