Skip to content

Commit

Permalink
Order: Adds argument for order close action
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Jul 28, 2023
1 parent d21ddf7 commit 891807e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions Order.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions Order.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Order.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 891807e

Please sign in to comment.