paréntesis desequilibradas

 

No consigo averiguar la forma correcta de poner los paréntesis. Por favor, explique cuál es mi error.

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:

No consigo averiguar la forma correcta de poner los paréntesis. Por favor, explique cuál es mi error.

paréntesis de cierre extra en la línea más larga
 
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);
}

se puede hacer esto, pero entonces el código ocupa más líneas:

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

También se puede hacer así, pero entonces hay inconvenientes a la hora de editar:

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

Por ejemplo, si quieres borrar o mover una línea con un corchete de apertura, tienes que hacer manipulaciones adicionales.

Por eso la opción 1 es mejor.

 
ilunga:
corchete de cierre extra en la línea más larga

Si lo quito, dice "final de corchete esperado"
 
valenok2003:


He copiado su versión - dice "paréntesis desequilibradas" de nuevo
 
liana:

He copiado tu versión y vuelve a decir "paréntesis desequilibradas".

Sí, ya veo, lo arreglaré.
 
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);
}
 

Por alguna razón todas tus opciones muestran "finalización del soporte esperado" ¿Cuál es la razón?

valenok2003:

se puede hacer así, pero entonces el código ocupa más líneas:

También puedes hacerlo, pero entonces tendrás inconvenientes a la hora de editar:

Por ejemplo, si quieres borrar o mover una línea con un corchete de apertura, tienes que hacer manipulaciones adicionales.

Por eso la opción 1 es mejor.

 

Aquí está el código completo. No importa cómo lo arregle, dice "final de paréntesis esperado" o "paréntesis desequilibrado".

Ayuda, he estado luchando con estos soportes durante una hora.
Quiero comprobar si hay órdenes abiertas y pendientes y luego abrir una orden.

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:

Aquí está el código completo. No importa cómo lo arregle, dice "final de paréntesis esperado" o "paréntesis desequilibrado".

Ayuda, he estado luchando con estos soportes durante una hora.
Quiero comprobar si hay órdenes abiertas y pendientes y luego abrir una orden.


Su última función ExistPositions no está cerrada. Y no hay ningún valor de retorno bool, lo que también es un error. Es decir, si no se cumplen las condiciones, la función debe devolver algo de todos modos.

Tenga cuidado al copiar los códigos.

 
valenok2003:

Su última función ExistPositions no está cerrada. Y no hay valor de retorno bool, también es un error.
Gracias (he copiado mal la función de Kim).
Ahora lo he corregido - de nuevo dice "paréntesis final esperado
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);
Razón de la queja: