How to select by pos and compare 2 orders at a time? How to make a OrderSelect loop? - page 3

3243

johnnybegoode:

Ya, does not work and only 1 order is close and not both together

Thanks, but is this comparing 1 with 2, then 2 with 3, then 3 with 4?

I need to specifically compare order

1 & 2 only

3 & 4 only

5 & 6 only

..... and so on

other orders should not be compared.

```if (...) {} // do what you need with both
```
`pos++;`
629

qjol:

```void CloseAll()
{

for (int i=0; i<OrdersTotal(); i++)
{
{
int ticketA = OrderTicket();
double profitA = OrderProfit();

for (i++; i<OrdersTotal(); i++)
{
{
int ticketB =  OrderTicket();
double profitB = OrderProfit();
i++;

if ((profitA + profitB) > Profit)
{
OrderClose(ticketA,OrderLots(),OrderClosePrice(),5,Violet);
OrderClose(ticketB,OrderLots(),OrderClosePrice(),5,Violet);
}
}
}
}
}

}```

Thanks, but does not work, It closes any profitable orders. It is quite a mess.

EX. I have 10 orders like order 1,2,3,4,5,6,7,8,9,10. I opened them in sequential order, meaning opened order 1 then 2 then follow by 3 ... etc.

I would like to group them in pairs (see below).

1 & 2  (Pair 1) or

3 & 4  (Pair 2) or

5 & 6  (Pair 3) or

7 & 8  (Pair 4) or

9 & 10 (Pair 5)

I would also like a loop to go through the 10 orders over and over again until the addition of any pair is more than Profit.

Pair must be inseparable.

If the addition of any of the 5 pairs is more than Profit, only then close that pair. It should not close 1 & 5, or 1 & 3, or 2 & 3 ... etc.

Do you think that my ticketA/B and profitA/B is updated correctly in the loop as (1 & 2), (3 & 4), (4 & 5) ... etc.?

Or do I need to store ticket number in some sort of an array?

420

is it possible to compare select first order and compare with others all orders with same pairs and order type? if not match do this or break and erase variable, then again start with 2nd order select and compare with others below match with same pairs and order type? and go on like this.
16111

1. ```OrderClose(ticketA,OrderLots(),OrderClosePrice(),5,Violet);
OrderClose(ticketB,OrderLots(),OrderClosePrice(),5,Violet); ```
OCP is the close price of the last selected order. You're trying to close both orders at the same price. You must reselect as price will have moved during the first server call.
2. In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum