When i Historical backtesting this my expert,What's wrong with this function

 

bool openstat(string name,string ordertp,int magicx){       bool stat=false;       bool haveopen=false;       if(OrdersTotal()>0){         for(int d52=0;d52<OrdersTotal();d52++){            if(OrderSelect(d52,SELECT_BY_POS,MODE_TRADES)==true)              {                      Alert("haveopenxx=",haveopen);                                     if((magicx==15)||(magicx==30)||(magicx==60)||(magicx==240))                   {                       if((OrderMagicNumber()==15)||(OrderMagicNumber()==30)||(OrderMagicNumber()==60)||(OrderMagicNumber()==240))                         {                              haveopen=true;                         }                   }                  if(haveopen)                  {                     if(ordertp=="buy"){                          if(OrderType()==OP_BUY){                              stat=true;                              break;                          }                        }                     if(ordertp=="sell"){                       if(OrderType()==OP_SELL){                         stat=true;                         Alert("magicx=",magicx,"OrderMagicNumber()=",OrderMagicNumber());                         break;                       }                     }                     }                }             }         }         return(stat);    }   

The result I obtained haveopen  is true,why?  select the tick magicnumber is 151515,But my search magics is  15,why return the haveopen is "true ",WHY

 
47803124:
                     Alert("haveopenxx=",haveopen);
  1. Please don't add text inside quoted text or CODE blocks, put it outside.
              MQL4 forum editor problem - MQL4 programming forum (2015)

  2. Your alert is before you set the variable.