Abnormal MQL Editor behaviour

 

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 

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

 
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 

 
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


 

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);
  }

 

 
Thanks stringo. I got it! :)