Error "No todas las rutas de control devuelven un valor". - página 2

Hola amigos, tengo el mismo problema ¿alguien puede ayudarme?


double price;
int    slippage;
double p = prce;
int    maxtry = RequoteAttempts;
color  CloseColor;

OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);

int ordtype = OrderType();
if (ordtype == OP_BUY) {price = NormalizeDouble(Bid,Digits); CloseColor = CloseBuyColor;}
if (ordtype == OP_SELL) {price = NormalizeDouble(Ask,Digits); CloseColor = CloseSellColor;}

if (MathAbs(OrderTakeProfit() - price) <= MarketInfo(Symbol(),MODE_FREEZELEVEL) * Point) return(0);
if (MathAbs(OrderStopLoss() - price) <= MarketInfo(Symbol(),MODE_FREEZELEVEL) * Point) return(0); 

if (OrderClose(ticket,OrderLots(),price,CloseSlippage,CloseColor)) return(1); 
if ((GetLastError() != 135) && (GetLastError() != 138) && (GetLastError() != 146)) return(0); 

Print("Requote");

//--- RequoteAttempts) 

for (int attempt = 1; attempt <= maxtry; attempt++)
   {
   RefreshRates();
   if (ordtype == OP_BUY)
      {
      slippage = MathRound((Bid - p) / pp);
      if (Bid >= p)
         {
         Print("Closing order. Attempt " + (attempt + 1));
         if (OrderClose(ticket,OrderLots(),NormalizeDouble(Bid,Digits),slippage,CloseColor)) return(1);
         if (!((GetLastError() != 135) && (GetLastError() != 138) && (GetLastError() != 146))) continue;
         return(0);
         }
      }
   if (ordtype == OP_SELL)
      {
      slippage = MathRound((p - Ask) / pp);
      if (p >= Ask)
         {
         Print("Closing order. Attempt " + (attempt + 1));
         if (OrderClose(ticket,OrderLots(),NormalizeDouble(Ask,Digits),slippage,CloseColor)) return(1);
         if ((GetLastError() != 135) && (GetLastError() != 138) && (GetLastError() != 146)) return(0);
         
         }
      }
   }
}

Copia y pega el código correspondiente. Por tu imagen, no has mostrado el inicio de la función, por lo que no sabemos qué debe devolver.

De todos modos tiene que haber un retorno al final de la función.

Gracias y perdón, ya está arreglado
Keith Watford:

Copie y pegue el código relevante. A partir de su imagen, no ha mostrado el comienzo de la función, por lo que no sabemos qué debería devolver.

De todos modos, debe haber una devolución al final de la función.

Hola amigo ¿puedes ver ahora el problema que tiene el código?

if(OrderSelect...
JermyRec:

No entiendo amigo


int CloseOrder(int ticket, double prce){ 
//+--------------------------------------------------------------------------------------------------------------+


double price;
int    slippage;
double p = prce;
int    maxtry = RequoteAttempts;
color  CloseColor;

OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);

int ordtype = OrderType();
if (ordtype == OP_BUY) {price = NormalizeDouble(Bid,Digits); CloseColor = CloseBuyColor;}
if (ordtype == OP_SELL) {price = NormalizeDouble(Ask,Digits); CloseColor = CloseSellColor;}

if (MathAbs(OrderTakeProfit() - price) <= MarketInfo(Symbol(),MODE_FREEZELEVEL) * Point) return(0);
if (MathAbs(OrderStopLoss() - price) <= MarketInfo(Symbol(),MODE_FREEZELEVEL) * Point) return(0); 

if (OrderClose(ticket,OrderLots(),price,CloseSlippage,CloseColor)) return(1); 
if ((GetLastError() != 135) && (GetLastError() != 138) && (GetLastError() != 146)) return(0); 

Print("Requote");

//--- RequoteAttempts) 

for (int attempt = 1; attempt <= maxtry; attempt++)
   {
   RefreshRates();
   if (ordtype == OP_BUY)
      {
      slippage = MathRound((Bid - p) / pp);
      if (Bid >= p)
         {
         Print("Closing order. Attempt " + (attempt + 1));
         if (OrderClose(ticket,OrderLots(),NormalizeDouble(Bid,Digits),slippage,CloseColor)) return(1);
         if (!((GetLastError() != 135) && (GetLastError() != 138) && (GetLastError() != 146))) continue;
         return(0);
         }
      }
   if (ordtype == OP_SELL)
      {
      slippage = MathRound((p - Ask) / pp);
      if (p >= Ask)
         {
         Print("Closing order. Attempt " + (attempt + 1));
         if (OrderClose(ticket,OrderLots(),NormalizeDouble(Ask,Digits),slippage,CloseColor)) return(1);
         if ((GetLastError() != 135) && (GetLastError() != 138) && (GetLastError() != 146)) return(0);
         
        }  
      }
   }
}               In this line would be the error (')' - not all control paths return to value)

