&& Illegal operation use

 

 I am trying to use 2 conditions , but I get that error message:

&&  Illegal operation use

Below is my function and the if condition  ,

that line is causing issues to me:

 if ( (iClose(_Symbol,PERIOD_W1,1) > iClose(_Symbol,PERIOD_W1,3)) && (CondBuy1 = 1)) { BUY_IT1(0.01);}
#property strict



int decimal_lot = 2;
int MgcB1 = 100,MgcB2 = 300, MgcS1 = 200, MgcS2 = 200;
///////////////////////////////////////////////////////////////////
void OnDeinit(const int reason){
   EventKillTimer();

}
///////////////////////////////////////////////////////////////////
void OnInit(){
EventSetTimer(1);
  if(MarketInfo(Symbol(),MODE_MINLOT)<0.1) {decimal_lot = 2;} else {decimal_lot = 1;} 

}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////       START  OF MAIN PROG.
/////////////////////////////////////////////////////////////////////////////////////////////////////
void OnTimer(){}
void OnTick(){


/////////////////////// Rules
 //BUY
 
 string CondBuy1 = 1;
if(MgcB1_AlreadyOpen(100) == 1) {CondBuy1 = "A trade is already opened";}

 
 
  if ( (iClose(_Symbol,PERIOD_W1,1) > iClose(_Symbol,PERIOD_W1,3)) && (CondBuy1 = 1)) { BUY_IT1(0.01);}
 
 
 
 
 
 
 
 
 //SELL 
 if (
      
  iClose(_Symbol,PERIOD_W1,1) < iClose(_Symbol,PERIOD_W1,3) 
      
      
    ) { SELL_IT1(0.01);}
 

}
/////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////  END OF MAIN PROG
int CountEach(int MAGIC){
int cc = 0;

       for(int iji=OrdersTotal(); iji>=0; iji--){
       if (OrderSelect(iji,SELECT_BY_POS) == true)
         if(OrderSymbol()==Symbol()  && OrderMagicNumber()==MAGIC)
           cc++;}
         
 return(cc);
}
////////////////////////////////////////////////////////////////////////
   double BUY_IT1(double vol){
 
      if(vol<MarketInfo(Symbol(),MODE_MINLOT))
      {Print("Volume is less than minimum permitted amount of a lot");
      vol=MarketInfo(Symbol(),MODE_MINLOT);}
      if(vol>MarketInfo(Symbol(),MODE_MAXLOT))
      {Print("Volume is more than maximum permitted amount of a lot");
      vol=MarketInfo(Symbol(),MODE_MAXLOT);}
      
      double myTP = 25;
      double mySL = 0;
   
    int B1 = OrderSend(Symbol(),OP_BUY,NormalizeDouble(vol,decimal_lot),Ask,20,mySL,myTP,"B1",MgcB1,0,CLR_NONE);

    return(0);
   }
/////////////////////////////////////////////////////////////////////////
double CloseAllBUY1(){
    for(int i=OrdersTotal(); i>=0; i--){
       if (OrderSelect(i,SELECT_BY_POS) == true){
         if(OrderSymbol()==Symbol()){             
          if(OrderType()==OP_BUY &&   OrderMagicNumber()== MgcB1){
           int G = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),15,CLR_NONE);}
  }}}

return(0);
}
////////////////////////////////////////////////////

double SELL_IT1(double vol){

      if(vol<MarketInfo(Symbol(),MODE_MINLOT))
      {Print("Volume is less than minimum permitted amount of a lot");
      vol=MarketInfo(Symbol(),MODE_MINLOT);}
      if(vol>MarketInfo(Symbol(),MODE_MAXLOT))
      {Print("Volume is more than maximum permitted amount of a lot");
      vol=MarketInfo(Symbol(),MODE_MAXLOT);}
      
      double myTP = 25;
      double mySL = 0;
      
    int S1 = OrderSend(Symbol(),OP_SELL,NormalizeDouble(vol,decimal_lot),Bid,20,mySL,myTP,"S1",MgcS1,0,CLR_NONE);

    return(0);
   }
////////////////////////////////////////////////////////////////////////
double CloseAllSELL1(){
    for(int i=OrdersTotal(); i>=0; i--){
       if (OrderSelect(i,SELECT_BY_POS) == true){
         if(OrderSymbol()==Symbol()){             
          if(OrderType()==OP_SELL &&  OrderMagicNumber()== MgcS1){
           int G = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),15,CLR_NONE);}
            }}}
