Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

TypePendingOrderTriggered - MetaTrader 5 Expert - MT4/MT5 Resources

author EAcpu | 4 reads | 0 comments |

The Expert Advisor shows examples of how to solve the following problems : How to determine the moment when a pending order is triggered?

How Expert Advisor works: In the onlineTrade () function, we wait for transactions of type " TRADE_TRANSACTION_DEAL_ADD ":

TRADE_TRANSACTION_DEAL_ADD

Add transaction to history. It is executed as a result of order execution or account balance operation

As soon as we "catch" such a transaction, we immediately search for the order using the "bln_find_order" flag and assign the order ticket to the "ul_find_order" variable :

 //+------------------------------------------------------------------+
//| TradeTransaction function |
//+------------------------------------------------------------------+
Blank OnlineTrade ( const MqlTrade transaction & trans,
Constant Mql Transaction Requests & Requirements,
Constant Mql Transaction Result &Result)
  { //+----------------------------------------------------------------------------------+
//| TRADE_TRANSACTION_DEAL_* |
//| The following fields in the MqlTradeTransaction structure |
//|Fill in the trade transactions related to transaction processing|
//| (TRADE_TRANSACTION_DEAL_ADD, TRADE_TRANSACTION_DEAL_UPDATE |
//|and TRADE_TRANSACTION_DEAL_DELETE): |
//| •deal - transaction order; |
//| •Order - the order ticket based on which the transaction is executed;|
//| •symbol - the name of the trading symbol; |
//| •type——trade transaction type; |
//| •deal_type - transaction type; |
//| •Price - transaction price; |
//| •price_sl - stop loss price (filled, if specified in the order, |
//| • Basis for executed transactions); |
//| •price_tp - take profit price (if specified, filled in |
//| According to the order of transaction execution); |
//| •volume - trading volume in lots.                                  |
//| •position - opened position, |
//| Modified or closed due to transaction execution.              |
//| •position_by - relative position of the ticket.            |
//| It is populated only by transactions |
//| (Close the position by the opposite).                      |
//+------------------------------------------------------------------+
//--- Get the transaction type as enumeration value ENUM_TRADE_TRANSACTION_TYPE type = trans.type; //--- If the transaction is the result of adding a historical transaction if (type == TRADE_TRANSACTION_DEAL_ADD )
    { bln_find_order= true ; // true -> you should find the order
      ul_find_order=trans.order; }
  }

In OnTick(), we always check the status of the "bln_find_order" flag; once the flag equals true, we start searching for the order.


Attachment download

📎 typependingordertriggered.mq5 (10.05 KB)

Source: MQL5 #17610

Verification code Refresh