Download MetaTrader 5
To add comments, please log in or register
Ask your broker to open the official channel. Thousands of traders will read the news!
crispin scruby
17
crispin scruby 2014.06.12 07:17 

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
7990
Keith Watford 2014.06.12 10:13  

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 2014.06.12 10:26  
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
13641
whroeder1 2014.06.12 14:16  
  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