unbalanced parantheses

 

I can't figure out the correct way to put the brackets. Please explain what my mistake is.

int start()
  { 
//----
   { 
   pending = ExistOrders(NULL);
   if (pending > 0 ) {return;}
   positions = ExistPositions(NULL);
   if (positions > 0 ) {return;}
   } else { 
   ticket=OrderSend(Symbol(),OP_SELL,0,1,Bid,3,Bid+20*Point,Bid-40*Point,"",magic,0,Red);}
   }
   
//----
   return(0);
  }
 
liana:

I can't figure out the correct way to put the brackets. Please explain what my mistake is.

extra curly closing parenthesis in the longest line
 
int start() { 
//----
   pending = ExistOrders(NULL);
   if(pending > 0 ) return(0); // если оператор одиночный фигурные скобки можно не ставить
   positions = ExistPositions(NULL);
   if(positions > 0 ) {
      return(0);     // хотя со скобками тоже правильно
   }
   else { // else относится к ближайшему if
      ticket=OrderSend(Symbol(),OP_SELL,0,1,Bid,3,Bid+20*Point,Bid-40*Point,"",magic,0,Red);   
   }
//----
   return(0);
}

you can do this, but then the code takes more lines:

int start() 
{ 
//----
   pending = ExistOrders(NULL);
   if(pending > 0 ) 
      return(0); // если оператор одиночный фигурные скобки можноне ставить
   positions = ExistPositions(NULL);
   if(positions > 0 ) 
   {
      return(0);     // хотя со скобками тоже правильно
   }
   else 
   { 
      // else относится к ближайшему if
      ticket=OrderSend(Symbol(),OP_SELL,0,1,Bid,3,Bid+20*Point,Bid-40*Point,"",magic,0,Red);   
   }
//----
   return(0);
}

You can also do it this way, but then there are inconveniences when editing:

int start() 
{  pending = ExistOrders(NULL);
   if(pending > 0 ) 
      return(0); // если оператор одиночный фигурные скобки можноне ставить
   positions = ExistPositions(NULL);
   if(positions > 0 ) 
   {  return(0);     // хотя со скобками тоже правильно
   }
   else 
   { // else относится к ближайшему if
      ticket=OrderSend(Symbol(),OP_SELL,0,1,Bid,3,Bid+20*Point,Bid-40*Point,"",magic,0,Red);
   }
//----
   return(0);
}

For example, if you want to delete or move a line with an opening bracket, you have to do extra manipulations.

That's why option 1 is better.

 
ilunga:
extra curly closing bracket in the longest line

If I remove it, it says "ending bracket expected"
 
valenok2003:


I copied your version - it says "unbalanced parantheses" again
 
liana:

I copied your version and it says "unbalanced parantheses" again.

Yeah, I see, I'll fix it.
 
int start() { 
//----
   pending = ExistOrders(NULL);
   if(pending > 0 ) return(0); // если оператор одиночный фигурные скобки можно не ставить
   positions = ExistPositions(NULL);
   if(positions > 0 ) {
      return(0);     // хотя со скобками тоже правильно
   }
   else { // else относится к ближайшему if
      ticket=OrderSend(Symbol(),OP_SELL,0,1,Bid,3,Bid+20*Point,Bid-40*Point,"",magic,0,Red);
   }
//----
   return(0);
}
 

For some reason all your options show "ending bracket expected" What's the reason?

valenok2003:

you can do it this way, but then the code takes more lines:

You can also do this, but then you get inconvenience when editing:

for example, if you want to delete or move a line with an opening bracket, you have to do extra manipulations.

That's why option 1 is better.

 

Here's all the code. No matter how I fix it, it says "ending bracket expected" or "unbalanced parantheses".

Help, I've been struggling with these brackets for an hour.
I want to check for open and pending orders and then open an order.

int pending;
int positions;
int ticket;
int magic=576;

int start() { 
//----
   pending = ExistOrders(NULL);
   if(pending = True ) return(0); // ???? ???????? ????????? ???????? ?????? ????? ?? ???????
   positions = ExistPositions(NULL);
   if(positions = True ) {
      return(0);     // ???? ?? ???????? ???? ?????????
   }
   else { // else ????????? ? ?????????? if
      ticket=OrderSend(Symbol(),OP_SELL,0,1,Bid,3,Bid+20*Point,Bid-40*Point,"",magic,0,Red);   
   }
//----
   return(0);
}
//+------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//|  Exist pending. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+

bool ExistOrders(string sy="", int op=-1, int mn=-1, datetime ot=0) {
  int i, k=OrdersTotal(), ty;
 
  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      ty=OrderType();
      if (ty>1 && ty<6) {
        if ((OrderSymbol()==sy || sy=="") && (op<0 || ty==op)) {
          if (mn<0 || OrderMagicNumber()==mn) {
            if (ot<=OrderOpenTime()) return(True);
          }
        }
      }
    }
  }
  return(False);
}
//+----------------------------------------------------------------------------+
//| Exist open Positions. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+

bool ExistPositions(string sy="", int op=-1, int mn=-1, datetime ot=0) {
  int i, k=OrdersTotal();
 
  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (ot<=OrderOpenTime()) return(True);
            }
          }
        }
      }
    }
  }
 

liana:

Here's the whole code. No matter how I fix it, it says "ending bracket expected" or "unbalanced parantheses".

Help, I've been struggling with these brackets for an hour.
I want to check if there are any open and pending orders and then open an order.


Your last function ExistPositions is not closed. And there is no bool return value, which is also an error. I.e., if the conditions are not met, the function should anyway return something.

Be careful when copying codes.

 
valenok2003:

Your last function ExistPositions is not closed. And there is no bool return value, also an error.
Thank you (I copied Kim's function wrongly).
Now I corrected it - it again says "ending bracket expected
int pending;
int positions;
int ticket;
int magic=576;

int start() { 
//----
   pending = ExistOrders(NULL);
   if(pending = True ) return(0); // ???? ???????? ????????? ???????? ?????? ????? ?? ???????
   positions = ExistPositions(NULL);
   if(positions = True ) {
      return(0);     // ???? ?? ???????? ???? ?????????
   }
   else { // else ????????? ? ?????????? if
      ticket=OrderSend(Symbol(),OP_SELL,0,1,Bid,3,Bid+20*Point,Bid-40*Point,"",magic,0,Red);
   }
//----
   return(0);
}
//+------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//|  Exist pending. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+

bool ExistOrders(string sy="", int op=-1, int mn=-1, datetime ot=0) {
  int i, k=OrdersTotal(), ty;
 
  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      ty=OrderType();
      if (ty>1 && ty<6) {
        if ((OrderSymbol()==sy || sy=="") && (op<0 || ty==op)) {
          if (mn<0 || OrderMagicNumber()==mn) {
            if (ot<=OrderOpenTime()) return(True);
          }
        }
      }
    }
  }
  return(False);
}

//+----------------------------------------------------------------------------+
//|  Exist open positions. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+

bool ExistPositions(string sy="", int op=-1, int mn=-1, datetime ot=0) {
  int i, k=OrdersTotal();
 
  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (ot<=OrderOpenTime()) return(True);
            }
          }
        }
      }
    }
  }
  return(False);
Reason: