2026-08-14 21:09:42 -03:00 | | | //+------------------------------------------------------------------+
|
| | | //| CLiveEnvironment.mqh |
|
| | | //| Synthetic Test Harness for MetaTrader 5 |
|
2026-08-21 00:24:00 -03:00 | | | //| Institutional Architecture in MQL5 - Part 2 Series |
|
2026-08-14 21:09:42 -03:00 | | | //+------------------------------------------------------------------+
|
| | | #ifndef SYNTHETIC_TEST_HARNESS_CLIVE_ENVIRONMENT_MQH
|
| | | #define SYNTHETIC_TEST_HARNESS_CLIVE_ENVIRONMENT_MQH
|
| | |
|
| | | #include "IMarketEnvironment.mqh"
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-08-20 22:00:35 -03:00 | | | //| CLiveEnvironment: Production Adapter for the Live MT5 Terminal. |
|
2026-08-14 21:09:42 -03:00 | | | //| |
|
2026-08-20 22:00:35 -03:00 | | | //| Bridges IMarketEnvironment to native MT5 API functions. |
|
| | | //| Uses the global scope resolution operator (`::`) to eliminate any |
|
| | | //| ambiguous calls or recursive collisions with interface methods. |
|
2026-08-14 21:09:42 -03:00 | | | //+------------------------------------------------------------------+
|
| | | class CLiveEnvironment : public IMarketEnvironment
|
| | | {
|
| | | private:
|
| | | string m_symbol;
|
| | |
|
| | | public:
|
| | | //+---------------------------------------------------------------+
|
2026-08-21 00:24:00 -03:00 | | | //| Constructor & Destructor |
|
2026-08-14 21:09:42 -03:00 | | | //+---------------------------------------------------------------+
|
2026-08-21 00:24:00 -03:00 | | | CLiveEnvironment(const string symbol = "")
|
| | | {
|
| | | m_symbol = (symbol == "") ? _Symbol : symbol;
|
| | | }
|
| | |
|
| | | ~CLiveEnvironment(void)
|
2026-08-14 21:09:42 -03:00 | | | {
|
| | | }
|
| | |
|
| | | //+---------------------------------------------------------------+
|
2026-08-21 00:24:00 -03:00 | | | //| Price queries |
|
2026-08-14 21:09:42 -03:00 | | | //+---------------------------------------------------------------+
|
| | | double GetBid(void)
|
| | | {
|
2026-08-20 22:00:35 -03:00 | | | return(::SymbolInfoDouble(m_symbol, SYMBOL_BID));
|
2026-08-14 21:09:42 -03:00 | | | }
|
| | |
|
| | | double GetAsk(void)
|
| | | {
|
2026-08-20 22:00:35 -03:00 | | | return(::SymbolInfoDouble(m_symbol, SYMBOL_ASK));
|
2026-08-14 21:09:42 -03:00 | | | }
|
| | |
|
| | | double GetSpread(void)
|
| | | {
|
2026-08-20 22:00:35 -03:00 | | | return((double)::SymbolInfoInteger(m_symbol, SYMBOL_SPREAD));
|
2026-08-14 21:09:42 -03:00 | | | }
|
| | |
|
| | | //+---------------------------------------------------------------+
|
2026-08-21 00:24:00 -03:00 | | | //| Time abstraction |
|
2026-08-14 21:09:42 -03:00 | | | //+---------------------------------------------------------------+
|
| | | datetime GetTimeCurrent(void)
|
| | | {
|
2026-08-20 22:00:35 -03:00 | | | return(::TimeCurrent());
|
2026-08-14 21:09:42 -03:00 | | | }
|
| | |
|
| | | //+---------------------------------------------------------------+
|
2026-08-21 00:24:00 -03:00 | | | //| Order execution |
|
2026-08-14 21:09:42 -03:00 | | | //+---------------------------------------------------------------+
|
2026-08-20 22:00:35 -03:00 | | | bool OrderSend(MqlTradeRequest &request, MqlTradeResult &result)
|
2026-08-14 21:09:42 -03:00 | | | {
|
2026-08-20 22:00:35 -03:00 | | | return(::OrderSend(request, result));
|
| | | }
|
| | |
|
| | | //+---------------------------------------------------------------+
|
2026-08-21 00:24:00 -03:00 | | | //| Depth of Market (DOM) |
|
2026-08-20 22:00:35 -03:00 | | | //+---------------------------------------------------------------+
|
| | | bool MarketBookGet(const string symbol, MqlBookInfo &book[])
|
| | | {
|
| | | return(::MarketBookGet(symbol, book));
|
2026-08-14 21:09:42 -03:00 | | | }
|
2026-08-21 00:24:00 -03:00 | | |
|
| | | //+---------------------------------------------------------------+
|
| | | //| Generic Symbol Info Bridge |
|
| | | //+---------------------------------------------------------------+
|
| | | double SymbolInfoDouble(const string symbol, const ENUM_SYMBOL_INFO_DOUBLE property)
|
| | | {
|
| | | return(::SymbolInfoDouble(symbol, property));
|
| | | }
|
| | |
|
| | | long SymbolInfoInteger(const string symbol, const ENUM_SYMBOL_INFO_INTEGER property)
|
| | | {
|
| | | return(::SymbolInfoInteger(symbol, property));
|
| | | }
|
| | |
|
| | | //+---------------------------------------------------------------+
|
| | | //| Generic Account Info Bridge |
|
| | | //+---------------------------------------------------------------+
|
| | | double AccountInfoDouble(const ENUM_ACCOUNT_INFO_DOUBLE property)
|
| | | {
|
| | | return(::AccountInfoDouble(property));
|
| | | }
|
| | |
|
| | | long AccountInfoInteger(const ENUM_ACCOUNT_INFO_INTEGER property)
|
| | | {
|
| | | return(::AccountInfoInteger(property));
|
| | | }
|
| | |
|
| | | //+---------------------------------------------------------------+
|
| | | //| Margin Calculation Bridge |
|
| | | //+---------------------------------------------------------------+
|
| | | bool OrderCalcMargin(const ENUM_ORDER_TYPE action,
|
| | | const string symbol,
|
| | | const double volume,
|
| | | const double price,
|
| | | double &margin)
|
| | | {
|
| | | return(::OrderCalcMargin(action, symbol, volume, price, margin));
|
| | | }
|
| | |
|
| | | //+---------------------------------------------------------------+
|
| | | //| Position Tracking Bridge |
|
| | | //+---------------------------------------------------------------+
|
| | | int PositionsTotal(void)
|
| | | {
|
| | | return(::PositionsTotal());
|
| | | }
|
| | |
|
| | | string PositionGetSymbol(const int index)
|
| | | {
|
| | | return(::PositionGetSymbol(index));
|
| | | }
|
| | |
|
| | | long PositionGetInteger(const ENUM_POSITION_PROPERTY_INTEGER property)
|
| | | {
|
| | | return(::PositionGetInteger(property));
|
| | | }
|
| | |
|
| | | double PositionGetDouble(const ENUM_POSITION_PROPERTY_DOUBLE property)
|
| | | {
|
| | | return(::PositionGetDouble(property));
|
| | | }
|
| | |
|
| | | //+---------------------------------------------------------------+
|
| | | //| Pending Order Tracking Bridge |
|
| | | //+---------------------------------------------------------------+
|
| | | int OrdersTotal(void)
|
| | | {
|
| | | return(::OrdersTotal());
|
| | | }
|
| | |
|
| | | ulong OrderGetTicket(const int index)
|
| | | {
|
| | | return(::OrderGetTicket(index));
|
| | | }
|
| | |
|
| | | long OrderGetInteger(const ulong ticket, const ENUM_ORDER_PROPERTY_INTEGER property)
|
| | | {
|
2026-09-11 14:43:32 -03:00 | | | int total = ::OrdersTotal();
|
| | | for(int i = 0; i < total; i++)
|
| | | {
|
| | | ulong t = ::OrderGetTicket(i);
|
| | | if(t == ticket)
|
| | | return(::OrderGetInteger(property));
|
| | | }
|
| | | return(0);
|
2026-08-21 00:24:00 -03:00 | | | }
|
| | |
|
| | | string OrderGetString(const ulong ticket, const ENUM_ORDER_PROPERTY_STRING property)
|
| | | {
|
2026-09-11 14:43:32 -03:00 | | | int total = ::OrdersTotal();
|
| | | for(int i = 0; i < total; i++)
|
| | | {
|
| | | ulong t = ::OrderGetTicket(i);
|
| | | if(t == ticket)
|
| | | return(::OrderGetString(property));
|
| | | }
|
| | | return("");
|
2026-08-21 00:24:00 -03:00 | | | }
|
| | |
|
| | | //+---------------------------------------------------------------+
|
| | | //| Deal History Bridge |
|
| | | //+---------------------------------------------------------------+
|
| | | bool HistorySelect(const datetime from_date, const datetime to_date)
|
| | | {
|
| | | return(::HistorySelect(from_date, to_date));
|
| | | }
|
| | |
|
| | | int HistoryDealsTotal(void)
|
| | | {
|
| | | return(::HistoryDealsTotal());
|
| | | }
|
| | |
|
| | | ulong HistoryDealGetTicket(const int index)
|
| | | {
|
| | | return(::HistoryDealGetTicket(index));
|
| | | }
|
| | |
|
| | | long HistoryDealGetInteger(const ulong ticket, const ENUM_DEAL_PROPERTY_INTEGER property)
|
| | | {
|
| | | return(::HistoryDealGetInteger(ticket, property));
|
| | | }
|
| | |
|
| | | double HistoryDealGetDouble(const ulong ticket, const ENUM_DEAL_PROPERTY_DOUBLE property)
|
| | | {
|
| | | return(::HistoryDealGetDouble(ticket, property));
|
| | | }
|
| | |
|
| | | string HistoryDealGetString(const ulong ticket, const ENUM_DEAL_PROPERTY_STRING property)
|
| | | {
|
| | | return(::HistoryDealGetString(ticket, property));
|
| | | }
|
2026-08-14 21:09:42 -03:00 | | | };
|
| | |
|
| | | #endif
|
2026-08-20 22:00:35 -03:00 | | | //+------------------------------------------------------------------+
|