I can't find the problem in this function - "not all control paths return a

 

Hi there. I'm having trouble with the below function. error - ')' - not all control paths return a value

I've been over the code a number of times and can't find the error. This is not my code it was put up here a few years ago and I'm placing into an EA. Would appreciate any help.

 

int OrderSendReliable(string symbol, int cmd, double volume, double price,

 int slippage, double stoploss, double takeprofit,

 string comment, int magic, datetime expiration = 0, 

 color arrow_color = CLR_NONE) 

{



OrderReliable_Fname = "OrderSendReliable";

OrderReliablePrint(" attempted " + OrderReliable_CommandString(cmd) + " " + volume + 

" lots @" + price + " sl:" + stoploss + " tp:" + takeprofit); 


if (IsStopped()) 

{

OrderReliablePrint("error: IsStopped() == true");

_OR_err = ERR_COMMON_ERROR; 

return(-1);

}

int cnt = 0;

while(!IsTradeAllowed() && cnt < retry_attempts) 

{

OrderReliable_SleepRandomTime(5*sleep_time, 12*sleep_maximum); 

cnt++;

}

if (!IsTradeAllowed()) 

{

OrderReliablePrint("error: no operation possible because IsTradeAllowed()==false, even after retries.");

_OR_err = ERR_TRADE_CONTEXT_BUSY; 


return(-1);  

}


int digits = MarketInfo(symbol, MODE_DIGITS);

if (digits > 0) 

{

price = NormalizeDouble(price, digits);

stoploss = NormalizeDouble(stoploss, digits);

takeprofit = NormalizeDouble(takeprofit, digits); 

}

if (stoploss != 0)

OrderReliable_EnsureValidStop(symbol, price, stoploss); 


int err = GetLastError();   

err = 0; 

_OR_err = 0; 

bool exit_loop = false;

bool limit_to_market = false; 


int ticket=-1;

if ((cmd == OP_BUYSTOP) || (cmd == OP_SELLSTOP) || (cmd == OP_BUYLIMIT) || (cmd == OP_SELLLIMIT)) 

{

cnt = 0;

while (!exit_loop) 

{

if (IsTradeAllowed()) 

{

ticket = OrderSend(symbol, cmd, volume, price, slippage, stoploss, 

takeprofit, comment, magic, expiration, arrow_color);

err = GetLastError();

_OR_err = err; 

else 

{

cnt++;

double servers_min_stop;

switch (err) 

{

case ERR_NO_ERROR:

exit_loop = true;

break;

case ERR_SERVER_BUSY:

case ERR_NO_CONNECTION:

case ERR_INVALID_PRICE:

case ERR_OFF_QUOTES:

case ERR_BROKER_BUSY:

case ERR_TRADE_CONTEXT_BUSY: 

cnt++; 

break;

case ERR_PRICE_CHANGED:

case ERR_REQUOTE:

RefreshRates();

continue;




case ERR_INVALID_STOPS:

servers_min_stop = MarketInfo(symbol, MODE_STOPLEVEL) * MarketInfo(symbol, MODE_POINT); 

if (cmd == OP_BUYSTOP)

{

if (MathAbs(Ask - price) <= servers_min_stop)

limit_to_market = true; 

else if (cmd == OP_SELLSTOP) 

{

if (MathAbs(Bid - price) <= servers_min_stop)

limit_to_market = true; 

}

exit_loop = true; 

break; 

default:

exit_loop = true;

break; 

}  


if (cnt > retry_attempts) 

exit_loop = true; 

if (exit_loop) 

{

if (err != ERR_NO_ERROR) 

{

OrderReliablePrint("non-retryable error: " + OrderReliableErrTxt(err)); 

}

if (cnt > retry_attempts) 

{

OrderReliablePrint("retry attempts maxed at " + retry_attempts); 

}

}

 

if (!exit_loop) 

{

OrderReliablePrint("retryable error (" + cnt + "/" + retry_attempts + 

"): " + OrderReliableErrTxt(err)); 

OrderReliable_SleepRandomTime(sleep_time, sleep_maximum); 

RefreshRates(); 

}

}

 

if (err == ERR_NO_ERROR) 

return(ticket);

if (!limit_to_market) 

{

OrderReliablePrint("failed to execute stop or limit order after " + cnt + " retries");

OrderReliablePrint("failed trade: " + OrderReliable_CommandString(cmd) + " " + symbol + 

"@" + price + " tp@" + takeprofit + " sl@" + stoploss); 

OrderReliablePrint("last error: " + OrderReliableErrTxt(err)); 

return(-1); 

}

}    

  

if (limit_to_market) 

{

OrderReliablePrint("going from limit order to market order because market is too close.");

if ((cmd == OP_BUYSTOP) || (cmd == OP_BUYLIMIT)) 

{

cmd = OP_BUY;

price = Ask;

else if ((cmd == OP_SELLSTOP) || (cmd == OP_SELLLIMIT)) 

{

cmd = OP_SELL;

price = Bid;

}

}

err = GetLastError(); 

err = 0; 

_OR_err = 0; 

ticket = -1;


if ((cmd == OP_BUY) || (cmd == OP_SELL)) 

{

cnt = 0;

while (!exit_loop) 

{

if (IsTradeAllowed()) 

{

RefreshRates();

      if (cmd == OP_BUY)

        {

      price = Ask;

               }

      else if (cmd == OP_SELL)

          {

      price = Bid;

        }

ticket = OrderSend(symbol, cmd, volume, price, slippage, 

stoploss, takeprofit, comment, magic, 

expiration, arrow_color);

err = GetLastError();

_OR_err = err;

if(err==ERR_INVALID_STOPS)

 {

               Print("This broker uses a bridge");

               ticket = OrderSendReliable(symbol, cmd, volume, price, slippage, 0, 0, comment, magic, expiration, arrow_color);

               if(ticket!=-1) OrderModifyReliable(ticket, price, stoploss, takeprofit, expiration);

    err = GetLastError();

    _OR_err = err;

 }

else

{

cnt++;

switch (err) 

{

case ERR_NO_ERROR:

exit_loop = true;

break;

case ERR_SERVER_BUSY:

case ERR_NO_CONNECTION:

case ERR_INVALID_PRICE:

case ERR_OFF_QUOTES:

case ERR_BROKER_BUSY:

case ERR_TRADE_CONTEXT_BUSY: 

cnt++; 

break;

case ERR_PRICE_CHANGED:

case ERR_REQUOTE:

RefreshRates();

      if (cmd == OP_BUY)

        {

      price = Ask;

               }

      else if (cmd == OP_SELL)

          {

      price = Bid;

        }

continue;

default:

exit_loop = true;

break; 

}  


if (cnt > retry_attempts) 

exit_loop = true;

if (!exit_loop) 

{

RefreshRates();

OrderReliablePrint("retryable error (" + cnt + "/" + 

retry_attempts + "): " + OrderReliableErrTxt(err)+ " (price = "+ price + ", Ask = "+ Ask +", and Bid = "+ Bid +")"); 

OrderReliable_SleepRandomTime(sleep_time,sleep_maximum); 

RefreshRates();

      if (cmd == OP_BUY)

        {

      price = Ask;

               }

      else if (cmd == OP_SELL)

          {

      price = Bid;

        }

}

if (exit_loop) 

{

if (err != ERR_NO_ERROR) 

{

OrderReliablePrint("non-retryable error: " + OrderReliableErrTxt(err)); 

}

if (cnt > retry_attempts) 

{

OrderReliablePrint("retry attempts maxed at " + retry_attempts); 

}

}

}

if (err == ERR_NO_ERROR) 

return(ticket);

OrderReliablePrint("failed to execute OP_BUY/OP_SELL, after " + cnt + " retries");

OrderReliablePrint("failed trade: " + OrderReliable_CommandString(cmd) + " " + symbol + 

"@" + price + " tp@" + takeprofit + " sl@" + stoploss);

      OrderReliablePrint("failed to execute OP_BUY/OP_SELL, after " + cnt + " retries");

OrderReliablePrint("last error: " + OrderReliableErrTxt(err)+ " (price = "+ price + ", Ask = "+ Ask +", and Bid = "+ Bid +")"); 

return(-1); 

}

 
  1. Please EDIT your post and use the "SRC" icon to place your code or attach it as a complete file.
  2. Since the code seems incomplete, we are unable to compile it ourselves to see the resulting compile errors. As it stands now, if compiled it gives 44 errors and 2 warnings.
Reason: