Skip to content

Commit

Permalink
Adds close retry counter (GH-703)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Aug 4, 2023
1 parent b43f990 commit bbe90f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions Order.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions Order.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -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<long>(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;
}
Expand Down
12 changes: 11 additions & 1 deletion Order.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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),
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -498,9 +502,15 @@ struct OrderData {
return "???";
}
// Setters.
void IncCloseTries() {
close_tries++;
}
template <typename T>
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;
Expand Down

0 comments on commit bbe90f0

Please sign in to comment.