English

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

 3134 qjol 2010.09.15 20:27 #   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. just add before this line ```if (...) {} // do what you need with both ``` `pos++;`
 103 johnnybegoode 2010.09.16 09:45 #   qjol: just add before this line ```void CloseAll() {    for (int i=0; i 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?   similar
 13126 WHRoeder 2016.06.13 15:10 #   ```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. 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