How can I select oldest BuyStop immediately after it gets Buy?

 

i know how to select last open order and it is possible like this:

OrderSelect(OrdersTotal()-1,SELECT_BY_POS); or OrderSelect(LastTicket,SELECT_BY_TICKET);

but the problem is: i have many pending orders and i can only get the last order information by its ticket

i want to get the order information when every one of them goes from Buystop to Buy

any one knows how it is possible, help please...

 
Check the OrderType()
 
Search for when the # of Market_Orders vs the # of Pending_Orders changes. You need some Saved Variable. Example: if( Last_Market_Orders_Value > Last_Pending_Orders_Value ) where Values are updated at the end of every run.
 
Farbod:

i know how to select last open order and it is possible like this:

OrderSelect(OrdersTotal()-1,SELECT_BY_POS); or OrderSelect(LastTicket,SELECT_BY_TICKET);

but the problem is: i have many pending orders and i can only get the last order information by its ticket

i want to get the order information when every one of them goes from Buystop to Buy

any one knows how it is possible, help please...

  1. OrderSelect(OrdersTotal()-1 means the EA is incompatible with every other, including itself on other charts and manual trading.
  2. OrderSelect(LastTicket means your EA will not handle a terminal restart, reboot, power failure, etc. assuming you're not using persistent storage.
    for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS)                    // Only my orders w/
    &&  OrderMagicNumber()  == Magic.Number                 // my magic number
    &&  OrderSymbol()       == chart.symbol                 // and my pair.
    ){
        if (OrderType() == OP_BUY){ // order is open
        else{ // Still pending
 

thanks for your respond but the problem is not solved yet...

suppose we select the latest 1.buystop when it reaches the price, then we put a new 2.buystop and a 3.sellstop based on our first 1.buy and at this time the 3.sellstop gets 3.sell and does not hit its TP but the price will open the 2.buystop meanwhile 3.sell still is open, so the problem is we will get the 3.sell instead of 2.buy...

hope you get my problem because my english is not well ;-)

 
  1. Don't understand your problem because you haven't explained what you need only some senario and that your code (that you don't post) doesn't handle it.
  2. Why are you using limits/stops in a EA. They're useful for humans as you don't need to be watching the screen waiting for price to hit. Not necessary for EAs since it is always watching. Just wait for the price to hit one of your levels and open an order.
  3. If you just want to delete the sellStop when the buyStop opens and visa versa try:
    int closeAllOp = -1;
    for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS)                    // Only my orders w/
    &&  OrderMagicNumber()  == Magic.Number                 // my magic number
    &&  OrderSymbol()       == chart.symbol                 // and my pair.
    ){
        int OT = OrderType();
        if (OT == OP_BUY)  closeAllOp = OP_SELLSTOP; 
        if (OT == OP_SELL) closeAllOp = OP_BUYSTOP;  
    }
    for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS)                    // Only my orders w/
    &&  OrderMagicNumber()  == Magic.Number                 // my magic number
    &&  OrderSymbol()       == chart.symbol                 // and my pair.
    &&  OrderType()         == closeAllOp
    ){
        if (!OrderDelete( OrderTicket() ) 
            Alert("OrderDelete failed: ", GetLastError());
    }

Reason: