lookback limits in init?

 

Dear friends, first time here, due to a "strange case".

Simple testing EA:

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
   for(int k = 1440; k >= 0; k--)
      {
       Print(TimeToStr(iTime(Symbol(), PERIOD_M1, k), TIME_DATE|TIME_MINUTES));
       Print("Bars ago: ", k, "; Open, High, Low, Close: ", DoubleToStr(Open[k], Digits), ", ", 
              DoubleToStr(High[k], Digits), ", ", DoubleToStr(Low[k], Digits), ", ", DoubleToStr(Close[k], Digits));
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Now I run it into the backtester, starting from 2011.11.28 (as everithing happens just into init, the end term has no meaning here).

I check the log, and I find this strange output:

...
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: Bars ago: 1005; Open, High, Low, Close: 0.00000, 0.00000, 0.00000, 0.00000
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: 1970.01.01 00:00
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: Bars ago: 1004; Open, High, Low, Close: 0.00000, 0.00000, 0.00000, 0.00000
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: 1970.01.01 00:00
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: Bars ago: 1003; Open, High, Low, Close: 0.00000, 0.00000, 0.00000, 0.00000
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: 1970.01.01 00:00
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: Bars ago: 1002; Open, High, Low, Close: 0.00000, 0.00000, 0.00000, 0.00000
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: 1970.01.01 00:00
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: Bars ago: 1001; Open, High, Low, Close: 0.00000, 0.00000, 0.00000, 0.00000
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: 2011.11.25 06:19
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: Bars ago: 1000; Open, High, Low, Close: 1.33104, 1.33112, 1.33103, 1.33110
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: 2011.11.25 06:20
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: Bars ago: 999; Open, High, Low, Close: 1.33110, 1.33110, 1.33105, 1.33109
22:16:38 2011.11.28 00:00  TestDataStream EURUSD,M1: 2011.11.25 06:21
...

... afterwards all normal.

So: for k > 1000 I don't have any data (even time stamp is 0). After bar 1000 back into the past, I finally have my data.

History center looks normal:

So, question: what's going on here? Why the cycle at init cannot access historic data more than 1000 "k's" ago?

Thanks in advance for all the wise replies.

Bye

DA

 
diagonAlley:

So, question: what's going on here? Why the cycle at init cannot access historic data more than 1000 "k's" ago?

Maybe it's taking too long . . init() can not run for longer than 2 secs, I think it is . .
 
RaptorUK:
Maybe it's taking too long . . init() can not run for longer than 2 secs, I think it is . .


mmm. This would be strange, because, being the cycle a "backwards one" (k big towards k small, through k--) the "right" values are the ones that actually get written in the log as the last.

And... where is it written that init() works for just 2 secs? It is OK with the 2.5 secs for deinit(), but I never heard something similar for init()...

 
diagonAlley:


mmm. This would be strange, because, being the cycle a "backwards one" (k big towards k small, through k--) the "right" values are the ones that actually get written in the log as the last.

And... where is it written that init() works for just 2 secs? It is OK with the 2.5 secs for deinit(), but I never heard something similar for init()...

OK, I imagined it . .
 
easy way to test if that's the problem, change the initial k from 1440 to like 100, that will perform below 2 seconds, and if you still get a strange output its something else.
 
AmitSharma:
easy way to test if that's the problem, change the initial k from 1440 to like 100, that will perform below 2 seconds, and if you still get a strange output its something else.


Hallo Raptor, hallo Amit,

thank you very much for your involvement and help, but... sorry. I think this is not the problem here.

I looked at 7bit's message, and, well, this 2 seconds story is really funny (I don't really understand why did they place that time limitation to init(). It makes sense with deinit(), but NOT for init()...).

The problem here is that the cycle gets performed 1440 times (Amit, of course with 100 cycles I have no problems at all...) but, for the first 440 runs I don't get any data, for the following 1000 I get the damned values correct. So: it is not a time-out problem.

Demonstration: I remade the EA.

//This is an EA
bool initialize = true;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
   //EMPTY HERE.
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(initialize)
      {
       
       for(int k = 1440; k >= 0; k--)
         {
          Print(TimeToStr(iTime(Symbol(), PERIOD_M1, k), TIME_DATE|TIME_MINUTES));
          Print("Bars ago: ", k, "; Open, High, Low, Close: ", DoubleToStr(Open[k], Digits), ", ", 
                 DoubleToStr(High[k], Digits), ", ", DoubleToStr(Low[k], Digits), ", ", DoubleToStr(Close[k], Digits));
          }
       initialize = false; 
      }   
//----
   return(0);
  }
//+------------------------------------------------------------------+

The result is exactly the same as above (refer to the pic in the first post: identical).

Still stranger! I just hypothesized there was a gap in my historical series (even if I cannot see it in the history).

I re-started the backtest, changing the start date one day after (Nov 29). The cycle would look back 1440 minutes, i.e. within the Nov 28 data, that, in the first output, were correctly printed out (the "good" final 1000 data).

The result is "depressive": first 440 runs--> empty data (timestamp = 0, i.e. 1970:01:01 00:00).

Then, last 1000 cycle runs: correct OHLC data.

If this might be relevant, on the platform, tools->Options->Charts tab, both Max Bars Numbers are set to 999999999.

Any hint from some "MetaQuotes core guru"???

Thank you in advance for all your help.

Bye

DA

 

what happen if u loop the other way around ?

for(int k = 0; k <= 1440; k++)
 
qjol:

what happen if u loop the other way around ?


Good question, easy answer:

you get data until k = 1000.

From k = 1001 on, you get empty data (timestamp, OHLC: all = 0.0).

Nice!

Thanks for the contribution, anyway.

BTW, I also tried to see whether iOpen, iHigh, i... helps somehow, but it didn't change anything (as expected, actually):

for(int k = 0; k <= 1440; k++)
         {
          Print(TimeToStr(iTime(Symbol(), PERIOD_M1, k), TIME_DATE|TIME_MINUTES));
          Print("Bars ago: ", k, "; Open, High, Low, Close: ", DoubleToStr(iOpen(Symbol(), PERIOD_M1, k), Digits), ", ", 
                 DoubleToStr(iHigh(Symbol(), PERIOD_M1, k), Digits), ", ", 
                 DoubleToStr(Low[k], Digits), ", ", DoubleToStr(Close[k], Digits));
          }

Bye

DA

 
diagonAlley:


Thank you in advance for all your help.

Bye

DA

I ran your code and got the same result . . . very strange, what version of MT4 are you using ? I tried 409.
 
RaptorUK:
I ran your code and got the same result . . . very strange, what version of MT4 are you using ? I tried 409.


409 as well (the latest).

LOL! Strange is the result, not the fact that you obtain the same output LOL!

This looks quite a weird thing. Is there a limit (=1000) into the time series access? Quite a bug, in the case! Is some MetaQuotes developer around?

Bye and thanks again.

DA

Reason: