DinexSpace Trade Events Library
- Kütüphaneler
- Sürüm: 1.0
DinexSpace Trade Events Library is a library for MetaTrader 5 (MT5) that turns what happens on the trading account into a list of plain events, for your indicator or Expert Advisor. A position was opened, reduced, closed or had its stop-loss or take-profit changed. A pending order was placed, filled, canceled or expired. You poll the library and read the new events one by one, in the order they happened.
How it works
- Call DxTeCreate with a symbol and a magic number (or empty and -1 for everything). The account as it is now is the starting point.
- Call DxTePoll from OnTradeTransaction or OnTimer. The library compares the account with what it saw before and queues the new events.
- Call DxTeNext in a loop, and read each event with DxTeType, DxTeTicket, DxTeVolume, DxTePrice, DxTeProfit and the other functions.
What you get
- Nine event types: position opened, increased, reduced, closed and modified; order placed, filled, canceled and expired.
- Full details: ticket, symbol, magic number, direction, volume, price, stop-loss, take-profit, the result of a closing deal (profit, commission, swap, fee) and the reason (client, expert, stop-loss, take-profit, and so on).
- Time order: events come out in the order they happened, also when several are found by one poll.
- Between two polls: deals and finished orders are read from the history, so a position that opens and closes between two polls is still reported.
- Filters: each list can look at one symbol, one magic number, both, or everything. Up to eight lists in one program.
- Status codes with plain-English texts: bad handle, no list available, no current event, queue full.
- Light: each program has its own lists. No DLLs, no web requests, no Sleep. The library places no orders.
How to use it
- Copy DinexTradeEvents.ex5 to MQL5\Libraries.
- Add the import block with the functions you use (shown in the images and in the example EA).
- Create a list, poll it, read the events.
Example EA (included in the description images)
The example runs a cycle of 12 bars: it opens positions, moves the stop-loss and take-profit, closes part of a position and the rest, places pending orders, deletes them, lets them expire or fill. At the same time it builds its own list of what happened from OnTradeTransaction and, at the end, compares it with the library event by event. It also checks the filters, a list created while a position is open, a list that is polled only now and then, and the error codes. It prints the number of checks and the number of failed checks.
Notes
- The time of a stop-loss or take-profit change is the time of the poll that found it. If both change between two polls, you get one event with the latest values.
- Tested on a hedging account. On a netting account a position can grow or turn around; the increase event is in the code but was not tested, and a deal that closes one position and opens the opposite one is not split.
- The queue holds 4 000 events per list. When it is full the library sets an error code and drops the newest events; read the events more often.
- The library gives no entries or exits and does not predict any move.
Requirements
- MetaTrader 5, any symbol and timeframe.
