From bbe90f026f5de8fe6a7b76124f1d4235b6a5b90f Mon Sep 17 00:00:00 2001 From: kenorb Date: Fri, 4 Aug 2023 19:36:40 +0100 Subject: [PATCH] Adds close retry counter (GH-703) --- Order.enum.h | 1 + Order.mqh | 6 ++---- Order.struct.h | 12 +++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Order.enum.h b/Order.enum.h index db1ecbc5a..00f009f17 100644 --- a/Order.enum.h +++ b/Order.enum.h @@ -71,6 +71,7 @@ enum ENUM_ORDER_PARAM { */ enum ENUM_ORDER_PROPERTY_CUSTOM { ORDER_PROP_NONE = 0, + ORDER_PROP_CLOSE_TRIES, // Close tries. ORDER_PROP_COMMISSION, // Commission. ORDER_PROP_LAST_ERROR, // Last error code. ORDER_PROP_PRICE_CLOSE, // Close price. diff --git a/Order.mqh b/Order.mqh index 10c994441..47e7eef09 100644 --- a/Order.mqh +++ b/Order.mqh @@ -2606,14 +2606,12 @@ class Order : public SymbolInfo { */ bool ProcessConditions(bool _refresh = false) { bool _result = true; - if (IsOpen(_refresh) && ShouldCloseOrder()) { -#ifdef __MQL__ - // _reason += StringFormat(": %s", EnumToString(oparams.cond_close)); -#endif + if (IsOpen(_refresh) && (odata.Get(ORDER_PROP_CLOSE_TRIES) > 0 || ShouldCloseOrder())) { ARRAY(DataParamEntry, _args); DataParamEntry _cond = ORDER_REASON_CLOSED_BY_CONDITION; ArrayPushObject(_args, _cond); _result &= Order::ExecuteAction(ORDER_ACTION_CLOSE, _args); + odata.IncCloseTries(); } return _result; } diff --git a/Order.struct.h b/Order.struct.h index 38b94e8ba..d295b370f 100644 --- a/Order.struct.h +++ b/Order.struct.h @@ -254,6 +254,7 @@ struct OrderData { ENUM_ORDER_TYPE_TIME type_time; // Lifetime (the order validity period). ENUM_ORDER_REASON reason; // Reason or source for placing an order. ENUM_ORDER_REASON_CLOSE reason_close; // Reason or source for closing an order. + unsigned int close_tries; // Number of close tries. unsigned int last_error; // Last error code. double volume_curr; // Current volume. double volume_init; // Initial volume. @@ -262,7 +263,8 @@ struct OrderData { string symbol; // Symbol of the order. public: OrderData() - : magic(0), + : close_tries(0), + magic(0), position_id(0), position_by_id(0), ticket(0), @@ -296,6 +298,8 @@ struct OrderData { T Get(ENUM_ORDER_PROPERTY_CUSTOM _prop_name) { double _tick_value = SymbolInfoStatic::GetTickValue(symbol); switch (_prop_name) { + case ORDER_PROP_CLOSE_TRIES: + return (T)close_tries; case ORDER_PROP_COMMISSION: return (T)commission; case ORDER_PROP_LAST_ERROR: @@ -498,9 +502,15 @@ struct OrderData { return "???"; } // Setters. + void IncCloseTries() { + close_tries++; + } template void Set(ENUM_ORDER_PROPERTY_CUSTOM _prop_name, T _value) { switch (_prop_name) { + case ORDER_PROP_CLOSE_TRIES: + close_tries = (unsigned int)_value; + return; case ORDER_PROP_COMMISSION: commission = (double)_value; return;