set 12:00 am

 
Hello to all.

taking as an example the code iBarShift, how can I change the date in the hour 12:00 AM of the current day without having to continually change the day?

thank you
datetime some_time=D'2016.12.02 13:45';
      int      shift=iBarShift(Symbol(),PERIOD_CURRENT,some_time);
      Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
iBarShift - Timeseries and Indicators Access - MQL4 Reference
iBarShift - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iBarShift - Timeseries and Indicators Access - MQL4 Reference
 

This will give you midnight: 

datetime when     = TimeCurrent();
datetime midnight = when - (when % 86400); // there are 86400 seconds in a day

HTH 

 
Great work!

Thank you
 

I added another code to find the highest value in X candles. but I can not make it work. The code does not have errors.

      datetime when     = TimeCurrent();
      datetime midnight = when - (when % 86400); // there are 86400 seconds in a day
      datetime some_time= midnight;
      int      shift=iBarShift(Symbol(),PERIOD_CURRENT,some_time);
      Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
      
      double val;
      //--- calculating the highest value on the 20 consecutive bars in the range
      //--- from the 4th to the 23rd index inclusive on the current chart
      int val_index=iHighest(Symbol(),PERIOD_CURRENT,MODE_HIGH,shift,1+i);
      if(val_index!=-1) val=High[val_index];
      else PrintFormat("Error in call iHighest. Error code=%d",GetLastError());
      
        
      //Indicator Buffer 1
      if( val )
        {
         Buffer1[i] = High[i];        
        }
 
I solved thanks
 

I'm trying to change this value to read 2 or more days, but if I enter a higher figure to 172,800 the result value does not change.

1 day = 86400

2 day = 172800

3 day = 345600

How could I solve?

      datetime when     = TimeCurrent();
      datetime midnight = when - (when % 86400); // there are 86400 seconds in a day
      datetime some_time= midnight;
      int      shift=iBarShift(Symbol(),PERIOD_CURRENT,some_time);
      Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
 
fly7680:

I'm trying to change this value to read 2 or more days, but if I enter a higher figure to 172,800 the result value does not change.

1 day = 86400

2 day = 172800

3 day = 345600

How could I solve?

      datetime when     = TimeCurrent();
      datetime midnight = when - (when % 86400); // there are 86400 seconds in a day
      datetime some_time= midnight;
      int      shift=iBarShift(Symbol(),PERIOD_CURRENT,some_time);
      Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);

% is giving you the remainder after division.

Just add 86400 to the midnight value for midnight tomorrow:

datetime when     = TimeCurrent();
datetime midnight = when - (when % 86400); // midnight today
midnight = midnight + 86400;               // midnight tomorrow
Reason: