Abnormal MQL Editor behaviour

To add comments, please log in or register
tom
45
tom  

Hello,

I get mad becouse of this problem. Please look at my OnTick() f-ion:

void OnTick()
  {
//---
        prepareData();
        if(orders()==0)
        {
                gX=0;//gX is a global int variable
                bool a=checkForBuy();//for test reasons
                if(a)//put breakpoint here
                {
                        Print("I buy");//code never reached. look further
                }
        }
  }

And here is the checkForBuy():

bool checkForBuy()
{
        if(o[gX]>c[gX])//o & c are arrays of previous open and close values
        {
                gX++;
                checkForBuy();
        }
        else
        {
                if(gX>0 && c[gX-1]<cmal(gX-1))//cmal returns some moving average value
                {
                        return(true);//put next BP here and look what happens
                }
        }
        return(false);
}

 I noticed that after return(true) in checkForBuy() f-ion. It IMMEDIATELY JUMPS TO return(false) and that is why f-ion ALWAYS returns FALSE.

I have absolutely no idea why this happens. Please point my mistake. Is it MetaQuotes fault?

 

Regards

Tilo 

Rashid Umarov
Admin
16577
Rashid Umarov  
You should fix this code in accordance with your taste because this is not our source code.

tom
45
tom  
Rosh:
You should fix this code in accordance with your taste because this is not our source code.

Excuse me but I don't understand. 

 

The question was why the MQL editor totally ignores "return(true)" and jumps to "return(false)" at end of code block. It shouldn't ever happen! I though that we have fully functional version of MQL currently.

Regards 

Rashid Umarov
Admin
16577
Rashid Umarov  
tilosag:

Excuse me but I don't understand. 

 

The question was why the MQL editor totally ignores "return(true)" and jumps to "return(false)" at end of code block. It shouldn't ever happen! I though that we have fully functional version of MQL currently.

Because function checkForBuy() is recursive one


Slava
Moderator
12368
Slava  

There is no problem with MetaEditor. Just problem with source code (or programmer writing this code). Just insert one return statement

bool checkForBuy()
  {
   if(o[gX]>c[gX])//o & c are arrays of previous open and close values
     {
      gX++;
      return(checkForBuy());
     }
   else
     {
      if(gX>0 && c[gX-1]<cmal(gX-1))//cmal returns some moving average value
          return(true);//put next BP here and look what happens
     }
   return(false);
  }

 

tom
45
tom  
Thanks stringo. I got it! :)
To add comments, please log in or register