Asynchronous trading orders have a huge advantage – high speed when sent in bulk. However, the spreading of such orders is hampered by the inconvenience – order result data can only be seen in OnTradeTransaction making users to build an event model of their trading strategy if they want asynchrony. This is not always easy (EAs), and sometimes even impossible (scripts).
The library solves this problem. At any time, it provides access to all transactions in the trading terminal (full data of the appropriate OnTradeTransaction) since the application launch simplifying the process of making your programs asynchronous.
Examples
The example below displays the library operation principle:
// Print out all transactions without OnTradeTransaction#include <fxsaberTradeTransactionsTradeTransactions.mqh> // Access to OnTradeTransaction data anywhere in the program
TRADETRANSACTIONS Transactions; // Trading transactionsconstbool Init = EventSetMillisecondTimer(100);
voidOnTimer()
{
  staticuint Total = 0;
  constuint NewTotal = Transactions.Total(); // Number of transactions saved
 Â
  for (uint i = Total; i < NewTotal; i++) // Run through new transactions
  {
    MqlTradeTransaction Trans;
    MqlTradeRequest Request;
    MqlTradeResult Result;
   Â
    // Get all the data on the respective transaction and print them.
    Print(TimeToString(Transactions[i].Get(Trans, Request, Result)) + "n" +
          ToString(Trans) + ToString(Request) + ToString(Result));       Â
  }
 Total = NewTotal;
}
Run this EA and try performing trading orders manually. The Expert Advisor will print all the details as if it has OnTradeTransaction. Although it has not!
There can be many practical scenarios for using such functionality. For example, trading a basket of symbols. For example, if you need to quickly open several positions inside the code. If they are open, you can perform additional trading operations without leaving the On function.
Since we frequently need to wait for a result of a massive sending of asynchronous orders, the library features the appropriate ability that can be quickly assessed using such an example
// Example of massive asynchronous trade orders with waiting for a result.#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006#include <fxsaberTradeTransactionsTradeTransactions.mqh> // Access to OnTradeTransaction data anywhere in the program
TRADETRANSACTIONS Transactions; // Trading transactions// Open Amount positions as quickly as possible. Return when positions are open.bool OpenPositions( constint Amount = 10 )
{
  uint RequestID[];
 Â
  for (int i = ArrayResize(RequestID, Amount) - 1; i >= 0; i--)
  {
    conststring Symb = SymbolName(i, true);
   Â
    RequestID[i] = OrderSendAsync(Symb, OP_BUY, 1, SymbolInfoDouble(Symb, SYMBOL_ASK), 100, 0, 0); // Send asynchronous order
  }
 Â
  return(Transactions.Waiting(RequestID)); // Wait for a server response to all asynchronous orders
}
// Close everything as quickly as possible. Return when the action is confirmed.bool CloseAll()
{
  uint RequestID[];
 Â
  for (int i = ArrayResize(RequestID, OrdersTotal()) - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS))
      // Send asynchronous order
      RequestID[i] = (OrderType() <= OP_SELL) ? OrderCloseAsync(OrderTicket(), OrderLots(), OrderClosePrice(), 100) : OrderDeleteAsync(OrderTicket());
 Â
  return(Transactions.Waiting(RequestID)); // Wait for a server response to all asynchronous orders
}
voidOnStart()
{
  if (OpenPositions())
    Print(CloseAll());
}
Of course, this is a script, but it still allows working with transactions via the library. The launch shows how to quickly open and close multiple trading positions/orders.
Features
The code IndicatorsfxsaberTradeTransactions.mq5 should be compiled.
JS-Chaos - EA MetaTrader 5 The author of the idea: JS_Sergey, the mq5 code author: barabashkakvn. The Expert Advisor is based on Bill Williams' strategy.…
MetaCOT 2 CFTC ToolBox (Set of Indicators) MT4 -… Contents GENERAL PROVISIONS Brief description Installing the libraries and indicators Several indicators in one window Exporting CFTC reports to CSV…
MAMACD - EA MetaTrader 5 Author of the idea: Â Yuri, author of the mq5 code: barabashkakvn. Two main iMA (Moving Average, MA) indicators with periods…
Dematus - EA MetaTrader 5 Author of the idea: Igor MQL5 code author: barabashkakvn How it works If there is a position, and the price…
EasyAndFastGUI library for creating graphical… EasyAndFastGUI v2.0 A new version of the EasyAndFastGUI v2.0 library for creating graphical interfaces has been released! This library contains…
MACD Stochastic - EA MetaTrader 5 The author of the idea: Firmin, the mq5 code author: barabashkakvn. The Expert Advisor uses two indicators, including iMACD (Moving…
🍪 By using RobotFX website, you agree with the use of cookies and following our terms of service.