거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Twitter에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

TradeTransaction Class - MetaTrader 5용 라이브러리

조회수:
9137
평가:
(32)
게시됨:
2019.03.06 01:31
업데이트됨:
2021.04.27 20:45
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

When performing some definite actions on a trade account, its state changes. Such actions include:

  • Sending a trade request from any MQL5 application in the client terminal using OrderSend and OrderSendAsync functions and its further execution;
  • Sending a trade request via the terminal graphical interface and its further execution;
  • activation of pending and stop orders on the server;
  • performing operations on the trade server side.

Special OnTradeTransaction() handler is provided in MQL5 to get trade transactions applied to an account.

void  OnTradeTransaction()
   const MqlTradeTransaction&    trans,     // trade transaction structure
   const MqlTradeRequest&        request,   // request structure
   const MqlTradeResult&         result     // response structure
   );

OnTradeTransaction() function can be used for:

  • Getting real-time notifications about trade transactions as they occur. 
  • Copying trades from one terminal to another.
  • Monitor trade transactions made by other ready-made expert advisors on different charts.
  • Having data on a trading operation type, you can decide on further analysis of the current state of orders, positions and deals on a trading account. (for example, update your calculations when the the list of open positions is changed).
  • Tracking the result of executing the trade request on a server sent by OrderSendAsync() function for conducting asynchronous trade operations without waiting for the trade server's response to a sent request. 

The OrderSendAsync() function is designed for high-frequency trading, when under the terms of the trading algorithm it is unacceptable to waste time waiting for a response from the server.


However, analysis of trade transations using the default OnTradeTransaction() handler provided in MQL5 seems complicated.

TradeTransaction class will map the underlying low-level trade transactions to a custom handler corresponding to the trade operation type. 

The class has the following methods:

//+------------------------------------------------------------------+
//| Class CTradeTransaction.                                         |
//| Purpose: Base class for trade transactions.                      |
//+------------------------------------------------------------------+
class CTradeTransaction
  {
public:
                     CTradeTransaction(void)  {   }
                    ~CTradeTransaction(void)  {   }
   //--- event handler
   void              OnTradeTransaction(const MqlTradeTransaction &trans,
                                        const MqlTradeRequest &request,
                                        const MqlTradeResult &result);
protected:
   //--- trade transactions
   //--- these methods should be overridden in the derived class
   virtual void      TradeTransactionOrderPlaced(ulong order)                      {   }
   virtual void      TradeTransactionOrderModified(ulong order)                    {   }
   virtual void      TradeTransactionOrderDeleted(ulong order)                     {   }
   virtual void      TradeTransactionOrderExpired(ulong order)                     {   }
   virtual void      TradeTransactionOrderTriggered(ulong order)                   {   }

   virtual void      TradeTransactionPositionOpened(ulong position, ulong deal)    {   }
   virtual void      TradeTransactionPositionStopTake(ulong position, ulong deal)  {   }
   virtual void      TradeTransactionPositionClosed(ulong position, ulong deal)    {   }
   virtual void      TradeTransactionPositionCloseBy(ulong position, ulong deal)   {   }
   virtual void      TradeTransactionPositionModified(ulong position)              {   }
  };

//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//---
   CTradeTransaction ExtTransaction;
//---
   ExtTransaction.OnTradeTransaction(trans,request,result);
  }
//+----


Finally this article makes an in-depth discussion about trade transactions in mql5  MQL5 Cookbook: Processing of the TradeTransaction Event

https://www.mql5.com/en/articles/1111



    Daily Percent Change Daily Percent Change

    This indicator uses the open price for the day, and computes the percent change for that day. Use on any chart TF up to and including D1.

    Average trend - multi time frame Average trend - multi time frame

    Short description.

    Vortex 2 Vortex 2

    Vortex 2

    Simple moving average Simple moving average

    Simple moving average