From 999de5fb4e9fbd4ae63ea2ae8890c06dcb0591fd Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Thu, 5 Sep 2024 19:57:30 +0200 Subject: [PATCH] C++ compatibility fixes. --- Indicator/Indicator.struct.h | 2 +- Indicator/IndicatorTf.h | 2 +- Platform/Chart/Chart.enum.h | 16 ++++++++------ Platform/Order.enum.h | 38 +++++++++++++++++--------------- Platform/Order.h | 14 ++++++------ Platform/Order.struct.h | 11 +++++---- Storage/ItemsHistory.h | 7 +++--- Storage/ValueStorage.indicator.h | 6 +---- Trade.mqh | 16 ++++++++------ 9 files changed, 57 insertions(+), 55 deletions(-) diff --git a/Indicator/Indicator.struct.h b/Indicator/Indicator.struct.h index b2229022e..c488930ce 100644 --- a/Indicator/Indicator.struct.h +++ b/Indicator/Indicator.struct.h @@ -133,7 +133,7 @@ struct IndicatorParams { void Set(STRUCT_ENUM(IndicatorParams, ENUM_INDI_PARAMS_PROP) _prop, T _value) { switch (_prop) { case INDI_PARAMS_PROP_BPS: - bps = (uint)_value; + bps = (unsigned int)_value; return; default: break; diff --git a/Indicator/IndicatorTf.h b/Indicator/IndicatorTf.h index 84548e7be..30f038823 100644 --- a/Indicator/IndicatorTf.h +++ b/Indicator/IndicatorTf.h @@ -65,7 +65,7 @@ class IndicatorTf : public IndicatorCandle -#include + #ifdef EMSCRIPTEN + #include + #include EMSCRIPTEN_BINDINGS(ENUM_TIMEFRAMES) { emscripten::enum_("timeframes") @@ -165,7 +167,7 @@ EMSCRIPTEN_BINDINGS(ENUM_APPLIED_PRICE) { .value("weighted", PRICE_WEIGHTED); } -#endif + #endif #endif diff --git a/Platform/Order.enum.h b/Platform/Order.enum.h index ca53f9b69..b8c94d7fa 100644 --- a/Platform/Order.enum.h +++ b/Platform/Order.enum.h @@ -26,8 +26,8 @@ */ #ifndef __MQL__ -// Allows the preprocessor to include a header file when it is needed. -#pragma once + // Allows the preprocessor to include a header file when it is needed. + #pragma once #endif /* Order actions. */ @@ -92,17 +92,17 @@ enum ENUM_ORDER_PROPERTY_CUSTOM { // Defines enumeration for order close reasons. enum ENUM_ORDER_REASON_CLOSE { - ORDER_REASON_CLOSED_ALL = 0, // Closed all - ORDER_REASON_CLOSED_BY_ACTION, // Closed by action - ORDER_REASON_CLOSED_BY_CONDITION, // Closed by condition - ORDER_REASON_CLOSED_BY_EXPIRE, // Closed by expiration - ORDER_REASON_CLOSED_BY_OPPOSITE, // Closed by opposite order - ORDER_REASON_CLOSED_BY_SIGNAL, // Closed by signal - ORDER_REASON_CLOSED_BY_SL, // Closed by stop loss - ORDER_REASON_CLOSED_BY_TEST, // Closed by test - ORDER_REASON_CLOSED_BY_TP, // Closed by take profit - ORDER_REASON_CLOSED_BY_USER, // Closed by user - ORDER_REASON_CLOSED_UNKNOWN, // Closed by unknown event + ORDER_REASON_CLOSED_ALL = 0, // Closed all + ORDER_REASON_CLOSED_BY_ACTION, // Closed by action + ORDER_REASON_CLOSED_BY_CONDITION, // Closed by condition + ORDER_REASON_CLOSED_BY_EXPIRE, // Closed by expiration + ORDER_REASON_CLOSED_BY_OPPOSITE, // Closed by opposite order + ORDER_REASON_CLOSED_BY_SIGNAL, // Closed by signal + ORDER_REASON_CLOSED_BY_SL, // Closed by stop loss + ORDER_REASON_CLOSED_BY_TEST, // Closed by test + ORDER_REASON_CLOSED_BY_TP, // Closed by take profit + ORDER_REASON_CLOSED_BY_USER, // Closed by user + ORDER_REASON_CLOSED_UNKNOWN, // Closed by unknown event }; #ifndef __MQL5__ @@ -209,7 +209,8 @@ enum ENUM_ORDER_PROPERTY_INTEGER { ORDER_MAGIC, // ID of an Expert Advisor that has placed the order. ORDER_REASON, // The reason or source for placing an order. ORDER_POSITION_ID, // Position identifier that is set to an order as soon as it is executed. - ORDER_POSITION_BY_ID // Identifier of an opposite position used for closing by order ORDER_TYPE_CLOSE_BY. + ORDER_POSITION_BY_ID, // Identifier of an opposite position used for closing by order ORDER_TYPE_CLOSE_BY. + __ORDER_REASON = 23, // Required, so ORDER_REASON define could work without throwing compilation error. }; /** @@ -219,9 +220,10 @@ enum ENUM_ORDER_PROPERTY_INTEGER { * @see: https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties */ enum ENUM_ORDER_PROPERTY_STRING { - ORDER_COMMENT, // Order comment. - ORDER_EXTERNAL_ID, // Order identifier in an external trading system (on the Exchange). - ORDER_SYMBOL, // Symbol of the order. + ORDER_COMMENT, // Order comment. + ORDER_EXTERNAL_ID, // Order identifier in an external trading system (on the Exchange). + ORDER_SYMBOL, // Symbol of the order. + __ORDER_EXTERNAL_ID = 20 // Required, so ORDER_EXTERNAL_ID define could work without throwing compilation error. }; #endif @@ -249,7 +251,7 @@ enum ENUM_ORDER_TYPE { ORDER_TYPE_UNSET // A NULL value. }; #else -#define ORDER_TYPE_UNSET NULL + #define ORDER_TYPE_UNSET NULL #endif /* Positions */ diff --git a/Platform/Order.h b/Platform/Order.h index 2928cb9f6..88ccbf307 100644 --- a/Platform/Order.h +++ b/Platform/Order.h @@ -931,11 +931,11 @@ class Order : public SymbolInfo { _request.action = TRADE_ACTION_DEAL; _request.comment = _comment != "" ? _comment : odata.GetReasonCloseText(); _request.deviation = orequest.deviation > 0 ? orequest.deviation : 40; - _request.magic = odata.Get(ORDER_MAGIC); + _request.magic = odata.Get(ORDER_MAGIC); _request.symbol = odata.Get(ORDER_SYMBOL); _request.type = NegateOrderType(odata.Get(ORDER_TYPE)); _request.type_filling = GetOrderFilling(odata.Get(ORDER_SYMBOL)); - _request.position = odata.Get(ORDER_PROP_TICKET); + _request.position = odata.Get(ORDER_PROP_TICKET); _request.price = SymbolInfo::GetCloseOffer(odata.Get(ORDER_TYPE)); _request.volume = odata.Get(ORDER_VOLUME_CURRENT); Order::OrderSend(_request, oresult, oresult_check); @@ -959,12 +959,12 @@ class Order : public SymbolInfo { if (OrderSelect()) { Refresh(true); if (!IsClosed()) { - ologger.Error( - StringFormat("Failed to send order request %u for position %d! Error: %d (%s)", oresult.request_id, - _request.position, fmax(oresult.retcode, oresult_check.retcode), oresult_check.comment), - __FUNCTION_LINE__); + ologger.Error(StringFormat("Failed to send order request %u for position %d! Error: %d (%s)", + oresult.request_id, _request.position, + fmax(oresult.retcode, oresult_check.retcode), C_STR(oresult_check.comment)), + __FUNCTION_LINE__); if (ologger.GetLevel() >= V_DEBUG) { - ologger.Debug(StringFormat("Failed request: %s", ToString()), __FUNCTION_LINE__); + ologger.Debug(StringFormat("Failed request: %s", C_STR(ToString())), __FUNCTION_LINE__); } } } diff --git a/Platform/Order.struct.h b/Platform/Order.struct.h index 1b83a8010..7d5411688 100644 --- a/Platform/Order.struct.h +++ b/Platform/Order.struct.h @@ -26,8 +26,8 @@ */ #ifndef __MQL__ -// Allows the preprocessor to include a header file when it is needed. -#pragma once + // Allows the preprocessor to include a header file when it is needed. + #pragma once #endif // Includes. @@ -473,7 +473,8 @@ struct OrderData { * Returns a comment with reason */ string GetCloseComment() { - string _result = StringFormat("%s (mn=%d,pips=%d)", GetReasonCloseText(), magic, Get(ORDER_PROP_PROFIT_PIPS)); + string _result = + StringFormat("%s (mn=%d,pips=%d)", C_STR(GetReasonCloseText()), magic, Get(ORDER_PROP_PROFIT_PIPS)); return _result; } @@ -511,9 +512,7 @@ struct OrderData { return "???"; } // Setters. - void IncCloseTries() { - close_tries++; - } + void IncCloseTries() { close_tries++; } template void Set(ENUM_ORDER_PROPERTY_CUSTOM _prop_name, T _value) { switch (_prop_name) { diff --git a/Storage/ItemsHistory.h b/Storage/ItemsHistory.h index 08cc1f37a..85b16383c 100644 --- a/Storage/ItemsHistory.h +++ b/Storage/ItemsHistory.h @@ -29,14 +29,15 @@ #pragma once #endif -#include "../Refs.mqh" -#include "../Storage/Dict/DictStruct.h" - /** * Direction used by ItemsHistoryItemProvider's methods. */ enum ENUM_ITEMS_HISTORY_DIRECTION { ITEMS_HISTORY_DIRECTION_FORWARD, ITEMS_HISTORY_DIRECTION_BACKWARD }; +#include "../Indicator/IndicatorData.h" +#include "../Refs.mqh" +#include "../Storage/Dict/DictStruct.h" + /** * Forward declaration. */ diff --git a/Storage/ValueStorage.indicator.h b/Storage/ValueStorage.indicator.h index 9cf03cc45..c6e4d6346 100644 --- a/Storage/ValueStorage.indicator.h +++ b/Storage/ValueStorage.indicator.h @@ -66,17 +66,13 @@ class IndicatorBufferValueStorage : public HistoryValueStorage { }; // clang-format off -#include "../Indicator/IndicatorData.h" +#include "../Indicator/IndicatorBase.h" // clang-format on #ifndef __MQL__ template C IndicatorBufferValueStorage::Fetch(int _rel_shift) { IndicatorBase* _indi = THIS_ATTR indi_candle.Ptr(); - #ifdef __MQL__ - return _indi PTR_DEREF GetValue(mode, THIS_ATTR RealShift(_rel_shift)); - #else return _indi PTR_DEREF template GetValue(mode, THIS_ATTR RealShift(_rel_shift)); - #endif } #endif diff --git a/Trade.mqh b/Trade.mqh index 3b096ec70..4ada25cb4 100644 --- a/Trade.mqh +++ b/Trade.mqh @@ -205,7 +205,8 @@ class Trade : public Taskable { MqlTradeRequest _request = {(ENUM_TRADE_REQUEST_ACTIONS)0}; _request.action = TRADE_ACTION_DEAL; _request.comment = _comment; - _request.deviation = tparams.Get(TRADE_PARAM_SLIPPAGE); // The maximal price deviation, specified in points. + _request.deviation = + tparams.Get(TRADE_PARAM_SLIPPAGE); // The maximal price deviation, specified in points. _request.magic = _magic > 0 ? _magic : tparams.Get(TRADE_PARAM_MAGIC_NO); _request.symbol = GetSource() PTR_DEREF GetSymbol(); _request.price = GetSource() PTR_DEREF GetOpenOffer(_type); @@ -888,11 +889,12 @@ HistorySelect(0, TimeCurrent()); // Select history for access. OrderMoveToHistory(_order.Ptr()); order_last = _order; } else { - logger.Error(StringFormat("Failed to close the order: %d! Error: %d (%s)", - _order REF_DEREF Get(ORDER_PROP_TICKET), - _order REF_DEREF Get(ORDER_PROP_LAST_ERROR), - Terminal::GetErrorText(_order REF_DEREF Get(ORDER_PROP_LAST_ERROR))), - __FUNCTION_LINE__); + logger.Error( + StringFormat("Failed to close the order: %d! Error: %d (%s)", + _order REF_DEREF Get(ORDER_PROP_TICKET), + _order REF_DEREF Get(ORDER_PROP_LAST_ERROR), + C_STR(Terminal::GetErrorText(_order REF_DEREF Get(ORDER_PROP_LAST_ERROR)))), + __FUNCTION_LINE__); continue; } } else { @@ -929,7 +931,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. StringFormat("Failed to close the order: %d! Error: %d (%s)", _order REF_DEREF Get(ORDER_PROP_TICKET), _order REF_DEREF Get(ORDER_PROP_LAST_ERROR), - Terminal::GetErrorText(_order REF_DEREF Get(ORDER_PROP_LAST_ERROR))), + C_STR(Terminal::GetErrorText(_order REF_DEREF Get(ORDER_PROP_LAST_ERROR)))), __FUNCTION_LINE__); continue; }