return(0);
}
////////////////////////////////////////////////////
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

////////////////////////////////////////////////////////////////////////
   double BUY_IT2(double vol){
 
      if(vol<MarketInfo(Symbol(),MODE_MINLOT))
      {Print("Volume is less than minimum permitted amount of a lot");
      vol=MarketInfo(Symbol(),MODE_MINLOT);}
      if(vol>MarketInfo(Symbol(),MODE_MAXLOT))
      {Print("Volume is more than maximum permitted amount of a lot");
      vol=MarketInfo(Symbol(),MODE_MAXLOT);}
      
      double myTP = 25;
      double mySL = 0;
   
    int B2 = OrderSend(Symbol(),OP_BUY,NormalizeDouble(vol,decimal_lot),Ask,20,mySL,myTP,"B2",MgcB2,0,CLR_NONE);

    return(0);
   }
/////////////////////////////////////////////////////////////////////////
double CloseAllBUY2(){
    for(int i=OrdersTotal(); i>=0; i--){
       if (OrderSelect(i,SELECT_BY_POS) == true){
         if(OrderSymbol()==Symbol()){             
          if(OrderType()==OP_BUY &&   OrderMagicNumber()== MgcB2){
           int G = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),15,CLR_NONE);}
  }}}

return(0);
}
////////////////////////////////////////////////////
////////////////////////////////////////////////////

double SELL_IT2(double vol){

      if(vol<MarketInfo(Symbol(),MODE_MINLOT))
      {Print("Volume is less than minimum permitted amount of a lot");
      vol=MarketInfo(Symbol(),MODE_MINLOT);}
      if(vol>MarketInfo(Symbol(),MODE_MAXLOT))
      {Print("Volume is more than maximum permitted amount of a lot");
      vol=MarketInfo(Symbol(),MODE_MAXLOT);}
      
      double myTP = 25;
      double mySL = 0;
      
    int S2 = OrderSend(Symbol(),OP_SELL,NormalizeDouble(vol,decimal_lot),Bid,20,mySL,myTP,"S2",MgcS2,0,CLR_NONE);

    return(0);
   }
////////////////////////////////////////////////////////////////////////
double CloseAllSELL2(){
    for(int i=OrdersTotal(); i>=0; i--){
       if (OrderSelect(i,SELECT_BY_POS) == true){
         if(OrderSymbol()==Symbol()){             
          if(OrderType()==OP_SELL &&  OrderMagicNumber()== MgcS2){
           int G = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),15,CLR_NONE);}
            }}}
return(0);
}
////////////////////////////////////////////////////

  int MgcB1_AlreadyOpen(int magicnumber)               
      {
      int count = 0;
      int total=OrdersTotal();

      for(int i=0; i<total; i++)
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

     if (OrderMagicNumber()==magicnumber ); 
     
           }
      return(1);
      }



 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 

Don't use string variables as conditionals. Use boolean variables.

// Change this ...

   string CondBuy1 = 1;
   if(MgcB1_AlreadyOpen(100) == 1) {CondBuy1 = "A trade is already opened";}
   if ( (iClose(_Symbol,PERIOD_W1,1) > iClose(_Symbol,PERIOD_W1,3)) && (CondBuy1 = 1)) { BUY_IT1(0.01);}

   /* ... */

   int MgcB1_AlreadyOpen(int magicnumber)               
   {
      int count = 0;
      int total=OrdersTotal();

      for(int i=0; i<total; i++)
      {
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

     if (OrderMagicNumber()==magicnumber ); 
     
           }
      return(1);
   }


// To this ...

   bool CondBuy1 = MgcB1_AlreadyOpen( _Symbol, 100 );
   if( ( iClose( _Symbol, PERIOD_W1, 1 ) > iClose( _Symbol, PERIOD_W1, 3 ) ) && !CondBuy1 )    BUY_IT1(0.01);

   /* ... */

   bool MgcB1_AlreadyOpen( string symbol, int magicnumber )               
   {
      for( int i = OrdersTotal() - 1; i >= 0; i-- )
        if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) &&
            ( OrderMagicNumber() == magicnumber )        &&
            ( OrderSymbol()      == symbol      ) ); 
           return( true );

      return( false );
   }

Also, "CondBuy1 = 1" is an assignment and not a comparison which would look like "CondBuy1 == 1".

 
CondBuy1 = 1)
This is an assignment (setting variable to one) and is always true (not zero).
Reason: