Results 1 to 6 of 36

Thread: Help with a very small part of code please

  1. #1
    Please can anyone point out what's wrong in this part of code under, it is revealing https://www.mql5.com/en/articles/2555 and pointing that the error is on this line:
    datetime time Time[0];

    Inserted Code datetime getLastTradeTime(int kind ) datetime time = Time#91;0#93;; for(int cnt = OrdersTotal()-1;cntgt;=0;cnt--) if(! OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))continue; if(OrderMagicNumber() == MagicNumber (OrderType() == kind for(int cnt = OrdersHistoryTotal()-1;cntgt;=0;cnt--) if(! OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY))continue; if(OrderMagicNumber() == MagicNumber (OrderType() == kind return(time);

  2. #2
    Quote Originally Posted by ;
    quote I'd assume that you're calling this from OnInit, and if you are then you ought to be aware that the built-in variables aren't ready to call until after OnInit returns INIT_SUCCEEDED, thus the Time array would have no components and you're calling to get some non-existent index.
    Hi Nicholishen,
    No not from OnInit, It's under void OnTick().

  3. #3
    Quote Originally Posted by ;
    quote Hi, No not from OnInit, it is under void OnTick().
    Not sure why the platform is failing to fill that array, but you need to error proof it and check its size before calling on its own elements.

  4. #4
    I think datetime time = Time[0]; is some old code, alternative:
    https://www.mql5.com/en/forum/235955

  5. #5
    Quote Originally Posted by ;
    I think datetime time = Time[0]; is a old code, solution: https://www.mql5.com/en/forum/235955
    iTime is much better since it wont throw a fatal error, but it will still throw 4066/4073 errors that you won't even know about unless you explicitly develop your app to look for them. What this means; in case for any reason that the built in arrays aren't ready then iTime won't be either, and the difference is Time[] will have a dimension ==0 and iTime will throw a quiet 4066 error and return -1. If you're not error checking then your algo is broken by default. So either way you decide to go, you've got more work to do

  6. #6
    Quote Originally Posted by ;
    Please can anybody point out what's wrong in this part of code below, it's showing https://www.mql5.com/en/articles/2555 and pointing out that the error is on this line: datetime period = Time[0]; datetime getLastTradeTime(int kind ) { datetime period = Time[0]; for(int cnt = OrdersTotal()-1;cntgt;=0;cnt--) for(int cnt = OrdersHistoryTotal()-1...
    I would assume that you are calling this by OnInit, and if you're then you ought to be aware that the built-in factors are not ready to call until after OnInit returns INIT_SUCCEEDED, thus the Time array would have no components and you are calling to get some non-existent index.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.