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

TradeTransactions - MetaTrader 5용 라이브러리

조회수:
4355
평가:
(30)
게시됨:
2018.10.25 18:37
\MQL5\Indicators\fxsaber\ \MQL5\Experts\fxsaber\ \MQL5\Include\fxsaber\TradeTransactions\
Resource.mqh (0.63 KB) 조회
String.mqh (0.45 KB) 조회
\MQL5\Include\
TypeToBytes.mqh (20.54 KB) 조회
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

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 <fxsaber\TradeTransactions\TradeTransactions.mqh> // Access to OnTradeTransaction data anywhere in the program

TRADETRANSACTIONS Transactions; // Trading transactions

const bool Init = EventSetMillisecondTimer(100);

void OnTimer()
{
  static uint Total = 0;
  const uint 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 <fxsaber\TradeTransactions\TradeTransactions.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( const int Amount = 10 )
{
  uint RequestID[];
  
  for (int i = ArrayResize(RequestID, Amount) - 1; i >= 0; i--)
  {
    const string 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
}

void OnStart()
{
  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 Indicators\fxsaber\TradeTransactions.mq5 should be compiled.
  • TypeToBytes library is used.
  • The library source code features (ResourceData.mqh) a universal class that allows you to conveniently save/read data to/from Resources.

MetaQuotes Ltd에서 러시아어로 번역함.
원본 코드: https://www.mql5.com/ru/code/22166

Skyscraper Skyscraper

A trend indicator of NRTR type with an additional middle line

XRSI_Candle_Vol_Zer_Alerts XRSI_Candle_Vol_Zer_Alerts

XRSI_Candle_Vol_Zer indicator provides alerts, sends email and push notifications at the incoming trading signals

Easy Canvas Easy Canvas

The library and iCanvas class simplify writing programs using Canvas.

Previous Candle Breakdown 3 Previous Candle Breakdown 3

"Previous Candle Breakdown" Expert Advisor.