richplank:
yes, sorry about that. I misunderstood what you needed.
I'm not sure what's wrong in your code snippet; maybe the expectation that the
"fired" pending order appears last in the order history?
You can adapt my code snippet for pending orders as follows:
inttrades[10000];
intmax = -1;
voidcloseSingletons(){// Build up table of tickets to close (those alone on a bar)for(inti = OrdersTotal() - 1; i >= 0; i-- ){if( ! OrderSelect(i, SELECT_BY_POS, MODE_TRADES))continue;
if(OrderSymbol() != Symbol())continue;
if(OrderType() == OP_BUY || OrderType() == OP_SELL)continue;
intb = iBarShift(Symbol(), Period(), OrderOpenTime(), false);
max = MathMax(max, b);
if(trades[b] == 0)trades[b] = OrderTicket(); elsetrades[b] = 0;
}// Close the ones being alone and clear the table to be ready for next timefor(i = 0; i <= max; i++ ){if(trades[b] != 0)OrderDelete(trades[b]);
trades[b] = 0;
}max = -1;
}
The idea is still to pair up trades by virtue of iBarShift(..) i.e. which bar the
order is opened at, and then delete all pending orders that are singletons on their
bars.
Thanks Richplank,
But your code is deleting the other pending order when one of them get triggered,
what I need is delete the other pending order when the other order closed because
of it's SL or TP. Or there's any other way to use your code?
Good that it works. Though I obviously didn't really grasp your intention, and maybe
what you want is beyond MT4, because I don't think there is any direct link kept
between a pending order and the order it seeds apart from the position profile
(price, SL and TP). The seeded buy/sell order is a different order, and I don't
think it inherits the magic number of the pending order. (I may be wrong, of course)
Your method is good, but requires a trace-back from the recently closed buy/sell
order to the pending order that seeded it, and then a trace-back from that to the
order it was paired with. The first trace-back could perhaps be done by matching
the open time of the buy/sell order with the close time of the pending order, while
the second could be done using magic number. Alternatively you might be able to
use the comment field for both trace-backs, if (as I think) the comment is inherited
from a pending order to the seeded order, although MT4 will add to and change the
tail part of the comment.
Or, if you are sure about the account activity, you might be able to rely on that
the pending order is the one closed before the most recently closed buy/sell order,
and thus look at and use the magic of last_trade-2 instead. That would probably
work no less incidentally than the current solution.
Btw, My code is working fine now, i've change it a little bit, although I don't
quiet understand why a minor change could make it works.
This is the correct code
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.
yes, sorry about that. I misunderstood what you needed.
I'm not sure what's wrong in your code snippet; maybe the expectation that the "fired" pending order appears last in the order history?
You can adapt my code snippet for pending orders as follows:
The idea is still to pair up trades by virtue of iBarShift(..) i.e. which bar the order is opened at, and then delete all pending orders that are singletons on their bars.
Thanks Richplank,
But your code is deleting the other pending order when one of them get triggered, what I need is delete the other pending order when the other order closed because of it's SL or TP. Or there's any other way to use your code?
Thanks for the code Richplank, I do it this way
But I'm still curious why my own code doesn't work, if anybody could fix it, we can control it using magic number.
Thanks
Your method is good, but requires a trace-back from the recently closed buy/sell order to the pending order that seeded it, and then a trace-back from that to the order it was paired with. The first trace-back could perhaps be done by matching the open time of the buy/sell order with the close time of the pending order, while the second could be done using magic number. Alternatively you might be able to use the comment field for both trace-backs, if (as I think) the comment is inherited from a pending order to the seeded order, although MT4 will add to and change the tail part of the comment.
Or, if you are sure about the account activity, you might be able to rely on that the pending order is the one closed before the most recently closed buy/sell order, and thus look at and use the magic of last_trade-2 instead. That would probably work no less incidentally than the current solution.
Btw, My code is working fine now, i've change it a little bit, although I don't quiet understand why a minor change could make it works.
This is the correct code
Be careful with Select by position, as it is affected by the sorting order of your trades in the terminal window.
***********
I may be confused about this, sorry.. Will retest
***********
Be careful with Select by position, as it is affected by the sorting order of your trades in the terminal window.
Or if you don't mind give me an example please?
Thank you