If you select from the MODE_TRADES pool then you are selecting only Open orders so they won't have an OrderCloseTime()
I think you need to be clearer about what you are trying to do . . . for example, you said the last Sell or last Buy . . . does that mean that there are no Buy orders open or no Sell orders open ? or could the one before the last one still be open ?
Hi Mr. RaptorUK
Thank you for your help
for example, you said the last Sell or last Buy . . . does that mean that there are no Buy orders open or no Sell orders open ?
for every buy there is a pending sell (OP_SELLSTOP)
and for every sell there is a pending buy (OP_BUYSTOP)
but if the buy order is closed In the case of the profit or loss
I need to delete the pending sell orders
Same thing for the sell order if it s closed pending buy should be deleted
- Why don't you simply delete the pending order, once its opposite opens?
int openTicket=-1, pendingTicket = -1; for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if ( OrderSelect(iPos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == Magic.Number // my magic number && OrderSymbol() == chart.symbol // and my pair. ){ if (OrderType() <= OP_SELL) openTicket = OrderTicket(); else pendingTicket = OrderTicket(); } if (openTicket > -1 && pendingTicket > -1){ if (!OrderDelete(pendingTicket)) Alert("OrderDelect(", pendingTicket, ") failed: ", GetLastError()); }
- Otherwise, if there is only one pending order and you always open two, the other must have triggered and closed.
int openTicket = -1, pendingTicket = -1, nPending = 0; for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if ( OrderSelect(iPos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == Magic.Number // my magic number && OrderSymbol() == chart.symbol // and my pair. ){ if (OrderType() <= OP_SELL) openTicket = OrderTicket(); else{ pendingTicket = OrderTicket(); nPending++; } } if (openTicket == -1 && nPending == 1){ if (!OrderDelete(pendingTicket)) Alert("OrderDelect(", pendingTicket, ") failed: ", GetLastError()); }
Not compiled, not tested. int total= OrdersTotal(); if(OrdersTotal()>0) { for(int i=0;i<OrdersTotal();i++) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
The IF is unnecessary, you must count down when closing/deleteing in the presence of multiple order (multiple charts). Always test return codes (orderSelect)
but if the buy order is closed In the case of the profit or loss
I need to delete the pending sell orders
Same thing for the sell order if it s closed pending buy should be deleted
OK, I understand that, but is there only one Buy and one Sell at at time or may there be many ?
If there is just ever one Buy or one Sell it is easy . . . loop through the open orders looking for a Buy, if you don't find one then simply OrderDelete() the pending buy order . . . and similarly for the Sell . . .
If there can be more than one then it gets more complicated and you need to be able to match up a Buy with a particular pending Buy and a Sell with a particular pending Sell.
Dear WHRoeder
Thank you for your help
But the issue is
For every opening order there is a one specific pending order, how can I delete this pending order if this opening order it s closed
Thanks again dear RaptorUK
really really I appreciate it
If there can be more than one then it gets more complicated and you need to be able to match up a Buy with a particular pending Buy and a Sell with a particular pending Sell.
How can I resolve this problem ?
I tried tickets numbers in vain
if(OrdersTotal()>0) { for(i=0;i<OrdersTotal();i++) { OrderSelect(i,SELECT_BY_TICKET,MODE_HISTORY); if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic_Nu) { if(OrderType()==OP_BUY){buy_ticket=OrderTicket();} if(OrderType()==OP_SELL){sell_ticket=OrderTicket();} } } //---- for(i=0;i<OrdersTotal();i++) { OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES); if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic_Nu) { if(OrderType()==OP_BUYSTOP){buystop_ticket=OrderTicket();} if(OrderType()==OP_SELLSTOP){sellstop_ticket=OrderTicket();} } } }
What about this solution how can I code it
If the Ask cross the stop loss of the buy ( win case) delete the pending sell
Or if the Bid cross the stop loss of the sell (win case) delete the pending buy
What about this solution how can I code it
If the Ask cross the stop loss of the buy ( win case) delete the pending sell
Or if the Bid cross the stop loss of the sell (win case) delete the pending buy
Sorry I misunderstood . . .
You still haven't said if you have more than one Buy or more than one Sell . . . if you just have one you can do this . . .
void Delete() { int cnt, i; int total= OrdersTotal(); bool DeletePendingSell = true, DeletePendingBuy = true; if(OrdersTotal()>0) { for( i=0;i<OrdersTotal();i++) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { Print("Order Select failed: ", GetLastError()); return; } if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic_Nu) { if(OrderType()==OP_BUY) DeletePendingSell = false; if(OrderType()==OP_SELL) DeletePendingBuy = false; } } for( i=0;i<OrdersTotal();i++) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { Print("Order Select failed: ", GetLastError()); return; } if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic_Nu) { if(OrderType()==OP_SELLSTOP && DeletePendingSell ) { if(!OrderDelete(OrderTicket())) Print("Delete Pending SellStop failed", GetLastError()); } if(OrderType()==OP_BUYSTOP && DeletePendingBuy ) { if(!OrderDelete(OrderTicket())) Print("Delete Pending BuyStop failed", GetLastError()); } } } } }
NOT TESTED ! !
Dear WHRoeder
Thank you for your help
But the issue is
For every opening order there is a one specific pending order, how can I delete this pending order if this opening order it s closed
Why are you opening multiple pending orders in the same direction per pair? There's no point in having 2 buy stops.
If you still must, you're going to have to save the grouping in a file and restore on startup.
Thank you so much dear RaptorUK
You are a Angel
Your function is exact and helpful
You still haven't said if you have more than one Buy or more than one Sell . . . if you just have one you can do this . . .
Yes sometime there is more than one buy or sell but I can make the expert allow only one trade every time
Thanks again and Best regards
Why are you opening multiple pending orders in the same direction per pair? There's no point in having 2 buy stops.
If you still must, you're going to have to save the grouping in a file and restore on startup.
Dear WHRoeder
Thank you for your interest
Why are you opening multiple pending orders in the same direction per pair? There's no point in having 2 buy stops.
Let's take a real example
AUDNZD
Suppose this pair will be go down
If I make a order sell 1.25900
Take profit in 1.2390
in place of stop loss I will putt a buy stop in 1.2640
suppose after one hour I make a another order sell automatically I need a another stop loss in my case that s mean I need a another buy stop
in this point I have 2 sell orders and 2 buy stop pending orders
what I need, if price cross the take profit of one of them automatically his stop loss should be deleted in my case the stop loss is the pending order
Hope you get what I mean
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi fellas
how can I delete a OP_BUYSTOP order if the last OP_SELL order it 's closed
and the same thing OP_SELLSTOP if the last OP_BUY it's closed
I tried this code but it didn't work
many thanks in advance for your help