parantesi sbilanciate

 

Non riesco a capire il modo corretto di mettere le parentesi. Per favore, spiegatemi qual è il mio errore.

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:

Non riesco a capire il modo corretto di mettere le parentesi. Per favore, spiegatemi qual è il mio errore.

extra parentesi graffa di chiusura nella linea più lunga
 
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);
}

si può fare così, ma poi il codice richiede più righe:

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

Si può anche fare in questo modo, ma poi ci sono degli inconvenienti quando si modifica:

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

Per esempio, se volete cancellare o spostare una linea con una parentesi aperta, dovete fare delle manipolazioni extra.

Ecco perché l'opzione 1 è migliore.

 
ilunga:
parentesi graffa di chiusura extra nella linea più lunga

Se lo rimuovo, mi dice che "è prevista una parentesi finale".
 
valenok2003:


Ho copiato la tua versione - dice ancora "parantesi sbilanciate"
 
liana:

Ho copiato la tua versione e dice di nuovo "parantesi sbilanciate".

Sì, capisco, lo sistemerò.
 
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);
}
 

Per qualche motivo tutte le tue opzioni mostrano "ending bracket expected" Qual è la ragione?

valenok2003:

si può fare in questo modo, ma poi il codice richiede più righe:

Si può anche fare così, ma poi si ottengono inconvenienti durante l'editing:

per esempio, se volete cancellare o spostare una linea con una parentesi aperta, dovete fare delle manipolazioni extra.

Ecco perché l'opzione 1 è migliore.

 

Ecco tutto il codice. Non importa come lo correggo, dice "parentesi finale prevista" o "parantesi sbilanciata".

Aiuto, sto lottando con queste staffe da un'ora.
Voglio controllare gli ordini aperti e pendenti e poi aprire un ordine.

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:

Ecco l'intero codice. Non importa come lo aggiusto, dice "parentesi finale prevista" o "parantesi sbilanciate".

Aiuto, sto lottando con queste staffe da un'ora.
Voglio controllare se ci sono ordini aperti e in sospeso e poi aprire un ordine.


La tua ultima funzione ExistPositions non è chiusa. E non c'è un valore di ritorno bool, che è anche un errore. Cioè, se le condizioni non sono soddisfatte, la funzione dovrebbe comunque restituire qualcosa.

Fate attenzione quando copiate i codici.

 
valenok2003:

La tua ultima funzione ExistPositions non è chiusa. E non c'è nessun valore di ritorno bool, anche questo è un errore.
Grazie (ho copiato male la funzione di Kim).
Ora l'ho corretto - dice ancora "parentesi finale prevista
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);
Motivazione: