Problem with

 

Hello,

i want to check day of week using TimeToStruct within OnTick, when new bar occurs.

The problem: Day of week is constant

TimeToStruct on latest completed bar fetched with CopyRates,  returns no error an also the bar date

is changing.


void OnTick()
{
        if(new_bar() == true)
        {
                MqlRates        history_data[];
                int count=CopyRates(Symbol(),Period(),1,1,history_data);

                MqlDateTime xbar;

                if(TimeToStruct(history_data[0].time,xbar) == false)
                        Print("TimeToStruct failed");


                if( (xbar.day_of_week == 5 && xbar.hour >= 21) 
                        || xbar.day_of_week == 6
                        || xbar.day_of_week == 0)
                        
                {
                        StringFormat("FridayOrWeekend %s dow=%d",TimeToString(history_data[0].time),xbar.day_of_week);
                        return;
                }
        }
}


This problem occurs only with GBPUSD and not with US30 for instance. Historical data are bad but when the history_data[0] is correct, which is the case

and TimeToStruct is not failing, why is the xbar.day_of_week constant  ?

Thank you for help

 

It's not constant, what makes you think it is ?

This line is useless as is :

StringFormat("FridayOrWeekend %s dow=%d",TimeToString(history_data[0].time),xbar.day_of_week);