Is there a way to know the date of the last bar I have in history?

 
I want to know the date/shift of the last history bar. Is there any way to do this?
 
Yes, the last bar is bar 0 . . or perhaps you meant the first bar ?
 
RaptorUK:
Yes, the last bar is bar 0 . . or perhaps you meant the first bar ?

Yes I meant the first bar.
 

Bars gives you the . . . "Number of bars in the current chart." but that isn't always going to be the same as the number of bars in the hst file, for example if you set Max bars in chart to 100 then you would only get 100 bars on the chart.

You could try an iBarShift() with a datetime of 0, but I'm not sure if this uses all the history in the hst file or just the history on your chart. Write a little test script and try it . . .

 

So from the code below its not where the chart history starts from? (edit remembering that arrays start from zero it has to be Bars -1)

int init()
  {
   Comment("chart starts from ", TimeToStr(Time[Bars-1])) ;
  }
 
Ickyrus:

So from the code below its not where the chart history starts from? (edit remembering that arrays start from zero it has to be Bars -1)

But that is not necessarily going to be the first bar in the history . . . it is the first bar on the chart.
 
In that case https://www.mql5.com/en/forum/107166 might be of interest.
 
RaptorUK:

Bars gives you the . . . "Number of bars in the current chart." but that isn't always going to be the same as the number of bars in the hst file, for example if you set Max bars in chart to 100 then you would only get 100 bars on the chart.

You could try an iBarShift() with a datetime of 0, but I'm not sure if this uses all the history in the hst file or just the history on your chart. Write a little test script and try it . . .


It worked with iBarShift() with datetime of 0 and exact = false, thanks ;)