Moderador : Copiado de otro hilo

int CloseOrder( int ticket, double prce){ 
//+--------------------------------------------------------------------------------------------------------------+


double price;
int     slippage;
double p = prce;
int     maxtry = RequoteAttempts;
color   CloseColor;

OrderSelect (ticket, SELECT_BY_TICKET , MODE_TRADES );

int ordtype = OrderType ();
if (ordtype == OP_BUY ) {price = NormalizeDouble ( Bid , Digits ); CloseColor = CloseBuyColor;}
if (ordtype == OP_SELL ) {price = NormalizeDouble ( Ask , Digits ); CloseColor = CloseSellColor;}

if ( MathAbs ( OrderTakeProfit () - price) <= MarketInfo ( Symbol (), MODE_FREEZELEVEL ) * Point ) return ( 0 );
if ( MathAbs ( OrderStopLoss () - price) <= MarketInfo ( Symbol (), MODE_FREEZELEVEL ) * Point ) return ( 0 ); 

if ( OrderClose (ticket, OrderLots (),price,CloseSlippage,CloseColor)) return ( 1 ); 
if (( GetLastError () != 135 ) && ( GetLastError () != 138 ) && ( GetLastError () != 146 )) return ( 0 ); 

Print ( "Requote" );

//--- RequoteAttempts) 

for ( int attempt = 1 ; attempt <= maxtry; attempt++)
   {
   RefreshRates ();
   if (ordtype == OP_BUY )
      {
      slippage = MathRound (( Bid - p) / pp);
       if ( Bid >= p)
         {
         Print ( "Closing order. Attempt " + (attempt + 1 ));
         if ( OrderClose (ticket, OrderLots (), NormalizeDouble ( Bid , Digits ),slippage,CloseColor)) return ( 1 );
         if (!(( GetLastError () != 135 ) && ( GetLastError () != 138 ) && ( GetLastError () != 146 ))) continue ;
         return ( 0 );
         }
      }
   if (ordtype == OP_SELL )
      {
      slippage = MathRound ((p - Ask ) / pp);
       if (p >= Ask )
         {
         Print ( "Closing order. Attempt " + (attempt + 1 ));
         if ( OrderClose (ticket, OrderLots (), NormalizeDouble ( Ask , Digits ),slippage,CloseColor)) return ( 1 );
         if (( GetLastError () != 135 ) && ( GetLastError () != 138 ) && ( GetLastError () != 146 )) return ( 0 );
         
        }  
      }
   }
return(-1);/// not all branching code in the function return values
}               

Moderador: respuesta deVitalii Ananev copiada de otro hilo

No hagas un doble post. Ya recibiste respuestas aquí, así que por qué abrir un nuevo tema con exactamente el mismo asunto. Esto es egoísta y hace perder el tiempo a las personas que intentan ayudarte.

He borrado tu otro tema.