Ibarshift return -1

 
Hello all

I have an issue to get ibarshift value.
Actually my current chart is m1 and i get open value from h1.
If i am working on future candle then i know i barshift is 0.but when i work on history bar
Let say m1 chart current time 27 oct 2021-11:55

And i try to the value of 60bar it mean then time is 27 oct 2021-10:55.. so i want to return 1 According to h1

Please help me to solve this

Thank you in advance
Megha
 

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the file.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code.

 
to get bar number from datetime :
   datetime newDt= TimeCurrent()-PeriodSeconds(PERIOD_H1);
   int n= iBarShift(_Symbol,PERIOD_M1, newDt, true);
   Print(TimeToString(newDt), " - bar: ", IntegerToString(n));

but when you use "true" & this date is absent on this chart (e.g. week_end or the hole on the chart) - of course you will get -1 -- see iBarShift...

if you'd like to get vc.vs.datetime from bar_number - you do not need iBarshift

   Print(iTime(_Symbol,PERIOD_H1,1)); 
   Print(iTime(_Symbol,PERIOD_M1,60)); 
iBarShift - Timeseries and Indicators Access - MQL4 Reference
iBarShift - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iBarShift - Timeseries and Indicators Access - MQL4 Reference
Reason: