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

Back to topics list  | 1 2 3 To post a new topic, please log in or register
avatar
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++;

avatar
102
johnnybegoode 2010.09.16 09:45 #
 
qjol:


just add before this line



void CloseAll() 
{

   for (int i=0; i<OrdersTotal(); i++)
   {
         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
               int ticketA = OrderTicket();
               double profitA = OrderProfit();
                            
               for (i++; i<OrdersTotal(); i++)
               {
                     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
                     { 
                              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?  

 
avatar
4
sajib0189 2016.06.12 10:07 #
 
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.
avatar
13001
WHRoeder 2016.06.13 15:10 #
 
  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
Back to topics list   | 1 2 3  

To add comments, please log in or register