Skip to content

Commit

Permalink
EA: Reenables initial task logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Jan 23, 2022
1 parent 41d50e4 commit 61b201c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
24 changes: 20 additions & 4 deletions EA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,34 @@ class EA : public Taskable<DataParamEntry> {
TaskManager tasks;
TradeSignalManager tsm;

protected:
/* Protected methods */

/**
* Init code (called on constructor).
*/
void Init() { InitTask(); }

/**
* Process initial task (called on constructor).
*/
void InitTask() {
// Add and process init task.
TaskObject<EA, EA> _taskobj_init(eparams.GetStruct<TaskEntry>(STRUCT_ENUM(EAParams, EA_PARAM_STRUCT_TASK_ENTRY)));
estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_ON_INIT), true);
_taskobj_init.Process();
estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_ON_INIT), false);
}

public:
/**
* Class constructor.
*/
EA(EAParams &_params) : account(new Account) {
eparams = _params;
estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_ON_INIT), true);
UpdateStateFlags();
// Add and process tasks.
AddTask(eparams.GetStruct<TaskEntry>(STRUCT_ENUM(EAParams, EA_PARAM_STRUCT_TASK_ENTRY)));
ProcessTasks();
estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_ON_INIT), false);
Init();
// Initialize a trade instance for the current chart and symbol.
ChartParams _cparams((ENUM_TIMEFRAMES)_Period, _Symbol);
TradeParams _tparams;
Expand Down
2 changes: 1 addition & 1 deletion EA.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct EAParams {
ver = _ver;
author = _author;
}
// void SetTaskEntry(TaskEntry &_task_entry) { task_init = _task_entry; }
void SetTaskEntry(TaskEntry &_task_entry) { task_init = _task_entry; }
// Printers.
string ToString(string _dlm = ",") { return StringFormat("%s v%s by %s (%s)", name, ver, author, desc); }
};
Expand Down
6 changes: 3 additions & 3 deletions tests/EATest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int OnInit() {
// Exporting to all possible formats once per hour.
ea_params.Set(STRUCT_ENUM(EAParams, EA_PARAM_PROP_DATA_STORE), EA_DATA_STORE_ALL);
ea_params.Set(STRUCT_ENUM(EAParams, EA_PARAM_PROP_DATA_EXPORT), EA_DATA_EXPORT_ALL);
//ea_params.SetTaskEntry(_task_export_per_hour);
ea_params.SetTaskEntry(_task_export_per_hour);
ea = new EA(ea_params);
assertTrueOrFail(ea.Get<string>(STRUCT_ENUM(EAParams, EA_PARAM_PROP_NAME)) == "EA",
StringFormat("Invalid EA name: %s!", ea.Get<string>(STRUCT_ENUM(EAParams, EA_PARAM_PROP_NAME))));
Expand All @@ -69,7 +69,7 @@ int OnInit() {
// Exporting to all possible formats once per hour.
ea_params1.Set(STRUCT_ENUM(EAParams, EA_PARAM_PROP_DATA_STORE), EA_DATA_STORE_ALL);
ea_params1.Set(STRUCT_ENUM(EAParams, EA_PARAM_PROP_DATA_EXPORT), EA_DATA_EXPORT_ALL);
//ea_params1.SetTaskEntry(_task_export_per_hour);
ea_params1.SetTaskEntry(_task_export_per_hour);
ea1 = new EA1(ea_params1);
assertTrueOrFail(ea1.Get<string>(STRUCT_ENUM(EAParams, EA_PARAM_PROP_NAME)) == "EA1", "Invalid EA1 name!");

Expand All @@ -78,7 +78,7 @@ int OnInit() {
// Exporting to all possible formats once per hour.
ea_params2.Set(STRUCT_ENUM(EAParams, EA_PARAM_PROP_DATA_STORE), EA_DATA_STORE_ALL);
ea_params2.Set(STRUCT_ENUM(EAParams, EA_PARAM_PROP_DATA_EXPORT), EA_DATA_EXPORT_ALL);
//ea_params2.SetTaskEntry(_task_export_per_hour);
ea_params2.SetTaskEntry(_task_export_per_hour);
ea2 = new EA2(ea_params2);
assertTrueOrFail(ea2.Get<string>(STRUCT_ENUM(EAParams, EA_PARAM_PROP_NAME)) == "EA2", "Invalid EA2 name!");

Expand Down

0 comments on commit 61b201c

Please sign in to comment.