i'm trying to write a code that ( at a indicator signal ) closes any possible, lets say, BUY orders and opens a SELL order in its place; also vice-versa. I've tried a few different ways, seemed to work when backtesting, but when looking at it on LIVE, the orders do get closed, but the new ones do not get opened. Does someone have a solution for it? What i have so far is the following:
int CloseOrderOpenOrder(int closeOperation, int openOperation){
bool closedOrderId = false;
bool closeOrderExsist = OrderExsists(closeOperation);
if(closeOrderExsist){
while(true){
closedOrderId = CloseOrders(closeOperation);
// Print("Attempting to close an order.");if(closedOrderId == true){
// Success. Break out of loopbreak;
}
if (Fun_Error(GetLastError())==1){
// Print("Failed. Retrying. Order ID :" + closedOrderId);
continue;
}
// Print("Order closed. Opening order.");
OpenOrder(openOperation);
break;
}
} else {
OpenOrder(openOperation);
}
returntrue;
}
int OpenOrder(int type){
// ... open order for a specific direction
}
int CloseOrders(int type){
// ... close open orders for a specific direction
}
For equity securities, the Depth of Market window is available, where you can see the current Buy and Sell orders. Desired direction of a trade operation, required amount and requested price are specified for each order. To obtain information...
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.
Greetings,
i'm trying to write a code that ( at a indicator signal ) closes any possible, lets say, BUY orders and opens a SELL order in its place; also vice-versa. I've tried a few different ways, seemed to work when backtesting, but when looking at it on LIVE, the orders do get closed, but the new ones do not get opened. Does someone have a solution for it? What i have so far is the following: