How can i get/select the last placed order either pending or market of a specific currency pair in MQL4

 

Hello traders, am building an EA that place a market order and also a pending order at the same time, once the pending order got activated and become a market order, The ea will place an opposite pending order. 
But Now i want to Attach the Ea to more than one currency  pair, How do i know when the last placed order on that currency pair has become a market order, so that i can placed opposite side pending order.

Here is my initial code ?? 

Am sure OrdersTotal -1 will return the last placed other on the account not with a specific currency pair


if(OrderSelect(OrdersTotal() - 1,SELECT_BY_POS))
           {
            if(OrderType() < 2 && OrderType() == OP_BUY)
              {
               firstSet01 = OrderSend(NULL,OP_SELLSTOP,OrderLots() * 2,OrderOpenPrice() - pipGapBtwPrimaryDirectionAnd1stHedgeTrade * Point,slippage,0,0,"firstSet01");
               if(firstSet01 > 0)
                 {
                  modify(firstSet01,OrderOpenPrice()- pipGapBtwPrimaryDirectionAnd1stHedgeTrade * Point,OrderOpenPrice() + pipGapBtwPrimaryDirectionAnd1stHedgeTrade * Point,OrderOpenPrice() - (pipGapBtwPrimaryDirectionAnd1stHedgeTrade + primaryDirectionTp) * Point,0);
                 }
              }

            if(OrderType() < 2 && OrderType() == OP_SELL)
              {
               firstSet02 = OrderSend(NULL,OP_BUYSTOP,OrderLots() * 2,OrderOpenPrice() + pipGapBtwPrimaryDirectionAnd1stHedgeTrade * Point,slippage,0,0,"firstSet02");
               if(firstSet02 > 0)
                 {
                  modify(firstSet02,OrderOpenPrice() + pipGapBtwPrimaryDirectionAnd1stHedgeTrade * Point,OrderOpenPrice() - primaryDirectionTp * Point,OrderOpenPrice() + primaryDirectionSl * Point,0);
                 }
              }
           }
        }
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
 
Bill Mayheptad: Here is my initial code ??

Only you know whether that is your “initial code.”

Bill Mayheptad: Am sure OrdersTotal -1 will return the last placed other on the account 

Only if you are running on one symbol.

 
William Roeder:

Only you know whether that is your “initial code.”

Only if you are running on one symbol.

so how do i get the last placed order of a particular symbol ??

 
Bill Mayheptad: so how do i get the last placed order of a particular symbol ??

Go through the list and find the highest ticket number for the symbol.