Orders β Overview
This section groups together methods for managing orders: creating, closing (directly or by opposite), and retrieving their details (live and historical). Use it for the full trade lifecycle.
π Methods in this folder
-
ShowOpenedOrders.md Get full details of all currently opened orders (ticket, symbol, lots, P/L, etc.).
-
ShowOpenedOrderTickets.md Lightweight list of ticket IDs for opened orders.
-
ShowOrdersHistory.md Retrieve closed trades within a specified time range (supports sorting).
-
ShowOrderSendExample.md Example of sending a market/pending order with volume, slippage, comment, magic.
-
CloseOrderExample.md Close (or delete) an order by its ticket and print server result/comment.
-
CloseByOrderExample.md Close one order by another opposite-direction order (hedged close-by).
β‘ Example Workflow (service wrapper)
// 1) Place an order (market or pending) β returns ticket in logs
await _service.ShowOrderSendExample("EURUSD");
// 2) Monitor active positions
await _service.ShowOpenedOrders();
await _service.ShowOpenedOrderTickets();
// 3) Option A: Close directly by ticket
await _service.CloseOrderExample(123456);
// 4) Option B: Close by opposite order (hedged accounts only)
await _service.CloseByOrderExample(123456, 654321);
// 5) Review historical performance for the past week
await _service.ShowOrdersHistory();
β Best Practices
- Fetch before you act. Call
ShowOpenedOrders(orOpenedOrdersAsync) before attempting modify/close to ensure the ticket is valid and still open. - CloseBy preconditions. Both tickets must be open, have equal volume, and be in opposite directions. Some brokers/accounts may disallow CloseBy.
- Deadlines & cancellation. Pass
deadline/CancellationTokenon long operations; the library applies sensible defaults but you can tighten or relax them. - Error handling. Catch
ApiExceptionMT4and log broker/terminal error codes (e.g., invalid ticket, trade disabled, market closed, stops too close). - Paging history. If you pull long ranges from
OrdersHistoryAsync, use paging (page/itemsPerPage) to avoid huge payloads. - Respect symbol rules. Use MarketβInfo docs (Digits, VolumeMin/Max/Step, TradeMode) to validate orders before send/close.
π― Purpose
Provide a compact toolkit for the order lifecycle:
- Open β Monitor β Close/Delete β Audit.
- Simplify UI/CLI workflows and automation.
- Offer predictable timeouts, retries, and clear error surfaces.
π Use this overview as a map and follow links to each .md file for complete method details, parameters, enums, and pitfalls.