I found the OrderReliable (OrderReliable_2010.10.12.mqh) functions a while ago - I guess here on mql4.
I can't provide the link right now, because every time I perform a search on this site I get an error (did open a topic here: https://forum.mql4.com/38704).
Anyhow: I like these reliable order functions, but did miss one, which will reliable close pending orders. Anybody a clue, why it was never included?
I'm not a professional programmer, but know a bit, so I tried to modify the OrderCloseReliable to have a OrderDeleteReliable.
Code compiles OK, but I really have no idea if everything I did makes sense or will work as it should. Could somebody please check the code?
One question upfront: When and why should I use which of the following for OrderSelect? "SELECT_BY_TICKET", "SELECT_BY_POS"?
Greetings.
WorstCases
Here's my code:
bool OrderDeleteReliable(int ticket, color arrow_color = CLR_NONE)
{
OrderReliable_Fname = "OrderDeleteReliable";
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)==true)
OrderReliablePrint(" attempted delete of #" + ticket);
/* if (!IsConnected())
{
OrderReliablePrint("error: IsConnected() == false");
_OR_err = ERR_NO_CONNECTION;
return(false);
}
*/if (IsStopped())
{
OrderReliablePrint("error: IsStopped() == true");
return(false);
}
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(false);
}
int err = GetLastError(); // so we clear the global variable.
err = 0;
_OR_err = 0;
bool exit_loop = false;
cnt = 0;
bool result = false;
while (!exit_loop)
{
if (IsTradeAllowed())
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)==true)
{
int type2 = OrderType();
bool result2 = false;
switch(type2)
{
case OP_BUYLIMIT:
case OP_BUYSTOP:
case OP_SELLLIMIT:
case OP_SELLSTOP: result2 = OrderDelete( OrderTicket() );
break;
}
}
result = OrderDelete(ticket, arrow_color);
err = GetLastError();
_OR_err = err;
}
else
cnt++;
if (result == true)
exit_loop = true;
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:
case ERR_TRADE_TIMEOUT: // for modify this is a retryable error, I hope.
cnt++; // a retryable errorbreak;
case ERR_PRICE_CHANGED:
case ERR_REQUOTE:
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)==true)
continue; // we can apparently retry immediately according to MT docs.default:
// an apparently serious, unretryable error.
exit_loop = true;
break;
} // end switch if (cnt > retry_attempts)
exit_loop = true;
if (exit_loop)
{
RefreshRates();
if ((err != ERR_NO_ERROR) && (err != ERR_NO_RESULT))
OrderReliablePrint("non-retryable error: " + OrderReliableErrTxt(err));
if (cnt > retry_attempts)
OrderReliablePrint("retry attempts maxed at " + retry_attempts);
}
}
// we have now exited from loop. if ((result == true) || (err == ERR_NO_ERROR))
{
//OrderReliablePrint("apparently successful modification order, updated trade details follow.");//OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES); //OrderPrint(); return(true); // SUCCESS!
}
RefreshRates();
OrderReliablePrint("failed to execute delete after " + cnt + " retries");
OrderReliablePrint("failed delete: Ticket #" + ticket);
OrderReliablePrint("last error: " + OrderReliableErrTxt(err));
return(false);
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello Folks,
I found the OrderReliable (OrderReliable_2010.10.12.mqh) functions a while ago - I guess here on mql4.
I can't provide the link right now, because every time I perform a search on this site I get an error (did open a topic here: https://forum.mql4.com/38704).
Anyhow: I like these reliable order functions, but did miss one, which will reliable close pending orders. Anybody a clue, why it was never included?
I'm not a professional programmer, but know a bit, so I tried to modify the OrderCloseReliable to have a OrderDeleteReliable.
Code compiles OK, but I really have no idea if everything I did makes sense or will work as it should. Could somebody please check the code?
One question upfront: When and why should I use which of the following for OrderSelect? "SELECT_BY_TICKET", "SELECT_BY_POS"?
Greetings.
WorstCases
Here's my code: