-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathAction.struct.h
120 lines (111 loc) · 4.56 KB
/
Action.struct.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+
/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* Includes Action's structs.
*/
#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif
// Includes.
#include "Account.enum.h"
#include "Action.enum.h"
#include "Chart.enum.h"
#include "Data.struct.h"
#include "EA.enum.h"
#include "Indicator.enum.h"
//#include "Market.enum.h"
#include "Order.enum.h"
#include "Serializer.mqh"
#include "Strategy.enum.h"
#include "Task.enum.h"
#include "Trade.enum.h"
/* Entry for Action class. */
struct ActionEntry {
unsigned char flags; /* Action flags. */
datetime last_success; /* Time of the previous check. */
int frequency; /* How often to check. */
long action_id; /* Action ID. */
short tries; /* Number of retries left. */
void *obj; /* Reference to associated object. */
ENUM_ACTION_TYPE type; /* Action type. */
DataParamEntry args[]; /* Action arguments. */
// Constructors.
ActionEntry() : type(FINAL_ACTION_TYPE_ENTRY), action_id(WRONG_VALUE) { Init(); }
ActionEntry(long _action_id, ENUM_ACTION_TYPE _type) : type(_type), action_id(_action_id) { Init(); }
ActionEntry(ActionEntry &_ae) { this = _ae; }
ActionEntry(ENUM_EA_ACTION _action_id) : type(ACTION_TYPE_EA), action_id(_action_id) { Init(); }
ActionEntry(ENUM_ORDER_ACTION _action_id) : type(ACTION_TYPE_ORDER), action_id(_action_id) { Init(); }
ActionEntry(ENUM_INDICATOR_ACTION _action_id) : type(ACTION_TYPE_INDICATOR), action_id(_action_id) { Init(); }
ActionEntry(ENUM_STRATEGY_ACTION _action_id) : type(ACTION_TYPE_STRATEGY), action_id(_action_id) { Init(); }
ActionEntry(ENUM_TASK_ACTION _action_id) : type(ACTION_TYPE_TASK), action_id(_action_id) { Init(); }
ActionEntry(ENUM_TRADE_ACTION _action_id) : type(ACTION_TYPE_TRADE), action_id(_action_id) { Init(); }
// Deconstructor.
~ActionEntry() {
// Object::Delete(obj);
}
// Flag methods.
bool HasFlag(unsigned char _flag) { return bool(flags & _flag); }
void AddFlags(unsigned char _flags) { flags |= _flags; }
void RemoveFlags(unsigned char _flags) { flags &= ~_flags; }
void SetFlag(ENUM_ACTION_ENTRY_FLAGS _flag, bool _value) {
if (_value)
AddFlags(_flag);
else
RemoveFlags(_flag);
}
void SetFlags(unsigned char _flags) { flags = _flags; }
// State methods.
bool IsActive() { return HasFlag(ACTION_ENTRY_FLAG_IS_ACTIVE); }
bool IsDone() { return HasFlag(ACTION_ENTRY_FLAG_IS_DONE); }
bool IsFailed() { return HasFlag(ACTION_ENTRY_FLAG_IS_FAILED); }
bool IsInvalid() { return HasFlag(ACTION_ENTRY_FLAG_IS_INVALID); }
bool IsValid() { return !IsInvalid(); }
// Getters.
long GetId() { return action_id; }
ENUM_ACTION_TYPE GetType() { return type; }
// Setter methods.
void AddArg(MqlParam &_arg) {
// @todo: Add another value to args[].
}
void Init() {
flags = ACTION_ENTRY_FLAG_NONE;
frequency = 60;
SetFlag(ACTION_ENTRY_FLAG_IS_ACTIVE, action_id != WRONG_VALUE);
SetFlag(ACTION_ENTRY_FLAG_IS_INVALID, action_id == WRONG_VALUE);
last_success = 0;
tries = 1;
}
void SetArgs(ARRAY_REF(MqlParam, _args)) {
// @todo: for().
}
void SetObject(void *_obj) { obj = _obj; }
void SetTries(short _count) { tries = _count; }
SerializerNodeType Serialize(Serializer &s) {
s.Pass(THIS_REF, "flags", flags);
s.Pass(THIS_REF, "last_success", last_success);
s.Pass(THIS_REF, "action_id", action_id);
// s.Pass(THIS_REF, "tries", tries);
s.PassEnum(THIS_REF, "type", type);
s.PassEnum(THIS_REF, "frequency", frequency);
s.PassArray(this, "args", args);
return SerializerNodeObject;
}
SERIALIZER_EMPTY_STUB;
};