Download MetaTrader 5

Bug in Build 646?? - re: Bars function and for loop - very very weird!

To add comments, please log in or register
crispin scruby
17
crispin scruby  

Hello MQL4 folks - I've been coding in MQL4 for a long time... this morning I was writing some code and noticed some very weird behaviour...... in the end I wrote a billy basic test routine and quite frankly I can't explain what on earth is going on here...  

Try this:- 

int OnInit()

  {
  Do_Calc();
  return(INIT_SUCCEEDED);
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])

  {
  return(rates_total);
  }

void Do_Calc()
{
int p;
int b=Bars;
Print ("Bars=",Bars);
Print ("Test");
for (p=0; p<b; p++)
      {
      Print (p);
      }
}        

 

Experts output:

experts op 

 

Errr..... OK ...  so the print statement were skipped and the loop jumps straight to 297....  I can't explain this at all... doesn't seem logical.

 

If you change the max iteration value in the loop to an integer such as 100... the program runs OK - so code mod to:-

 void Do_Calc()
{
int p;
int b=Bars;
Print ("Bars=",Bars);
Print ("Test");
for (p=0; p<100; p++)
      {
      Print (p);
      }
}

experts op:

 

 

So it appears there's a bug to do with the Bars function.... has this been deprecated?? 

 

MQL4 Ref makes direct reference to Bars in for loop..... 

 

Doesn't seem to work so well in Build 646 - tried rebooting machine - purging memory - copying code to new indy... makes no sense at all! 

Keith Watford
Moderator
9642
Keith Watford  

I haven't studied your post in depth.

Always check the actual experts log file. Whole swathes are often missed in the experts tab.

crispin scruby
17
crispin scruby  
GumRai:

I haven't studied your post in depth.

Always check the actual experts log file. Whole swathes are often missed in the experts tab.


OK - fair enough - I gave up trying to work out why it wasn't displayed in the experts tab and just carried on coding - things seem to be operating normally - it's just a bit irritating when you're debugging if print statements and loop contents don't get accurately reported in experts... I didn't know the experts tab sometimes misses program output data....good tip to check the log... I've been coding mql4 since 2007 so it's good to learn something new. Cheers
whroeder1
14781
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Look in the log FILE
To add comments, please log in or register