diff --git a/Order.enum.h b/Order.enum.h index 04606c164..db1ecbc5a 100644 --- a/Order.enum.h +++ b/Order.enum.h @@ -93,6 +93,7 @@ enum ENUM_ORDER_PROPERTY_CUSTOM { 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 diff --git a/Order.mqh b/Order.mqh index 782f07419..cdbf20bc4 100644 --- a/Order.mqh +++ b/Order.mqh @@ -2603,12 +2603,11 @@ class Order : public SymbolInfo { bool ProcessConditions(bool _refresh = false) { bool _result = true; if (IsOpen(_refresh) && ShouldCloseOrder()) { - string _reason = "Close condition"; #ifdef __MQL__ // _reason += StringFormat(": %s", EnumToString(oparams.cond_close)); #endif ARRAY(DataParamEntry, _args); - DataParamEntry _cond = _reason; + DataParamEntry _cond = ORDER_REASON_CLOSED_BY_CONDITION; ArrayPushObject(_args, _cond); _result &= Order::ExecuteAction(ORDER_ACTION_CLOSE, _args); } @@ -2715,13 +2714,16 @@ class Order : public SymbolInfo { * Returns true when the condition is met. */ bool ExecuteAction(ENUM_ORDER_ACTION _action, ARRAY_REF(DataParamEntry, _args)) { + bool _result = true; switch (_action) { case ORDER_ACTION_CLOSE: switch (oparams.dummy) { case false: - return OrderClose(ORDER_REASON_CLOSED_BY_ACTION); + return ArraySize(_args) > 0 ? OrderClose((ENUM_ORDER_REASON_CLOSE)_args[0].integer_value) + : OrderClose(ORDER_REASON_CLOSED_BY_ACTION); case true: - return OrderCloseDummy(ORDER_REASON_CLOSED_BY_ACTION); + return ArraySize(_args) > 0 ? OrderCloseDummy((ENUM_ORDER_REASON_CLOSE)_args[0].integer_value) + : OrderCloseDummy(ORDER_REASON_CLOSED_BY_ACTION); } case ORDER_ACTION_OPEN: return !oparams.dummy ? OrderSend() >= 0 : OrderSendDummy() >= 0; @@ -2737,10 +2739,12 @@ class Order : public SymbolInfo { } oparams.AddConditionClose((ENUM_ORDER_CONDITION)_args[0].integer_value, _sargs); } + break; default: ologger.Error(StringFormat("Invalid order action: %s!", EnumToString(_action), __FUNCTION_LINE__)); return false; } + return _result; } bool ExecuteAction(ENUM_ORDER_ACTION _action) { ARRAY(DataParamEntry, _args); diff --git a/Order.struct.h b/Order.struct.h index 706e3686c..38b94e8ba 100644 --- a/Order.struct.h +++ b/Order.struct.h @@ -476,6 +476,8 @@ struct OrderData { return "CALL"; case ORDER_REASON_CLOSED_BY_ACTION: return "CBA"; + case ORDER_REASON_CLOSED_BY_CONDITION: + return "CBC"; case ORDER_REASON_CLOSED_BY_EXPIRE: return "EXP"; case ORDER_REASON_CLOSED_BY_OPPOSITE: