Why the Warning, empty controlled statement found?

 

Why does the Warning "empty controlled statement found" come up when using  if(enableCount == true within the following code?

void OnTick()    
{   
   double close = Close[1];  
   datetime time = iTime(NULL,0,1);

   static int barCount = 1;
   static bool enableCount = false;   

             
   if(Close[1] < Open[1]) 
   {
      barCount++;        
   }
   
   if(barCount == 7) 
   {
      enableCount = true; 
   }
   
   if(enableCount == true);
   {   
      ObjectCreate("Buy",OBJ_ARROW_THUMB_UP,0,time,close); 
   }
     
}
 

Lose the ; at the end of it.

Regarding style, there is no need to write ==true for a bool. 

void OnTick()    
{   
   double close = Close[1];  
   datetime time = iTime(NULL,0,1);

   static int barCount = 1;
   static bool enableCount = false;   

             
   if(Close[1] < Open[1]) 
   {
      barCount++;        
   }
   
   if(barCount == 7) 
   {
      enableCount = true; 
   }
   
//   if(enableCount == true);
   if(enableCount)
   {   
      ObjectCreate("Buy",OBJ_ARROW_THUMB_UP,0,time,close); 
   }
     
}
 
honest_knave:

Lose the ; at the end of it.

Regarding style, there is no need to write ==true for a bool.  

honest_knave:

Lose the ; at the end of it.

Regarding style, there is no need to write ==true for a bool. 

Thanks for pointing that ; mistake out!

 

Help Me Warning, empty controlled statement found?


int start() {



   string PSH="SwingHigh";
   string PZH="ZoneH1";
   string PZL="ZoneL1";   
   string PSL="SwingLow";
   string PC="Center";  
   long current_chart_id=ChartID();

   if(ObjectCreate(PSH, OBJ_HLINE, 0, Time[0], pa, 0, 0));
   ObjectSetInteger(current_chart_id,PSH,OBJPROP_COLOR,clrGold);
   ObjectSetInteger(current_chart_id,PSH,OBJPROP_STYLE,4); 
   ObjectSetInteger(current_chart_id,PSH,OBJPROP_WIDTH,1);
    
   if(ObjectCreate(PZH, OBJ_HLINE, 0, Time[0], pb, 0, 0));
   ObjectSetInteger(current_chart_id,PZH,OBJPROP_COLOR,clrGold);
   ObjectSetInteger(current_chart_id,PZH,OBJPROP_STYLE,4); 
   ObjectSetInteger(current_chart_id,PZH,OBJPROP_WIDTH,1); 
   
       
   if(ObjectCreate(PZL, OBJ_HLINE, 0, Time[0], pc, 0, 0));
   ObjectSetInteger(current_chart_id,PZL,OBJPROP_COLOR,clrGold); 
   ObjectSetInteger(current_chart_id,PZL,OBJPROP_STYLE,4); 
   ObjectSetInteger(current_chart_id,PZL,OBJPROP_WIDTH,1); 

   if(ObjectCreate(PSL, OBJ_HLINE, 0, Time[0], pd, 0, 0));
   ObjectSetInteger(current_chart_id,PSL,OBJPROP_COLOR,clrGold);
   ObjectSetInteger(current_chart_id,PSL,OBJPROP_STYLE,4); 
   ObjectSetInteger(current_chart_id,PSL,OBJPROP_WIDTH,1); 

   if(ObjectCreate(PC, OBJ_HLINE, 0, Time[0], pe, 0, 0));
   ObjectSetInteger(current_chart_id,PC,OBJPROP_COLOR,clrAqua);
   ObjectSetInteger(current_chart_id,PC,OBJPROP_STYLE,1); 

   ObjectSetInteger(current_chart_id,PC,OBJPROP_WIDTH,1); 

}

 

You have a semi-colon after your if() conditionals. That causes the error.

You want braces around your code blocks.

For example:

if(ObjectCreate(PSH, OBJ_HLINE, 0, Time[0], pa, 0, 0))
{
   ObjectSetInteger(current_chart_id,PSH,OBJPROP_COLOR,clrGold);
   ObjectSetInteger(current_chart_id,PSH,OBJPROP_STYLE,4); 
   ObjectSetInteger(current_chart_id,PSH,OBJPROP_WIDTH,1);
}
 

Thank You.

 

 Help Me Warning possible loss of data due to type conversion      [MQL4]


input double _TrailingStop    = 300; // TrailingStop

int start() {



   _TrailingSELL2       = Simple_Trailing_Stop(15, 0, _TrailingStop, 10);
   _TrailingSELL3       = Simple_Trailing_Stop(17, 0, _TrailingStop, 10);
   _Trailing_StopBUY    = Simple_Trailing_Stop(14, 0, _TrailingStop, 10);
   _Trailing_StopBUY_2  = Simple_Trailing_Stop(16, 0, _TrailingStop, 10);   


}

   return(0);

}

bool Simple_Trailing_Stop(int MagicIndex, int WaitForProfit, int TrailingStopPoints, int MinAdjustmentPoints)

{   

   double pnlPoints=0;   

   double price, sl, tp;

   double point = MarketInfo(Symbol(),MODE_POINT);

   int stopLevel = int(MarketInfo(Symbol(),MODE_STOPLEVEL) + MarketInfo(Symbol(),MODE_SPREAD));  

   int cmd;   

   bool result = true;   

   double newSl;

   int total = OrdersTotal();

      for(int i=total-1;i>=0;i--){

      if (!OrderSelect(i, SELECT_BY_POS)) continue;

      if(OrderMagicNumber() != __STRATEGY_MAGIC + MagicIndex || OrderSymbol() != Symbol()) continue;      

      cmd = OrderType();      

      sl = NormalizeDouble(OrderStopLoss(),Digits);

      tp = OrderTakeProfit();      

      if (OrderType() == OP_BUY)

      {

         price = MarketInfo(Symbol(),MODE_BID);

         newSl = NormalizeDouble(price - TrailingStopPoints * point, Digits);    

         if(((tp - price)/point) < stopLevel && tp != 0) continue;         

         if(((price - newSl)/point) < stopLevel)continue; 

         if(WaitForProfit == 0)

         {        

            pnlPoints = (price - OrderOpenPrice())/point; 

            if (pnlPoints < TrailingStopPoints ) continue;  

         }        

         if (sl + MinAdjustmentPoints*point>= newSl) continue;              

         if(!OrderModify(OrderTicket(), OrderOpenPrice(), newSl, tp, 0))

         {

            printf("Error: Failed to modify trade. Ticket #%i, error code: %i", OrderTicket(), GetLastError());

            result = false;

            Sleep(__SLEEP_AFTER_EXECUTION_FAIL);

         }

      }  

      else if (OrderType() == OP_SELL)

      {

         price = MarketInfo(Symbol(),MODE_ASK);

         newSl = NormalizeDouble(price+ TrailingStopPoints * point, Digits);

         if(((price - tp)/point) < stopLevel) continue;

         if(((newSl - price)/point) < stopLevel) continue;

         if(WaitForProfit == 0)

         {              

            pnlPoints = (OrderOpenPrice() - price)/point;

            if (pnlPoints < TrailingStopPoints) continue; 

         }         

         if (sl - MinAdjustmentPoints*point <= newSl && sl != 0) continue;

         

         if(!OrderModify(OrderTicket(), OrderOpenPrice(), newSl, tp, 0))

         {

            printf("Error: Failed to modify trade. Ticket #%i, error code: %i", OrderTicket(), GetLastError());

            result = false;

            Sleep(__SLEEP_AFTER_EXECUTION_FAIL);

         }         

       }      

   }   

   return(result);

}

//---------------------------------------------------------------


 
Help Me  MR.Anthony Garot
 
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Don't post code that doesn't even compile.
  3. You know what line it is, don't expect us to know, but start with this:
    input double _TrailingStop    = 300;    // TrailingStop
    
    int start() {
    
    
       _TrailingSELL2       = Simple_Trailing_Stop(15, 0, _TrailingStop, 10);
       _TrailingSELL3       = Simple_Trailing_Stop(17, 0, _TrailingStop, 10);
       _Trailing_StopBUY    = Simple_Trailing_Stop(14, 0, _TrailingStop, 10);
       _Trailing_StopBUY_2  = Simple_Trailing_Stop(16, 0, _TrailingStop, 10);   
    
    
    }
    
       return(0);
    
    }
    
    bool Simple_Trailing_Stop(int MagicIndex, int WaitForProfit, int TrailingStopPoints, int MinAdjustmentPoints)

 

Thank you

 

anyone can help me why i have warning "empty controlled statement found" ?


extern double up=30;
extern double down=-30;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{

 

   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
Comment("\n","\n","\n","\n",profittotlal());
   Button(0,"Button",0,50,150,200,250);
    if(ObjectGetInteger(0,"Button",OBJPROP_STATE,true));
  {
   if(profittotlal()>up || profittotlal()< down)
   for(int i=OrdersTotal()-1;i>=0;i--)
    {
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     bool bebaaand=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),2,clrWhite);
  
  
    }
  
  }
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{

 
 
 
 
 
}
//+------------------------------------------------------------------+
bool Button(const long                    chart_ID=0,              
                  const string            name="Button",            
                  const int               sub_window=0,             
                  const int               x=0,                      
                  const int               y=0,                     
                  const int               width=50,                 
                  const int               height=18,                
                  const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, 
                  const string            text="Button",            
                  const string            font="Arial",             
                  const int               font_size=10,             
                  const color             clr=clrBlack,             
                  const color             back_clr=C'236,233,216',  
                  const color             border_clr=clrNONE,       
                  const bool              state=false,              
                  const bool              back=false,               
                  const bool              selection=false,          
                  const bool              hidden=true,              
                  const long              z_order=0)               
  {
  ResetLastError();
   if(ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))
     {
      ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
      ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
      ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
      ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
      ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
      ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
      ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
      ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
      ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);
      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
      ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);
      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
      ChartRedraw();
      return(true);
      }
     else {
      Print(__FUNCTION__,
             ": failed to create => ",name," object! Error code = ",GetLastError());
      return(false);
     }
  }
  //////////////////////////////////////////////////////////// 
  double profittotlal()
  {
  double sum=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
    {
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     sum=sum+OrderProfit()+OrderCommission();   
    } 
  return(sum); 
  }
Reason: