How to initialize if EA starts in sunday

 

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)

 

one_monk:

...If the EA starts in Sunday I do not accept data. When the EA is already started - no problems...

re-stating your question will help a lot.

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;

          }

      }

 
one_monk:

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?
 
one_monk:
Why? Where is the problem?
TimeCurrent returns the time of last tick of any pair active in MarketWatch window.
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.
 
if you state your problem exactly (giving a few weekday and times examples) it will be easier to suggest a solution
 

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!