Time is relative. So are timeframes?

 

I want to collect some historical data:


TF = 60;
NumberOfBars = 1000;
datetime When = iTime(_Symbol, TF, NumberOfBars);

void Collect()   {
   Date = IntegerToString(TimeYear(When)) + "-" + IntegerToString(TimeMonth(When)) + "-" + IntegerToString(TimeDay(When));
   LogText = NumberOfBars + " bars since " + Date + "\n\n";

   get open and close values, log data etc...

}

Collect();


The log says:

1000 bars since 2022-9-12


Then I changed that to this:

TF = 1;
NumberOfBars = 60000;


1,000 bars in H1 equals 60 times as many bars in M1, right? 1,000 * 60 = 60,000.

But the log says:


60000 bars since 1970-1-1


Great Scott! That's not what I want. I was fully expecting to go back as far as 2022-9-12 again.

What did I do wrong?

 
whoowl: What did I do wrong?

You asked for the time of a nonexistent bar; you got zero and set _LastError.

 
Why is it nonexistent? What is wrong about my assumption of 1,000 * 60 = 60,000?
 
whoowl #: Why is it nonexistent? What is wrong about my assumption of 1,000 * 60 = 60,000?
  1. You haven't downloaded M1 history.
  2. Your assumption is that history magically appears.
  3. Otherwise, you will have to download history from elsewhere. MT4 history: How to Start with Metatrader 5 - General - MQL5 programming forum - Page 94 #932 (2017)

 

Thank you for the information. I read it and I believe I obtained some more bar data.

The highest number of M1 bars I can get now is 251500 so I chose:

H1   = 4,000 bars

M15 =  16,000 bars
M1   =  240,000 bars

The results:

H1: 4000 bars since 2022-3-10

M15: 16000 bars since 2022-3-10 Yes! It matches!  :-)

M1: 240000 bars since 2020-12-11 Noooo!  :-(

I could forgive one or two days off, but not one year and three months!

Why does this happen?

 
whoowl #: Why does this happen?

Asked and answered. "You haven't downloaded M1 history."

 
whoowl #: Thank you for the information. I read it and I believe I obtained some more bar data. The highest number of M1 bars I can get now is 251500 so I chose: H1 = 4,000 bars. M15 =  16,000 bars. M1 =  240,000 bars

The results: H1: 4000 bars since 2022-3-10, M15: 16000 bars since 2022-3-10 Yes! It matches!  :-), M1: 240000 bars since 2020-12-11 Noooo!  :-(, I could forgive one or two days off, but not one year and three months! Why does this happen?

Assuming no intra-day gaps, then 240000 M1 bars = 166.6 days = 33.3 weeks (5 day weeks).

However since there are ALWAYS intra-day and inter-day gaps, then time can be off quite a lot.

So, don't just assume the counting M1 bars will be equivalent to counting minutes of time.

 
William Roeder #:

Asked and answered. "You haven't downloaded M1 history."

Yes, I have. I followed the tip shared in one of the links you provided and acquired more data.

But there are discrepancies.

Anyway, I gave up on the idea of analyzing the exact same period in every timeframe.