Select last trade of BUYLIMIT trigger.

 

My EA open 3 trades :
BuyLimit 1.1111
BuyLimit 1.0000
SellLimit 1.2345

Then 1 BuyLimit 1.1111 is trigger, so the OrderType is changed from "BUYLIMIT" to "BUY".

How to select the last modified trade "BUY" ?

I use the following code :

if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS)){ };
double last_price = OrderOpenPrice();
printf( last_price );

Output is 1.2345. How to make the output 1.1111 since it is last modified trade?

 
  1. Loop through all orders and look for an opened one.
  2. OrderSelect(OrdersTotal()-1,SELECT_BY_POS)

    Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum 2013.02.15
              PositionClose is not working - MQL5 programming forum 2020.02.21
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles 24 July 2006
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles Small>1 February 2011

Reason: