I am trying to confirm that I am using mt4's ibarshift correctly but the results seem to be not self consistent. I feed ibarshift a datetime, get the indice of the corresponding bar, then ask what time the bar corresponds to but I get a different datetime that I provided. I am performing this self consistency check to make sure I am accessing the bars that I think I am accessing. Any ideas would be welcomed, as this is a pretty bare bones example. I have updated my history for the chart and problems persist.
I have boiled it down to the following code:
//choose start date and an end date to study
datetime startTime = StrToTime( "2016.04.01 00:00" );
datetime endTime = StrToTime( "2019.09.30 00:00" );
Print("startTime string=",startTime);
Print("endTime string=",endTime);
//bar indices
int startBari = iBarShift("EURUSD",PERIOD_H1,startTime);
int endBari = iBarShift("EURUSD",PERIOD_H1,endTime);
printf("startBari=%i",startBari);
printf("endBari=%i",endBari);
//convert back to time
Print("start time from iBarShift = ",iTime("EURUSD",PERIOD_H1,startBari));
Print("end time from iBarShift = ",iTime("EURUSD",PERIOD_H1,endBari));