Time fucntion question

 

Does anyone knows why this

Alert (TimeToStr(Time[2300], TIME_DATE));

Displays the date as 1970.01.01

while this

Alert (TimeToStr(Time[2299], TIME_DATE));

Displays the date as 2006.09.05

Thanks

Kam

 
knili:
Does anyone knows why this

Alert (TimeToStr(Time[2300], TIME_DATE));

Displays the date as 1970.01.01

while this

Alert (TimeToStr(Time[2299], TIME_DATE));

Displays the date as 2006.09.05

Thanks

Kam

Hi Kam!

You are very lucky that the Time[] function of the bar 2299 returned 2006.09.05. which means you have up-to 2300 bars on your chart (I'm kidding)!

The Time[] function returns the open time of the given bar!

The reason you've got 1970.01.01 for the bar 2300 is that you don't have 2300 bar on your chart and the Time[2300] have to return -1.

But the TimeToStr() function when saw -1 it returned the default date 1970.01.01.

 

Thanks for the info. I'm clear on that now

Reason: