Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indicators refactor (part 3) #634

Merged
merged 41 commits into from
Jan 19, 2022
Merged
Changes from 5 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6b147ae
Adds TickManager
kenorb Oct 28, 2021
95f05ac
Tick/TickManager: Adds TickManagerOverflowListener()
kenorb Oct 29, 2021
484bd82
Fixed Dicts to take into consideration overflow listeners.
nseam Nov 8, 2021
1f2902c
GHA: Adds Tick tests
kenorb Nov 8, 2021
5a9836c
Merge tag 'v2.009' into dev-tickmanager
kenorb Nov 9, 2021
3b2045d
Chart: ChartTf: Adds SecsToTf()
kenorb Oct 28, 2021
182f79f
Indi_AC: Sets 2 modes when using iCustom()
kenorb Nov 9, 2021
f60a9fc
Indicator: Moves Init() to protected section
kenorb Nov 9, 2021
c508d52
Fixes problem with non-visual mode 4086 errors due to BarsCalculated(…
nseam Nov 12, 2021
b85e815
GHA: Uses 4.0.0.1349 to run main tests
kenorb Dec 5, 2021
fee7085
GHA: Uses 4.0.0.1349 to compile main tests
kenorb Dec 5, 2021
43829c3
GHA: Removes init-platform due to hang
kenorb Dec 5, 2021
61b6c16
Merge pull request #617 from EA31337/dev-tickmanager
kenorb Dec 5, 2021
9603dc3
WIP. i*OnIndicator versions of all indicators (except MA).
nseam Dec 7, 2021
1aa8db9
Fixed Dicts to take into consideration overflow listeners.
nseam Nov 8, 2021
66d435a
Merge pull request #622 from EA31337/dev
kenorb Dec 9, 2021
a493f36
WIP. Finished i*OnIndicator mode for all indicators except MA. Change…
nseam Dec 9, 2021
f4c946d
WIP. AMA now requires refactor back to be parent of Indicator or some…
nseam Dec 11, 2021
761face
WIP. Introduces IndicatorCandleSource and IndicatorTickSource indicat…
nseam Dec 15, 2021
fea144a
WIP. Almost working AMA indicator (still varies to much with original…
nseam Dec 16, 2021
0e14527
WIP. Partially working Tick/Candle/TickOrCandle indicators differenti…
nseam Dec 22, 2021
c5be80f
WIP. Closer to the end. Now we need to find a way to feed indicator w…
nseam Dec 29, 2021
08c6062
Indi_MA: Renames InpMAPeriod to _ma_period to avoid global variable c…
kenorb Dec 29, 2021
506d08e
Indi_MA: Renames InpMAMethod to _ma_method to avoid global variable c…
kenorb Dec 29, 2021
88d0a7c
WIP. Now we need to find a way to make BufferTick to provide continuo…
nseam Dec 30, 2021
c2a87cd
AS-IS.
nseam Jan 4, 2022
435f1d1
WIP. IndicatorsTest ready for testing!
nseam Jan 5, 2022
a7f3334
Adds Indi_Custom indicator
kenorb Jan 5, 2022
c6bc378
Merge branch 'dev' of https://github.com/EA31337/EA31337-classes into…
nseam Jan 6, 2022
58f94f9
Fixed bug with IndicatorBase::GetValue() which called GetEntryValue()…
nseam Jan 7, 2022
d1c927b
EA: Adds enum's comment
kenorb Jan 8, 2022
a47681b
Merge branch 'dev-indi-custom' into dev
kenorb Jan 8, 2022
d93deb8
Improves tasks return logic
kenorb Jan 8, 2022
2640ceb
Merge branch 'dev' of https://github.com/EA31337/EA31337-classes into…
nseam Jan 12, 2022
e950493
State of the art
nseam Jan 12, 2022
078af3a
Looks like there is nothing more to do with AMA. Differences are marg…
nseam Jan 13, 2022
8e39201
Fixed order of mode and shift when calling Indicator::GetValue<T>(). …
nseam Jan 18, 2022
71108dc
Fixed typo in auxiliary indicator fetching by ID.
nseam Jan 18, 2022
a469c5e
Merge branch 'dev-indicator-refactor' of https://github.com/EA31337/E…
nseam Jan 18, 2022
6ee889c
Fixes EOL characters
kenorb Jan 18, 2022
74eb036
IndicatorsTest was set to test only AMA or Pattern indicator. Now it …
nseam Jan 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/test-indicators-special.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: Test Indicators (Special)

# yamllint disable-line rule:truthy
on:
pull_request:
paths:
- 'Indicator**'
- 'Indicators/Special/**'
- '.github/workflows/test-indicators-special.yml'
push:
paths:
- 'Indicator**'
- 'Indicators/Special/**'
- '.github/workflows/test-indicators-special.yml'

jobs:

Compile:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Compile
uses: fx31337/mql-compile-action@master
with:
init-platform: true
path: 'Indicators/Special/tests'
verbose: true
- name: Print compiled files
run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname'
shell: powershell
- name: Upload artifacts (MQL4)
uses: actions/upload-artifact@v2
with:
name: files-ex4
path: '**/*.ex4'
- name: Upload artifacts (MQL5)
uses: actions/upload-artifact@v2
with:
name: files-ex5
path: '**/*.ex5'

Indicators-Tests-MQL4:
defaults:
run:
shell: bash
working-directory: Indicators/tests
needs: Compile
runs-on: ubuntu-latest
strategy:
matrix:
test:
- Indi_Custom.test
steps:
- uses: actions/download-artifact@v2
with:
name: files-ex4
- name: Run ${{ matrix.test }}
uses: fx31337/mql-tester-action@master
with:
BtDays: 4-8
BtMonths: 1
BtYears: 2020
TestExpert: ${{ matrix.test }}
timeout-minutes: 10
8 changes: 5 additions & 3 deletions Action.mqh
Original file line number Diff line number Diff line change
@@ -303,6 +303,7 @@ class Action {
* Returns true when the condition is met.
*/
bool CheckCondition(ENUM_ACTION_CONDITION _cond, DataParamEntry &_args[]) {
bool _result = false;
switch (_cond) {
case ACTION_COND_IS_ACTIVE:
// Is active;
@@ -321,8 +322,9 @@ class Action {
return IsInvalid();
default:
logger.Ptr().Error(StringFormat("Invalid Action condition: %s!", EnumToString(_cond), __FUNCTION_LINE__));
return false;
break;
}
return _result;
}
bool CheckCondition(ENUM_ACTION_CONDITION _cond) {
ARRAY(DataParamEntry, _args);
@@ -338,7 +340,7 @@ class Action {
* Returns true when the action has been executed successfully.
*/
bool ExecuteAction(ENUM_ACTION_ACTION _action, DataParamEntry &_args[]) {
bool _result = true;
bool _result = false;
switch (_action) {
case ACTION_ACTION_DISABLE:
// Disable action.
@@ -360,7 +362,7 @@ class Action {
return SetFlags(ACTION_ENTRY_FLAG_IS_INVALID);
default:
logger.Ptr().Error(StringFormat("Invalid action of action: %s!", EnumToString(_action), __FUNCTION_LINE__));
return false;
break;
}
return _result;
}
10 changes: 5 additions & 5 deletions EA.enum.h
Original file line number Diff line number Diff line change
@@ -43,11 +43,11 @@ enum ENUM_EA_DATA_STORE_TYPE {

/* Defines EA data export methods. */
enum ENUM_EA_DATA_EXPORT_METHOD {
EA_DATA_EXPORT_NONE = 0 << 0,
EA_DATA_EXPORT_CSV = 1 << 0, // Export into CSV file.
EA_DATA_EXPORT_DB = 1 << 1, // Export into database table.
EA_DATA_EXPORT_JSON = 1 << 2, // Export into JSON file.
EA_DATA_EXPORT_ALL = (1 << 3) - 1, // Export in all formats.
EA_DATA_EXPORT_NONE = 0 << 0, // (None)
EA_DATA_EXPORT_CSV = 1 << 0, // CSV file
EA_DATA_EXPORT_DB = 1 << 1, // Database (SQLite)
EA_DATA_EXPORT_JSON = 1 << 2, // JSON file
EA_DATA_EXPORT_ALL = (1 << 3) - 1, // All
};

/* Defines EA state flags. */
6 changes: 4 additions & 2 deletions EA.mqh
Original file line number Diff line number Diff line change
@@ -880,6 +880,7 @@ class EA {
* Returns true when the condition is met.
*/
bool CheckCondition(ENUM_EA_CONDITION _cond, DataParamEntry &_args[]) {
bool _result = false;
switch (_cond) {
case EA_COND_IS_ACTIVE:
return estate.IsActive();
@@ -906,8 +907,9 @@ class EA {
return estate.IsOnQuit();
default:
logger.Error(StringFormat("Invalid EA condition: %s!", EnumToString(_cond), __FUNCTION_LINE__));
return false;
break;
}
return _result;
}
bool CheckCondition(ENUM_EA_CONDITION _cond) {
ARRAY(DataParamEntry, _args);
@@ -923,7 +925,7 @@ class EA {
* Returns true when the action has been executed successfully.
*/
bool ExecuteAction(ENUM_EA_ACTION _action, DataParamEntry &_args[]) {
bool _result = true;
bool _result = false;
long arg_size = ArraySize(_args);
switch (_action) {
case EA_ACTION_DISABLE:
118 changes: 118 additions & 0 deletions Indicators/Special/Indi_Custom.mqh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//+------------------------------------------------------------------+
//| Copyright 2016-2022, 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/>.
*
*/

// Prevents processing the same indicator file twice.
#ifndef INDI_CUSTOM_MQH
#define INDI_CUSTOM_MQH

// Defines
#ifndef INDI_CUSTOM_PATH
#ifdef __MQL4__
#define INDI_CUSTOM_PATH "RSI"
#else
#define INDI_CUSTOM_PATH "Examples\\RSI"
#endif
#endif

// Includes.
#include "../../Indicator.mqh"

// Structs.

// Defines struct to store indicator parameter values.
struct IndiCustomParams : public IndicatorParams {
DataParamEntry iargs[];
// Struct constructors.
IndiCustomParams(string _filepath = INDI_CUSTOM_PATH, int _shift = 0) : IndicatorParams(INDI_CUSTOM, 1, TYPE_DOUBLE) {
custom_indi_name = _filepath;
SetDataSourceType(IDATA_ICUSTOM);
}
IndiCustomParams(IndiCustomParams &_params, ENUM_TIMEFRAMES _tf) {
THIS_REF = _params;
tf = _tf;
}
// Getters.
DataParamEntry GetParam(int _index) const { return iargs[_index - 1]; }
int GetParamsSize() const { return ArraySize(iargs); }
// Setters.
void AddParam(DataParamEntry &_entry) {
int _size = GetParamsSize();
ArrayResize(iargs, _size + 1);
iargs[_size] = _entry;
}
void SetParam(DataParamEntry &_entry, int _index) {
if (_index >= GetParamsSize()) {
ArrayResize(iargs, _index + 1);
}
iargs[_index + 1] = _entry;
}
void SetParams(DataParamEntry &_entries[]) {
for (int i = 0; i < ArraySize(_entries); i++) {
iargs[i] = _entries[i];
}
}
};

/**
* Implements indicator class.
*/
class Indi_Custom : public Indicator<IndiCustomParams> {
public:
/**
* Class constructor.
*/
Indi_Custom(IndiCustomParams &_p, IndicatorBase *_indi_src = NULL) : Indicator<IndiCustomParams>(_p, _indi_src) {}
Indi_Custom(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CUSTOM, _tf){};

/**
* Returns the indicator's value.
*/
IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = -1) {
double _value = EMPTY_VALUE;
int _ishift = _shift >= 0 ? _shift : iparams.GetShift();
switch (iparams.idstype) {
case IDATA_ICUSTOM:
switch (iparams.GetParamsSize()) {
case 0:
_value = iCustom(istate.handle, Get<string>(CHART_PARAM_SYMBOL), Get<ENUM_TIMEFRAMES>(CHART_PARAM_TF),
iparams.custom_indi_name, _mode, _ishift);
break;
case 1:
_value = iCustom(istate.handle, Get<string>(CHART_PARAM_SYMBOL), Get<ENUM_TIMEFRAMES>(CHART_PARAM_TF),
iparams.custom_indi_name, iparams.GetParam(1).ToValue<double>(), _mode, _ishift);
break;
case 2:
_value = iCustom(istate.handle, Get<string>(CHART_PARAM_SYMBOL), Get<ENUM_TIMEFRAMES>(CHART_PARAM_TF),
iparams.custom_indi_name, iparams.GetParam(1).ToValue<double>(),
iparams.GetParam(2).ToValue<double>(), _mode, _ishift);
break;
}
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
_value = EMPTY_VALUE;
break;
}
return _value;
}
};

#endif // INDI_CUSTOM_MQH
1 change: 1 addition & 0 deletions Indicators/Special/indicators.h
Original file line number Diff line number Diff line change
@@ -26,4 +26,5 @@
*/

// Special indicators.
#include "Indi_Custom.mqh"
#include "Indi_Math.mqh"
27 changes: 27 additions & 0 deletions Indicators/Special/tests/Indi_Custom.test.mq4
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2022, 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
* Test functionality of Indi_Custom indicator class.
*/

#include "Indi_Custom.test.mq5"
65 changes: 65 additions & 0 deletions Indicators/Special/tests/Indi_Custom.test.mq5
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2022, 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/>.
*/

// Includes.
#include "../../../Test.mqh"
#include "../Indi_Custom.mqh"

/**
* @file
* Test functionality of Indi_Custom indicator class.
*/

Indi_Custom indi(PERIOD_CURRENT);

/**
* Implements Init event handler.
*/
int OnInit() {
bool _result = true;
assertTrueOrFail(indi.IsValid(), "Error on IsValid!");
// assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!");
// Overrides indicator params.
DataParamEntry _iparam_rsi_period = 12;
IndiCustomParams _iparams(INDI_CUSTOM_PATH);
_iparams.AddParam(_iparam_rsi_period);
indi.SetParams(_iparams);
return (_result && _LastError == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED);
}

/**
* Implements Tick event handler.
*/
void OnTick() {
static MqlTick _tick_last;
MqlTick _tick_new = SymbolInfoStatic::GetTick(_Symbol);
if (_tick_new.time % 60 < _tick_last.time % 60) {
// Process ticks each minute.
if (_tick_new.time % 3600 < _tick_last.time % 3600) {
// Print indicator values every hour.
Print(indi.ToString());
if (indi.Get<bool>(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY))) {
assertTrueOrExit(indi.GetEntry().IsValid(), "Invalid entry!");
}
}
}
_tick_last = _tick_new;
}
Loading