I gave you several links which explain it. Here's a graphic FIFO example.
Start with orders:
0
1
2
3
4
5
SomeChart
SomeChart
CurrentChart1
CurrentChart2
AnotherChart
AnotherChart
Loop goes 0,1, finds an order at position 2, and calls OrderClose.
SomeChart orders are closed by SL, before position 2 can send network request, have it processed in brokers queue, and received server reply. On next select, position list looks like:
William Roeder: I gave you several links which explain it. Here's a graphic FIFO example.
Start with orders:
0
1
2
3
4
5
SomeChart
SomeChart
CurrentChart1
CurrentChart2
AnotherChart
AnotherChart
Loop goes 0,1, finds an order at position 2, and calls OrderClose.
SomeChart orders are closed by SL, before position 2 can send network request, have it processed in brokers queue, and received server reply. On next select, position list looks like:
0
1
2
3
CurrentChart1
CurrentChart2
AnotherChart
AnotherChart
OrderClose completes, On next select, position list looks like:
0
1
2
CurrentChart2
AnotherChart
AnotherChart
Your code decremented i to 1. For loop increments i back to 2, then 3 and exits. Order at position zero is not closed.
LMAO
Typical Rhoeder
In the 3 years I have been using this function, in every situation in which I could see the need to close multiple positions on multiple charts or just 1, this function has never failed to close all the orders.
OP can use this function or not doesn't matter to me. I am still waiting on something better to come along, haven't seen anything but links and graphics so far.
In the 3 years I have been using this function, in every situation in which I could see the need to close multiple positions on multiple charts or just 1, this function has never failed to close all the orders.
LMAO as you apparently like bugs in your code. Three years and your bug remains.
Typical? Apparently you can't think beyond your own pride. Can't type correctly either.
What part of FIFO and multiple orders was unclear? What part of "non-FIFO (US
brokers,)(or the EA only opens
one order per symbol,) you cansimply count down" was unclear?
I don't help rude, arrogant, or ignorant persons. You are apparently all three. Added to my do not help list.
In the 3 years I have been using this function, in every situation in which I could see the need to close multiple positions on multiple charts or just 1, this function has never failed to close all the orders.
OP can use this function or not doesn't matter to me.
I'm going to side with whordor on this one. No matter what programming language you use you should never mutate an iterable while you are iterating it. With MQL you are forced against your will to iterate a mutating iterable and need to adjust your code accordingly. First, iterating index forward over the iterable (while mutating it explicitly) is an absolute recipe for failure. I also don't agree that reversing the index is the best fix, but it's better than forward since it won't skip over elements when they are removed. No matter what, working with FIFO and the MQL order-pool is always a race-condition. Therefore it is best to find the (F)irst ticket in the pool, deal with it, then recursively call back to the function so that you can limit the race-condition to just the nanosecond it takes to iterate over the pool (w/o trade ops).
I am still waiting on something better to come along, haven't seen anything but links and graphics so far.
This is better.
int closeFifoTrades(string symbol, int order_type) {
int ticket = WRONG_VALUE;
for (int i=OrdersTotal()-1; i>=0; --i)
if (OrderSelect(i, SELECT_BY_POS)
&& OrderSymbol() == symbol
&& OrderType() == order_type
&& (ticket == WRONG_VALUE || OrderTicket() < ticket)
)
ticket = OrderTicket();
if (OrderSelect(ticket, SELECT_BY_TICKET)
&& OrderClose(ticket, OrderLots(), OrderClosePrice(), 10)
)
return closeFifoTrades(symbol, order_type) + 1;
return0;
}
And shouldn't use iteration when a loop will do. Perhaps this, for both of us:
Iteration is looping. I think you meant recursion? Your function would only work on non-FIFO brokers, and even still, recursion is much more explicit than mutating the index.
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.
I would like to see an example where the code I posted would fail.
I gave you several links which explain it. Here's a graphic FIFO example.
LMAO
Typical Rhoeder
In the 3 years I have been using this function, in every situation in which I could see the need to close multiple positions on multiple charts or just 1, this function has never failed to close all the orders.
OP can use this function or not doesn't matter to me. I am still waiting on something better to come along, haven't seen anything but links and graphics so far.
Donald Gibson:
LMAO
Typical Rhoeder
In the 3 years I have been using this function, in every situation in which I could see the need to close multiple positions on multiple charts or just 1, this function has never failed to close all the orders.
LMAO
Typical Rhoeder
In the 3 years I have been using this function, in every situation in which I could see the need to close multiple positions on multiple charts or just 1, this function has never failed to close all the orders.
OP can use this function or not doesn't matter to me.
I'm going to side with whordor on this one. No matter what programming language you use you should never mutate an iterable while you are iterating it. With MQL you are forced against your will to iterate a mutating iterable and need to adjust your code accordingly. First, iterating index forward over the iterable (while mutating it explicitly) is an absolute recipe for failure. I also don't agree that reversing the index is the best fix, but it's better than forward since it won't skip over elements when they are removed. No matter what, working with FIFO and the MQL order-pool is always a race-condition. Therefore it is best to find the (F)irst ticket in the pool, deal with it, then recursively call back to the function so that you can limit the race-condition to just the nanosecond it takes to iterate over the pool (w/o trade ops).
I am still waiting on something better to come along, haven't seen anything but links and graphics so far.
This is better.
And shouldn't use iteration when a loop will do. Perhaps this, for both of us:
And shouldn't use iteration when a loop will do. Perhaps this, for both of us:
Iteration is looping. I think you meant recursion? Your function would only work on non-FIFO brokers, and even still, recursion is much more explicit than mutating the index.
Wasn't yet awake, yes I meant recursion. Function works on both.
Wasn't it you who said, "don't assume the order is ordered"? ...don't assume the order pool is ordered.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 and MetaTrader 4 - MQL4 programming forum
Count how many lost orders from the last profit order - MQL4 and MetaTrader 4 - MQL4 programming forum