From 9df418f1c3f05533aebf1f16f041b812d29db42f Mon Sep 17 00:00:00 2001 From: kenorb Date: Wed, 8 Sep 2021 22:56:18 +0100 Subject: [PATCH 01/78] Strategy: Moves indicator references from struct to the class --- EA.mqh | 2 +- Strategy.mqh | 33 ++++++++++++++++++++++++++++++--- Strategy.struct.h | 28 ---------------------------- tests/StrategyTest-RSI.mq5 | 2 +- tests/StrategyTest.mq5 | 2 +- 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/EA.mqh b/EA.mqh index f9c1ac9f1..2a6a012d0 100644 --- a/EA.mqh +++ b/EA.mqh @@ -363,7 +363,7 @@ class EA { if (eparams.CheckFlagDataStore(EA_DATA_STORE_INDICATOR)) { for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { Strategy *_strati = iter.Value().Ptr(); - Indicator *_indi = _strati.GetParams().GetIndicator(); + Indicator *_indi = _strati.GetIndicator(); if (_indi != NULL) { ENUM_TIMEFRAMES _itf = _indi.GetParams().tf.GetTf(); IndicatorDataEntry _ientry = _indi.GetEntry(); diff --git a/Strategy.mqh b/Strategy.mqh index c9b94f297..11ad9aea2 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -93,6 +93,8 @@ class Strategy : public Object { Dict ddata; Dict fdata; Dict idata; + Dict indicators_unmanaged; // Indicators list (unmanaged). + DictStruct> indicators_managed; // Indicators list (managed). DictStruct tasks; Log logger; // Log instance. MqlTick last_tick; @@ -156,7 +158,11 @@ class Strategy : public Object { /** * Class deconstructor. */ - ~Strategy() { sparams.DeleteObjects(); } + ~Strategy() { + for (DictIterator iter = indicators_unmanaged.Begin(); iter.IsValid(); ++iter) { + delete iter.Value(); + } + } /* Processing methods */ @@ -355,12 +361,21 @@ class Strategy : public Object { /** * Returns handler to the strategy's indicator class. */ - Indicator *GetIndicator(int _id = 0) { return sparams.GetIndicator(_id); } + Indicator *GetIndicator(int _id = 0) { + if (indicators_managed.KeyExists(_id)) { + return indicators_managed[_id].Ptr(); + } else if (indicators_unmanaged.KeyExists(_id)) { + return indicators_unmanaged[_id]; + } + + Alert("Missing indicator id ", _id); + return NULL; + } /** * Returns strategy's indicators. */ - DictStruct> GetIndicators() { return sparams.indicators_managed; } + DictStruct> GetIndicators() { return indicators_managed; } /* Struct getters */ @@ -612,6 +627,18 @@ class Strategy : public Object { void SetData(Dict *_fdata) { fdata = _fdata; } void SetData(Dict *_idata) { idata = _idata; } + /** + * Sets reference to indicator. + */ + void SetIndicator(Indicator *_indi, int _id = 0, bool _managed = true) { + if (_managed) { + Ref _ref = _indi; + indicators_managed.Set(_id, _ref); + } else { + indicators_unmanaged.Set(_id, _indi); + } + } + /* Static setters */ /** diff --git a/Strategy.struct.h b/Strategy.struct.h index 3c41b81d6..482822bbd 100644 --- a/Strategy.struct.h +++ b/Strategy.struct.h @@ -37,7 +37,6 @@ #include "Task.struct.h" // Forward class declaration. -class Indicator; class Strategy; class Trade; @@ -76,8 +75,6 @@ struct StgParams { datetime refresh_time; // Order refresh frequency (in sec). short shift; // Shift (relative to the current bar, 0 - default) ChartTf tf; // Main timeframe where strategy operates on. - DictStruct> indicators_managed; // Indicators list keyed by id. - Dict indicators_unmanaged; // Indicators list keyed by id. // Constructor. StgParams() : id(rand()), @@ -142,7 +139,6 @@ struct StgParams { type(0), refresh_time(0) {} StgParams(StgParams &_stg_params) { - DeleteObjects(); this = _stg_params; } // Deconstructor. @@ -206,20 +202,9 @@ struct StgParams { SetUserError(ERR_INVALID_PARAMETER); return WRONG_VALUE; } - bool HasIndicator(int _id = 0) { return GetIndicator(_id) != NULL; } bool IsBoosted() { return is_boosted; } bool IsEnabled() { return is_enabled; } bool IsSuspended() { return is_suspended; } - Indicator *GetIndicator(int _id = 0) { - if (indicators_managed.KeyExists(_id)) { - return indicators_managed[_id].Ptr(); - } else if (indicators_unmanaged.KeyExists(_id)) { - return indicators_unmanaged[_id]; - } - - Alert("Missing indicator id ", _id); - return NULL; - } // Setters. template void Set(ENUM_STRATEGY_PARAM _param, T _value) { @@ -312,14 +297,6 @@ struct StgParams { } } void SetId(long _id) { id = _id; } - void SetIndicator(Indicator *_indi, int _id = 0, bool _managed = true) { - if (_managed) { - Ref _ref = _indi; - indicators_managed.Set(_id, _ref); - } else { - indicators_unmanaged.Set(_id, _indi); - } - } void SetStops(Strategy *_sl = NULL, Strategy *_tp = NULL) { // @todo: To remove. } @@ -334,11 +311,6 @@ struct StgParams { void Enabled(bool _is_enabled) { is_enabled = _is_enabled; }; void Suspended(bool _is_suspended) { is_suspended = _is_suspended; }; void Boost(bool _is_boosted) { is_boosted = _is_boosted; }; - void DeleteObjects() { - for (DictIterator iter = indicators_unmanaged.Begin(); iter.IsValid(); ++iter) { - delete iter.Value(); - } - } // Printers. string ToString() { // SerializerConverter _stub = SerializerConverter::MakeStubObject(SERIALIZER_FLAG_SKIP_HIDDEN); diff --git a/tests/StrategyTest-RSI.mq5 b/tests/StrategyTest-RSI.mq5 index f673fed95..5b8d87639 100644 --- a/tests/StrategyTest-RSI.mq5 +++ b/tests/StrategyTest-RSI.mq5 @@ -41,8 +41,8 @@ class Stg_RSI : public Strategy { RSIParams _indi_params(12, PRICE_OPEN, 0); StgParams _stg_params; TradeParams _tparams; - _stg_params.SetIndicator(new Indi_RSI(_indi_params)); Strategy *_strat = new Stg_RSI(_stg_params, _tparams, _cparams, "RSI"); + _strat.SetIndicator(new Indi_RSI(_indi_params)); return _strat; } diff --git a/tests/StrategyTest.mq5 b/tests/StrategyTest.mq5 index 5282c63a3..d0c6efa10 100644 --- a/tests/StrategyTest.mq5 +++ b/tests/StrategyTest.mq5 @@ -112,8 +112,8 @@ int OnInit() { StgParams stg2_params; stg2_params.Enabled(false); stg2_params.Suspended(true); - stg2_params.SetIndicator(new Indi_Demo(iparams)); strat2 = new Stg2(stg2_params); + strat2.SetIndicator(new Indi_Demo(iparams)); strat2.SetName("Stg2"); assertTrueOrFail(strat2.GetName() == "Stg2", "Invalid Strategy name!"); assertTrueOrFail(strat2.IsValid(), "Fail on IsValid()!"); From bdd0c5c71569fd813b04ad2193de98e15bf939da Mon Sep 17 00:00:00 2001 From: kenorb Date: Wed, 15 Sep 2021 21:51:28 +0100 Subject: [PATCH 02/78] Adds Indi_Killzones --- .github/workflows/test.yml | 1 + Indicator.enum.h | 2 + Indicators/Indi_Killzones.mqh | 202 +++++++++++++++++++++++ Indicators/tests/Indi_Killzones.test.mq4 | 27 +++ Indicators/tests/Indi_Killzones.test.mq5 | 57 +++++++ 5 files changed, 289 insertions(+) create mode 100644 Indicators/Indi_Killzones.mqh create mode 100644 Indicators/tests/Indi_Killzones.test.mq4 create mode 100644 Indicators/tests/Indi_Killzones.test.mq5 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80d1459a8..05ded02b8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -101,6 +101,7 @@ jobs: matrix: test: - Indi_Pivot.test + - Indi_Killzones.test steps: - uses: actions/download-artifact@v2 with: diff --git a/Indicator.enum.h b/Indicator.enum.h index 9214dc8fd..04fe32011 100644 --- a/Indicator.enum.h +++ b/Indicator.enum.h @@ -82,6 +82,7 @@ enum ENUM_INDICATOR_TYPE { INDI_GATOR, // Gator Oscillator INDI_HEIKENASHI, // Heiken Ashi INDI_ICHIMOKU, // Ichimoku Kinko Hyo + INDI_KILLZONES, // Killzones INDI_MA, // Moving Average INDI_MACD, // MACD INDI_MA_ON_PRICE, // Moving Average (on Price). @@ -128,6 +129,7 @@ enum ENUM_INDICATOR_TYPE { /* Defines type of source data for indicator. */ enum ENUM_IDATA_SOURCE_TYPE { IDATA_BUILTIN, // Platform built-in + IDATA_CHART, // Chart calculation IDATA_ICUSTOM, // iCustom: Custom indicator file IDATA_INDICATOR, // OnIndicator: Another indicator as a source of data IDATA_MATH // Math-based indicator diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh new file mode 100644 index 000000000..9ee93093a --- /dev/null +++ b/Indicators/Indi_Killzones.mqh @@ -0,0 +1,202 @@ +//+------------------------------------------------------------------+ +//| 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 . + * + */ + +// Includes. +#include "../Indicator.mqh" +#include "../Market.struct.h" + +// Defines enumerations. +enum ENUM_INDI_KILLZONES_MODE { + INDI_KILLZONES_MODE_CHICAGO_HIGH = 0, + INDI_KILLZONES_MODE_CHICAGO_LOW, + INDI_KILLZONES_MODE_FRANKFURT_HIGH, + INDI_KILLZONES_MODE_FRANKFURT_LOW, + INDI_KILLZONES_MODE_HONGKONG_HIGH, + INDI_KILLZONES_MODE_HONGKONG_LOW, + INDI_KILLZONES_MODE_LONDON_HIGH, + INDI_KILLZONES_MODE_LONDON_LOW, + INDI_KILLZONES_MODE_NEWYORK_HIGH, + INDI_KILLZONES_MODE_NEWYORK_LOW, + INDI_KILLZONES_MODE_SYDNEY_HIGH, + INDI_KILLZONES_MODE_SYDNEY_LOW, + INDI_KILLZONES_MODE_TOKYO_HIGH, + INDI_KILLZONES_MODE_TOKYO_LOW, + INDI_KILLZONES_MODE_WELLINGTON_HIGH, + INDI_KILLZONES_MODE_WELLINGTON_LOW, + FINAL_INDI_KILLZONES_MODE_ENTRY, +}; + +// Defines structs. +struct IndiKillzonesParams : IndicatorParams { + ENUM_PP_TYPE method; // Pivot point calculation method. + // Struct constructor. + void IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + itype = INDI_PIVOT; + max_modes = FINAL_INDI_KILLZONES_MODE_ENTRY; + SetDataValueType(TYPE_FLOAT); + SetDataValueRange(IDATA_RANGE_MIXED); + SetDataSourceType(IDATA_CHART); + SetShift(_shift); + tf = _tf; + }; + void IndiKillzonesParams(IndiKillzonesParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _params; + tf = _tf; + }; +}; + +struct Indi_Killzones_Time : MarketTimeForex { + float highs[FINAL_INDI_KILLZONES_MODE_ENTRY / 2], lows[FINAL_INDI_KILLZONES_MODE_ENTRY / 2]; + datetime reset_last; + Indi_Killzones_Time() : reset_last(0), MarketTimeForex(::TimeGMT()) { + ArrayFill(highs, 0, ArraySize(highs), 0.0f); + ArrayFill(lows, 0, ArraySize(lows), 0.0f); + } + bool CheckHours(int _index) { + bool _result = MarketTimeForex::CheckHours(1 << _index); + if (!_result) { + Reset(_index); + } + return _result; + } + float GetHigh(int _index) { return highs[_index]; } + float GetLow(int _index) { return lows[_index]; } + void Reset(int _index) { + highs[_index] = 0.0f; + lows[_index] = 0.0f; + } + void Update(float _value, int _index) { + highs[_index] = _value > highs[_index] ? _value : highs[_index]; + lows[_index] = _value < lows[_index] || lows[_index] == 0.0f ? _value : lows[_index]; + } +}; + +/** + * Implements Pivot Detector. + */ +class Indi_Killzones : public Indicator { + protected: + Indi_Killzones_Time ikt; + IndiKillzonesParams params; + + public: + /** + * Class constructor. + */ + Indi_Killzones(IndiKillzonesParams &_params) : params(_params), Indicator((IndicatorParams)_params){}; + Indi_Killzones(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : Indicator(INDI_KILLZONES, _tf, _shift) { + params.tf = _tf; + }; + + /** + * Returns the indicator's value. + */ + float GetValue(unsigned int _mode, int _shift = 0) { + ResetLastError(); + float _value = FLT_MAX; + int _index = (int)floor(_mode / 2); + switch (params.idstype) { + case IDATA_BUILTIN: + // Builtin mode not supported. + SetUserError(ERR_INVALID_PARAMETER); + istate.is_ready = false; + break; + case IDATA_CHART: + ikt.Set(::TimeGMT()); + if (ikt.CheckHours(_index)) { + // Pass values to check for new highs or lows. + ikt.Update(_mode % 2 == 0 ? (float)GetHigh(_shift) : (float)GetLow(_shift), _index); + } + // Set a final value. + _value = _mode % 2 == 0 ? ikt.GetHigh(_index) : ikt.GetLow(_index); + break; + default: + SetUserError(ERR_INVALID_PARAMETER); + } + return _value; + } + + /** + * Checks if value is valid. + */ + bool IsValidValue(float _value, unsigned int _mode = 0, int _shift = 0) { return _value > 0.0f; } + + /** + * Returns the indicator's struct value. + */ + IndicatorDataEntry GetEntry(int _shift = 0) { + long _bar_time = GetBarTime(_shift); + IndicatorDataEntry _entry = idata.GetByKey(_bar_time); + if (!_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) { + _entry.Resize(params.max_modes); + _entry.timestamp = GetBarTime(_shift); + for (unsigned int _mode = 0; _mode < params.max_modes; _mode++) { + float _value = GetValue(_mode, _shift); + if (IsValidValue(_value, _mode, _shift)) { + _entry.values[_mode] = _value; + } + } + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.IsGe(0) && !_entry.HasValue(FLT_MAX)); + if (_entry.IsValid()) { + _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + idata.Add(_entry, _bar_time); + istate.is_changed = false; + istate.is_ready = true; + } else { + _entry.AddFlags(INDI_ENTRY_FLAG_INSUFFICIENT_DATA); + istate.is_ready = false; + } + } + return _entry; + } + + /** + * Returns the indicator's entry value. + */ + MqlParam GetEntryValue(int _shift = 0, int _mode = 0) { + MqlParam _param = {TYPE_INT}; + _param.integer_value = GetEntry(_shift).GetValue(_mode); + return _param; + } + + /* Getters */ + + /** + * Get pivot point calculation method. + */ + ENUM_PP_TYPE GetMethod() { return params.method; } + + /* Setters */ + + /** + * Set pivot point calculation method. + */ + void SetMethod(ENUM_PP_TYPE _method) { + istate.is_changed = true; + params.method = _method; + } + + /** + * Whether we can and have to select mode when specifying data source. + */ + virtual bool IsDataSourceModeSelectable() { return false; } +}; diff --git a/Indicators/tests/Indi_Killzones.test.mq4 b/Indicators/tests/Indi_Killzones.test.mq4 new file mode 100644 index 000000000..12f792f2c --- /dev/null +++ b/Indicators/tests/Indi_Killzones.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Killzones indicator class. + */ + +#include "Indi_Killzones.test.mq5" diff --git a/Indicators/tests/Indi_Killzones.test.mq5 b/Indicators/tests/Indi_Killzones.test.mq5 new file mode 100644 index 000000000..45d8d0fc3 --- /dev/null +++ b/Indicators/tests/Indi_Killzones.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Killzones.mqh" + +/** + * @file + * Test functionality of Indi_Killzones indicator class. + */ + +Indi_Killzones indi(PERIOD_CURRENT, 1); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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(1)); + } + } + _tick_last = _tick_new; +} From 69627fd5fcd05cef6ee5672200ca70887cad8068 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 21 Sep 2021 21:46:24 +0100 Subject: [PATCH 03/78] Indicators/tests: Adds new tests --- Indicators/tests/Indi_BWMFI.test.mq4 | 27 +++++++++ Indicators/tests/Indi_BWMFI.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_BWZT.test.mq4 | 27 +++++++++ Indicators/tests/Indi_BWZT.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Bands.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Bands.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_BearsPower.test.mq4 | 27 +++++++++ Indicators/tests/Indi_BearsPower.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_BullsPower.test.mq4 | 27 +++++++++ Indicators/tests/Indi_BullsPower.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_CCI.test.mq4 | 27 +++++++++ Indicators/tests/Indi_CCI.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_CHO.test.mq4 | 27 +++++++++ Indicators/tests/Indi_CHO.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_CHV.test.mq4 | 27 +++++++++ Indicators/tests/Indi_CHV.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_ColorBars.test.mq4 | 27 +++++++++ Indicators/tests/Indi_ColorBars.test.mq5 | 57 +++++++++++++++++++ .../tests/Indi_ColorCandlesDaily.test.mq4 | 27 +++++++++ .../tests/Indi_ColorCandlesDaily.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_ColorLine.test.mq4 | 27 +++++++++ Indicators/tests/Indi_ColorLine.test.mq5 | 57 +++++++++++++++++++ .../tests/Indi_CustomMovingAverage.test.mq4 | 27 +++++++++ .../tests/Indi_CustomMovingAverage.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_DEMA.test.mq4 | 27 +++++++++ Indicators/tests/Indi_DEMA.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_DeMarker.test.mq4 | 27 +++++++++ Indicators/tests/Indi_DeMarker.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Demo.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Demo.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_DetrendedPrice.test.mq4 | 27 +++++++++ Indicators/tests/Indi_DetrendedPrice.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Drawer.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Drawer.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Envelopes.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Envelopes.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Force.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Force.test.mq5 | 57 +++++++++++++++++++ .../tests/Indi_FractalAdaptiveMA.test.mq4 | 27 +++++++++ .../tests/Indi_FractalAdaptiveMA.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Fractals.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Fractals.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Gator.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Gator.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_HeikenAshi.test.mq4 | 27 +++++++++ Indicators/tests/Indi_HeikenAshi.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Ichimoku.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Ichimoku.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_MA.test.mq4 | 27 +++++++++ Indicators/tests/Indi_MA.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_MACD.test.mq4 | 27 +++++++++ Indicators/tests/Indi_MACD.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_MFI.test.mq4 | 27 +++++++++ Indicators/tests/Indi_MFI.test.mq5 | 57 +++++++++++++++++++ .../Indi_MarketFacilitationIndex.test.mq4 | 27 +++++++++ .../Indi_MarketFacilitationIndex.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_MassIndex.test.mq4 | 27 +++++++++ Indicators/tests/Indi_MassIndex.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Momentum.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Momentum.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_OBV.test.mq4 | 27 +++++++++ Indicators/tests/Indi_OBV.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_OsMA.test.mq4 | 27 +++++++++ Indicators/tests/Indi_OsMA.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Pattern.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Pattern.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Price.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Price.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_PriceChannel.test.mq4 | 27 +++++++++ Indicators/tests/Indi_PriceChannel.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_PriceFeeder.test.mq4 | 27 +++++++++ Indicators/tests/Indi_PriceFeeder.test.mq5 | 57 +++++++++++++++++++ .../tests/Indi_PriceVolumeTrend.test.mq4 | 27 +++++++++ .../tests/Indi_PriceVolumeTrend.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_RS.test.mq4 | 27 +++++++++ Indicators/tests/Indi_RS.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_RSI.test.mq4 | 27 +++++++++ Indicators/tests/Indi_RSI.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_RVI.test.mq4 | 27 +++++++++ Indicators/tests/Indi_RVI.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_RateOfChange.test.mq4 | 27 +++++++++ Indicators/tests/Indi_RateOfChange.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_SAR.test.mq4 | 27 +++++++++ Indicators/tests/Indi_SAR.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_StdDev.test.mq4 | 27 +++++++++ Indicators/tests/Indi_StdDev.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Stochastic.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Stochastic.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_TEMA.test.mq4 | 27 +++++++++ Indicators/tests/Indi_TEMA.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_TRIX.test.mq4 | 27 +++++++++ Indicators/tests/Indi_TRIX.test.mq5 | 57 +++++++++++++++++++ .../tests/Indi_UltimateOscillator.test.mq4 | 27 +++++++++ .../tests/Indi_UltimateOscillator.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_VIDYA.test.mq4 | 27 +++++++++ Indicators/tests/Indi_VIDYA.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_VROC.test.mq4 | 27 +++++++++ Indicators/tests/Indi_VROC.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_Volumes.test.mq4 | 27 +++++++++ Indicators/tests/Indi_Volumes.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_WPR.test.mq4 | 27 +++++++++ Indicators/tests/Indi_WPR.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_WilliamsAD.test.mq4 | 27 +++++++++ Indicators/tests/Indi_WilliamsAD.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_ZigZag.test.mq4 | 27 +++++++++ Indicators/tests/Indi_ZigZag.test.mq5 | 57 +++++++++++++++++++ Indicators/tests/Indi_ZigZagColor.test.mq4 | 27 +++++++++ Indicators/tests/Indi_ZigZagColor.test.mq5 | 57 +++++++++++++++++++ 108 files changed, 4536 insertions(+) create mode 100644 Indicators/tests/Indi_BWMFI.test.mq4 create mode 100644 Indicators/tests/Indi_BWMFI.test.mq5 create mode 100644 Indicators/tests/Indi_BWZT.test.mq4 create mode 100644 Indicators/tests/Indi_BWZT.test.mq5 create mode 100644 Indicators/tests/Indi_Bands.test.mq4 create mode 100644 Indicators/tests/Indi_Bands.test.mq5 create mode 100644 Indicators/tests/Indi_BearsPower.test.mq4 create mode 100644 Indicators/tests/Indi_BearsPower.test.mq5 create mode 100644 Indicators/tests/Indi_BullsPower.test.mq4 create mode 100644 Indicators/tests/Indi_BullsPower.test.mq5 create mode 100644 Indicators/tests/Indi_CCI.test.mq4 create mode 100644 Indicators/tests/Indi_CCI.test.mq5 create mode 100644 Indicators/tests/Indi_CHO.test.mq4 create mode 100644 Indicators/tests/Indi_CHO.test.mq5 create mode 100644 Indicators/tests/Indi_CHV.test.mq4 create mode 100644 Indicators/tests/Indi_CHV.test.mq5 create mode 100644 Indicators/tests/Indi_ColorBars.test.mq4 create mode 100644 Indicators/tests/Indi_ColorBars.test.mq5 create mode 100644 Indicators/tests/Indi_ColorCandlesDaily.test.mq4 create mode 100644 Indicators/tests/Indi_ColorCandlesDaily.test.mq5 create mode 100644 Indicators/tests/Indi_ColorLine.test.mq4 create mode 100644 Indicators/tests/Indi_ColorLine.test.mq5 create mode 100644 Indicators/tests/Indi_CustomMovingAverage.test.mq4 create mode 100644 Indicators/tests/Indi_CustomMovingAverage.test.mq5 create mode 100644 Indicators/tests/Indi_DEMA.test.mq4 create mode 100644 Indicators/tests/Indi_DEMA.test.mq5 create mode 100644 Indicators/tests/Indi_DeMarker.test.mq4 create mode 100644 Indicators/tests/Indi_DeMarker.test.mq5 create mode 100644 Indicators/tests/Indi_Demo.test.mq4 create mode 100644 Indicators/tests/Indi_Demo.test.mq5 create mode 100644 Indicators/tests/Indi_DetrendedPrice.test.mq4 create mode 100644 Indicators/tests/Indi_DetrendedPrice.test.mq5 create mode 100644 Indicators/tests/Indi_Drawer.test.mq4 create mode 100644 Indicators/tests/Indi_Drawer.test.mq5 create mode 100644 Indicators/tests/Indi_Envelopes.test.mq4 create mode 100644 Indicators/tests/Indi_Envelopes.test.mq5 create mode 100644 Indicators/tests/Indi_Force.test.mq4 create mode 100644 Indicators/tests/Indi_Force.test.mq5 create mode 100644 Indicators/tests/Indi_FractalAdaptiveMA.test.mq4 create mode 100644 Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 create mode 100644 Indicators/tests/Indi_Fractals.test.mq4 create mode 100644 Indicators/tests/Indi_Fractals.test.mq5 create mode 100644 Indicators/tests/Indi_Gator.test.mq4 create mode 100644 Indicators/tests/Indi_Gator.test.mq5 create mode 100644 Indicators/tests/Indi_HeikenAshi.test.mq4 create mode 100644 Indicators/tests/Indi_HeikenAshi.test.mq5 create mode 100644 Indicators/tests/Indi_Ichimoku.test.mq4 create mode 100644 Indicators/tests/Indi_Ichimoku.test.mq5 create mode 100644 Indicators/tests/Indi_MA.test.mq4 create mode 100644 Indicators/tests/Indi_MA.test.mq5 create mode 100644 Indicators/tests/Indi_MACD.test.mq4 create mode 100644 Indicators/tests/Indi_MACD.test.mq5 create mode 100644 Indicators/tests/Indi_MFI.test.mq4 create mode 100644 Indicators/tests/Indi_MFI.test.mq5 create mode 100644 Indicators/tests/Indi_MarketFacilitationIndex.test.mq4 create mode 100644 Indicators/tests/Indi_MarketFacilitationIndex.test.mq5 create mode 100644 Indicators/tests/Indi_MassIndex.test.mq4 create mode 100644 Indicators/tests/Indi_MassIndex.test.mq5 create mode 100644 Indicators/tests/Indi_Momentum.test.mq4 create mode 100644 Indicators/tests/Indi_Momentum.test.mq5 create mode 100644 Indicators/tests/Indi_OBV.test.mq4 create mode 100644 Indicators/tests/Indi_OBV.test.mq5 create mode 100644 Indicators/tests/Indi_OsMA.test.mq4 create mode 100644 Indicators/tests/Indi_OsMA.test.mq5 create mode 100644 Indicators/tests/Indi_Pattern.test.mq4 create mode 100644 Indicators/tests/Indi_Pattern.test.mq5 create mode 100644 Indicators/tests/Indi_Price.test.mq4 create mode 100644 Indicators/tests/Indi_Price.test.mq5 create mode 100644 Indicators/tests/Indi_PriceChannel.test.mq4 create mode 100644 Indicators/tests/Indi_PriceChannel.test.mq5 create mode 100644 Indicators/tests/Indi_PriceFeeder.test.mq4 create mode 100644 Indicators/tests/Indi_PriceFeeder.test.mq5 create mode 100644 Indicators/tests/Indi_PriceVolumeTrend.test.mq4 create mode 100644 Indicators/tests/Indi_PriceVolumeTrend.test.mq5 create mode 100644 Indicators/tests/Indi_RS.test.mq4 create mode 100644 Indicators/tests/Indi_RS.test.mq5 create mode 100644 Indicators/tests/Indi_RSI.test.mq4 create mode 100644 Indicators/tests/Indi_RSI.test.mq5 create mode 100644 Indicators/tests/Indi_RVI.test.mq4 create mode 100644 Indicators/tests/Indi_RVI.test.mq5 create mode 100644 Indicators/tests/Indi_RateOfChange.test.mq4 create mode 100644 Indicators/tests/Indi_RateOfChange.test.mq5 create mode 100644 Indicators/tests/Indi_SAR.test.mq4 create mode 100644 Indicators/tests/Indi_SAR.test.mq5 create mode 100644 Indicators/tests/Indi_StdDev.test.mq4 create mode 100644 Indicators/tests/Indi_StdDev.test.mq5 create mode 100644 Indicators/tests/Indi_Stochastic.test.mq4 create mode 100644 Indicators/tests/Indi_Stochastic.test.mq5 create mode 100644 Indicators/tests/Indi_TEMA.test.mq4 create mode 100644 Indicators/tests/Indi_TEMA.test.mq5 create mode 100644 Indicators/tests/Indi_TRIX.test.mq4 create mode 100644 Indicators/tests/Indi_TRIX.test.mq5 create mode 100644 Indicators/tests/Indi_UltimateOscillator.test.mq4 create mode 100644 Indicators/tests/Indi_UltimateOscillator.test.mq5 create mode 100644 Indicators/tests/Indi_VIDYA.test.mq4 create mode 100644 Indicators/tests/Indi_VIDYA.test.mq5 create mode 100644 Indicators/tests/Indi_VROC.test.mq4 create mode 100644 Indicators/tests/Indi_VROC.test.mq5 create mode 100644 Indicators/tests/Indi_Volumes.test.mq4 create mode 100644 Indicators/tests/Indi_Volumes.test.mq5 create mode 100644 Indicators/tests/Indi_WPR.test.mq4 create mode 100644 Indicators/tests/Indi_WPR.test.mq5 create mode 100644 Indicators/tests/Indi_WilliamsAD.test.mq4 create mode 100644 Indicators/tests/Indi_WilliamsAD.test.mq5 create mode 100644 Indicators/tests/Indi_ZigZag.test.mq4 create mode 100644 Indicators/tests/Indi_ZigZag.test.mq5 create mode 100644 Indicators/tests/Indi_ZigZagColor.test.mq4 create mode 100644 Indicators/tests/Indi_ZigZagColor.test.mq5 diff --git a/Indicators/tests/Indi_BWMFI.test.mq4 b/Indicators/tests/Indi_BWMFI.test.mq4 new file mode 100644 index 000000000..3db17f482 --- /dev/null +++ b/Indicators/tests/Indi_BWMFI.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_BWMFI indicator class. + */ + +#include "Indi_BWMFI.test.mq5" diff --git a/Indicators/tests/Indi_BWMFI.test.mq5 b/Indicators/tests/Indi_BWMFI.test.mq5 new file mode 100644 index 000000000..a5229b301 --- /dev/null +++ b/Indicators/tests/Indi_BWMFI.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_BWMFI.mqh" + +/** + * @file + * Test functionality of Indi_BWMFI indicator class. + */ + +Indi_BWMFI indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_BWZT.test.mq4 b/Indicators/tests/Indi_BWZT.test.mq4 new file mode 100644 index 000000000..63b312f58 --- /dev/null +++ b/Indicators/tests/Indi_BWZT.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_BWZT indicator class. + */ + +#include "Indi_BWZT.test.mq5" diff --git a/Indicators/tests/Indi_BWZT.test.mq5 b/Indicators/tests/Indi_BWZT.test.mq5 new file mode 100644 index 000000000..3f9737520 --- /dev/null +++ b/Indicators/tests/Indi_BWZT.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_BWZT.mqh" + +/** + * @file + * Test functionality of Indi_BWZT indicator class. + */ + +Indi_BWZT indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Bands.test.mq4 b/Indicators/tests/Indi_Bands.test.mq4 new file mode 100644 index 000000000..78e550018 --- /dev/null +++ b/Indicators/tests/Indi_Bands.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Bands indicator class. + */ + +#include "Indi_Bands.test.mq5" diff --git a/Indicators/tests/Indi_Bands.test.mq5 b/Indicators/tests/Indi_Bands.test.mq5 new file mode 100644 index 000000000..0fba23043 --- /dev/null +++ b/Indicators/tests/Indi_Bands.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Bands.mqh" + +/** + * @file + * Test functionality of Indi_Bands indicator class. + */ + +Indi_Bands indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_BearsPower.test.mq4 b/Indicators/tests/Indi_BearsPower.test.mq4 new file mode 100644 index 000000000..8d43b3c60 --- /dev/null +++ b/Indicators/tests/Indi_BearsPower.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_BearsPower indicator class. + */ + +#include "Indi_BearsPower.test.mq5" diff --git a/Indicators/tests/Indi_BearsPower.test.mq5 b/Indicators/tests/Indi_BearsPower.test.mq5 new file mode 100644 index 000000000..d75d399b1 --- /dev/null +++ b/Indicators/tests/Indi_BearsPower.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_BearsPower.mqh" + +/** + * @file + * Test functionality of Indi_BearsPower indicator class. + */ + +Indi_BearsPower indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_BullsPower.test.mq4 b/Indicators/tests/Indi_BullsPower.test.mq4 new file mode 100644 index 000000000..d9fc05869 --- /dev/null +++ b/Indicators/tests/Indi_BullsPower.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_BullsPower indicator class. + */ + +#include "Indi_BullsPower.test.mq5" diff --git a/Indicators/tests/Indi_BullsPower.test.mq5 b/Indicators/tests/Indi_BullsPower.test.mq5 new file mode 100644 index 000000000..6daa8d462 --- /dev/null +++ b/Indicators/tests/Indi_BullsPower.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_BullsPower.mqh" + +/** + * @file + * Test functionality of Indi_BullsPower indicator class. + */ + +Indi_BullsPower indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_CCI.test.mq4 b/Indicators/tests/Indi_CCI.test.mq4 new file mode 100644 index 000000000..309271938 --- /dev/null +++ b/Indicators/tests/Indi_CCI.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_CCI indicator class. + */ + +#include "Indi_CCI.test.mq5" diff --git a/Indicators/tests/Indi_CCI.test.mq5 b/Indicators/tests/Indi_CCI.test.mq5 new file mode 100644 index 000000000..cf632abb0 --- /dev/null +++ b/Indicators/tests/Indi_CCI.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_CCI.mqh" + +/** + * @file + * Test functionality of Indi_CCI indicator class. + */ + +Indi_CCI indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_CHO.test.mq4 b/Indicators/tests/Indi_CHO.test.mq4 new file mode 100644 index 000000000..11acc3005 --- /dev/null +++ b/Indicators/tests/Indi_CHO.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_CHO indicator class. + */ + +#include "Indi_CHO.test.mq5" diff --git a/Indicators/tests/Indi_CHO.test.mq5 b/Indicators/tests/Indi_CHO.test.mq5 new file mode 100644 index 000000000..f02148a36 --- /dev/null +++ b/Indicators/tests/Indi_CHO.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_CHO.mqh" + +/** + * @file + * Test functionality of Indi_CHO indicator class. + */ + +Indi_CHO indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_CHV.test.mq4 b/Indicators/tests/Indi_CHV.test.mq4 new file mode 100644 index 000000000..e190dc77d --- /dev/null +++ b/Indicators/tests/Indi_CHV.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_CHV indicator class. + */ + +#include "Indi_CHV.test.mq5" diff --git a/Indicators/tests/Indi_CHV.test.mq5 b/Indicators/tests/Indi_CHV.test.mq5 new file mode 100644 index 000000000..6019bcad4 --- /dev/null +++ b/Indicators/tests/Indi_CHV.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_CHV.mqh" + +/** + * @file + * Test functionality of Indi_CHV indicator class. + */ + +Indi_CHV indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_ColorBars.test.mq4 b/Indicators/tests/Indi_ColorBars.test.mq4 new file mode 100644 index 000000000..0858213d2 --- /dev/null +++ b/Indicators/tests/Indi_ColorBars.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_ColorBars indicator class. + */ + +#include "Indi_ColorBars.test.mq5" diff --git a/Indicators/tests/Indi_ColorBars.test.mq5 b/Indicators/tests/Indi_ColorBars.test.mq5 new file mode 100644 index 000000000..6fb4ff8fc --- /dev/null +++ b/Indicators/tests/Indi_ColorBars.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_ColorBars.mqh" + +/** + * @file + * Test functionality of Indi_ColorBars indicator class. + */ + +Indi_ColorBars indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_ColorCandlesDaily.test.mq4 b/Indicators/tests/Indi_ColorCandlesDaily.test.mq4 new file mode 100644 index 000000000..d77adc574 --- /dev/null +++ b/Indicators/tests/Indi_ColorCandlesDaily.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_ColorCandlesDaily indicator class. + */ + +#include "Indi_ColorCandlesDaily.test.mq5" diff --git a/Indicators/tests/Indi_ColorCandlesDaily.test.mq5 b/Indicators/tests/Indi_ColorCandlesDaily.test.mq5 new file mode 100644 index 000000000..75aad77ab --- /dev/null +++ b/Indicators/tests/Indi_ColorCandlesDaily.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_ColorCandlesDaily.mqh" + +/** + * @file + * Test functionality of Indi_ColorCandlesDaily indicator class. + */ + +Indi_ColorCandlesDaily indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_ColorLine.test.mq4 b/Indicators/tests/Indi_ColorLine.test.mq4 new file mode 100644 index 000000000..0199b7560 --- /dev/null +++ b/Indicators/tests/Indi_ColorLine.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_ColorLine indicator class. + */ + +#include "Indi_ColorLine.test.mq5" diff --git a/Indicators/tests/Indi_ColorLine.test.mq5 b/Indicators/tests/Indi_ColorLine.test.mq5 new file mode 100644 index 000000000..3516f1d6b --- /dev/null +++ b/Indicators/tests/Indi_ColorLine.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_ColorLine.mqh" + +/** + * @file + * Test functionality of Indi_ColorLine indicator class. + */ + +Indi_ColorLine indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_CustomMovingAverage.test.mq4 b/Indicators/tests/Indi_CustomMovingAverage.test.mq4 new file mode 100644 index 000000000..b42e19e49 --- /dev/null +++ b/Indicators/tests/Indi_CustomMovingAverage.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_CustomMovingAverage indicator class. + */ + +#include "Indi_CustomMovingAverage.test.mq5" diff --git a/Indicators/tests/Indi_CustomMovingAverage.test.mq5 b/Indicators/tests/Indi_CustomMovingAverage.test.mq5 new file mode 100644 index 000000000..952d5ae9e --- /dev/null +++ b/Indicators/tests/Indi_CustomMovingAverage.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_CustomMovingAverage.mqh" + +/** + * @file + * Test functionality of Indi_CustomMovingAverage indicator class. + */ + +Indi_CustomMovingAverage indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_DEMA.test.mq4 b/Indicators/tests/Indi_DEMA.test.mq4 new file mode 100644 index 000000000..c2a168889 --- /dev/null +++ b/Indicators/tests/Indi_DEMA.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_DEMA indicator class. + */ + +#include "Indi_DEMA.test.mq5" diff --git a/Indicators/tests/Indi_DEMA.test.mq5 b/Indicators/tests/Indi_DEMA.test.mq5 new file mode 100644 index 000000000..b6b4fe929 --- /dev/null +++ b/Indicators/tests/Indi_DEMA.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_DEMA.mqh" + +/** + * @file + * Test functionality of Indi_DEMA indicator class. + */ + +Indi_DEMA indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_DeMarker.test.mq4 b/Indicators/tests/Indi_DeMarker.test.mq4 new file mode 100644 index 000000000..cc63b04c8 --- /dev/null +++ b/Indicators/tests/Indi_DeMarker.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_DeMarker indicator class. + */ + +#include "Indi_DeMarker.test.mq5" diff --git a/Indicators/tests/Indi_DeMarker.test.mq5 b/Indicators/tests/Indi_DeMarker.test.mq5 new file mode 100644 index 000000000..b6abf6db0 --- /dev/null +++ b/Indicators/tests/Indi_DeMarker.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_DeMarker.mqh" + +/** + * @file + * Test functionality of Indi_DeMarker indicator class. + */ + +Indi_DeMarker indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Demo.test.mq4 b/Indicators/tests/Indi_Demo.test.mq4 new file mode 100644 index 000000000..d5056995e --- /dev/null +++ b/Indicators/tests/Indi_Demo.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Demo indicator class. + */ + +#include "Indi_Demo.test.mq5" diff --git a/Indicators/tests/Indi_Demo.test.mq5 b/Indicators/tests/Indi_Demo.test.mq5 new file mode 100644 index 000000000..368d72d2a --- /dev/null +++ b/Indicators/tests/Indi_Demo.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Demo.mqh" + +/** + * @file + * Test functionality of Indi_Demo indicator class. + */ + +Indi_Demo indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_DetrendedPrice.test.mq4 b/Indicators/tests/Indi_DetrendedPrice.test.mq4 new file mode 100644 index 000000000..297f2c81a --- /dev/null +++ b/Indicators/tests/Indi_DetrendedPrice.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_DetrendedPrice indicator class. + */ + +#include "Indi_DetrendedPrice.test.mq5" diff --git a/Indicators/tests/Indi_DetrendedPrice.test.mq5 b/Indicators/tests/Indi_DetrendedPrice.test.mq5 new file mode 100644 index 000000000..b40a1f9f8 --- /dev/null +++ b/Indicators/tests/Indi_DetrendedPrice.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_DetrendedPrice.mqh" + +/** + * @file + * Test functionality of Indi_DetrendedPrice indicator class. + */ + +Indi_DetrendedPrice indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Drawer.test.mq4 b/Indicators/tests/Indi_Drawer.test.mq4 new file mode 100644 index 000000000..32cf4a1e2 --- /dev/null +++ b/Indicators/tests/Indi_Drawer.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Drawer indicator class. + */ + +#include "Indi_Drawer.test.mq5" diff --git a/Indicators/tests/Indi_Drawer.test.mq5 b/Indicators/tests/Indi_Drawer.test.mq5 new file mode 100644 index 000000000..178a25fe8 --- /dev/null +++ b/Indicators/tests/Indi_Drawer.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Drawer.mqh" + +/** + * @file + * Test functionality of Indi_Drawer indicator class. + */ + +Indi_Drawer indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Envelopes.test.mq4 b/Indicators/tests/Indi_Envelopes.test.mq4 new file mode 100644 index 000000000..af9885c8e --- /dev/null +++ b/Indicators/tests/Indi_Envelopes.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Envelopes indicator class. + */ + +#include "Indi_Envelopes.test.mq5" diff --git a/Indicators/tests/Indi_Envelopes.test.mq5 b/Indicators/tests/Indi_Envelopes.test.mq5 new file mode 100644 index 000000000..ff468b16e --- /dev/null +++ b/Indicators/tests/Indi_Envelopes.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Envelopes.mqh" + +/** + * @file + * Test functionality of Indi_Envelopes indicator class. + */ + +Indi_Envelopes indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Force.test.mq4 b/Indicators/tests/Indi_Force.test.mq4 new file mode 100644 index 000000000..aefa93e28 --- /dev/null +++ b/Indicators/tests/Indi_Force.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Force indicator class. + */ + +#include "Indi_Force.test.mq5" diff --git a/Indicators/tests/Indi_Force.test.mq5 b/Indicators/tests/Indi_Force.test.mq5 new file mode 100644 index 000000000..bfd0d97d7 --- /dev/null +++ b/Indicators/tests/Indi_Force.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Force.mqh" + +/** + * @file + * Test functionality of Indi_Force indicator class. + */ + +Indi_Force indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_FractalAdaptiveMA.test.mq4 b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq4 new file mode 100644 index 000000000..1073b537d --- /dev/null +++ b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_FractalAdaptiveMA indicator class. + */ + +#include "Indi_FractalAdaptiveMA.test.mq5" diff --git a/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 new file mode 100644 index 000000000..3a7f4d9c8 --- /dev/null +++ b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_FractalAdaptiveMA.mqh" + +/** + * @file + * Test functionality of Indi_FractalAdaptiveMA indicator class. + */ + +Indi_FractalAdaptiveMA indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Fractals.test.mq4 b/Indicators/tests/Indi_Fractals.test.mq4 new file mode 100644 index 000000000..74575bfef --- /dev/null +++ b/Indicators/tests/Indi_Fractals.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Fractals indicator class. + */ + +#include "Indi_Fractals.test.mq5" diff --git a/Indicators/tests/Indi_Fractals.test.mq5 b/Indicators/tests/Indi_Fractals.test.mq5 new file mode 100644 index 000000000..2a441ca5c --- /dev/null +++ b/Indicators/tests/Indi_Fractals.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Fractals.mqh" + +/** + * @file + * Test functionality of Indi_Fractals indicator class. + */ + +Indi_Fractals indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Gator.test.mq4 b/Indicators/tests/Indi_Gator.test.mq4 new file mode 100644 index 000000000..017e97229 --- /dev/null +++ b/Indicators/tests/Indi_Gator.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Gator indicator class. + */ + +#include "Indi_Gator.test.mq5" diff --git a/Indicators/tests/Indi_Gator.test.mq5 b/Indicators/tests/Indi_Gator.test.mq5 new file mode 100644 index 000000000..325623c1f --- /dev/null +++ b/Indicators/tests/Indi_Gator.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Gator.mqh" + +/** + * @file + * Test functionality of Indi_Gator indicator class. + */ + +Indi_Gator indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_HeikenAshi.test.mq4 b/Indicators/tests/Indi_HeikenAshi.test.mq4 new file mode 100644 index 000000000..7412e5399 --- /dev/null +++ b/Indicators/tests/Indi_HeikenAshi.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_HeikenAshi indicator class. + */ + +#include "Indi_HeikenAshi.test.mq5" diff --git a/Indicators/tests/Indi_HeikenAshi.test.mq5 b/Indicators/tests/Indi_HeikenAshi.test.mq5 new file mode 100644 index 000000000..8f5dd357d --- /dev/null +++ b/Indicators/tests/Indi_HeikenAshi.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_HeikenAshi.mqh" + +/** + * @file + * Test functionality of Indi_HeikenAshi indicator class. + */ + +Indi_HeikenAshi indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Ichimoku.test.mq4 b/Indicators/tests/Indi_Ichimoku.test.mq4 new file mode 100644 index 000000000..942b84bd7 --- /dev/null +++ b/Indicators/tests/Indi_Ichimoku.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Ichimoku indicator class. + */ + +#include "Indi_Ichimoku.test.mq5" diff --git a/Indicators/tests/Indi_Ichimoku.test.mq5 b/Indicators/tests/Indi_Ichimoku.test.mq5 new file mode 100644 index 000000000..8325c0b14 --- /dev/null +++ b/Indicators/tests/Indi_Ichimoku.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Ichimoku.mqh" + +/** + * @file + * Test functionality of Indi_Ichimoku indicator class. + */ + +Indi_Ichimoku indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_MA.test.mq4 b/Indicators/tests/Indi_MA.test.mq4 new file mode 100644 index 000000000..89d4ee4b4 --- /dev/null +++ b/Indicators/tests/Indi_MA.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_MA indicator class. + */ + +#include "Indi_MA.test.mq5" diff --git a/Indicators/tests/Indi_MA.test.mq5 b/Indicators/tests/Indi_MA.test.mq5 new file mode 100644 index 000000000..8c84ef55e --- /dev/null +++ b/Indicators/tests/Indi_MA.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_MA.mqh" + +/** + * @file + * Test functionality of Indi_MA indicator class. + */ + +Indi_MA indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_MACD.test.mq4 b/Indicators/tests/Indi_MACD.test.mq4 new file mode 100644 index 000000000..e03f0a44b --- /dev/null +++ b/Indicators/tests/Indi_MACD.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_MACD indicator class. + */ + +#include "Indi_MACD.test.mq5" diff --git a/Indicators/tests/Indi_MACD.test.mq5 b/Indicators/tests/Indi_MACD.test.mq5 new file mode 100644 index 000000000..a8f664f1c --- /dev/null +++ b/Indicators/tests/Indi_MACD.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_MACD.mqh" + +/** + * @file + * Test functionality of Indi_MACD indicator class. + */ + +Indi_MACD indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_MFI.test.mq4 b/Indicators/tests/Indi_MFI.test.mq4 new file mode 100644 index 000000000..d6e3a1c9e --- /dev/null +++ b/Indicators/tests/Indi_MFI.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_MFI indicator class. + */ + +#include "Indi_MFI.test.mq5" diff --git a/Indicators/tests/Indi_MFI.test.mq5 b/Indicators/tests/Indi_MFI.test.mq5 new file mode 100644 index 000000000..812533deb --- /dev/null +++ b/Indicators/tests/Indi_MFI.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_MFI.mqh" + +/** + * @file + * Test functionality of Indi_MFI indicator class. + */ + +Indi_MFI indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_MarketFacilitationIndex.test.mq4 b/Indicators/tests/Indi_MarketFacilitationIndex.test.mq4 new file mode 100644 index 000000000..7528e9508 --- /dev/null +++ b/Indicators/tests/Indi_MarketFacilitationIndex.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_MarketFacilitationIndex indicator class. + */ + +#include "Indi_MarketFacilitationIndex.test.mq5" diff --git a/Indicators/tests/Indi_MarketFacilitationIndex.test.mq5 b/Indicators/tests/Indi_MarketFacilitationIndex.test.mq5 new file mode 100644 index 000000000..a4f58f32d --- /dev/null +++ b/Indicators/tests/Indi_MarketFacilitationIndex.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_MarketFacilitationIndex.mqh" + +/** + * @file + * Test functionality of Indi_MarketFacilitationIndex indicator class. + */ + +Indi_MarketFacilitationIndex indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_MassIndex.test.mq4 b/Indicators/tests/Indi_MassIndex.test.mq4 new file mode 100644 index 000000000..9a53fa65f --- /dev/null +++ b/Indicators/tests/Indi_MassIndex.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_MassIndex indicator class. + */ + +#include "Indi_MassIndex.test.mq5" diff --git a/Indicators/tests/Indi_MassIndex.test.mq5 b/Indicators/tests/Indi_MassIndex.test.mq5 new file mode 100644 index 000000000..6c9117aa3 --- /dev/null +++ b/Indicators/tests/Indi_MassIndex.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_MassIndex.mqh" + +/** + * @file + * Test functionality of Indi_MassIndex indicator class. + */ + +Indi_MassIndex indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Momentum.test.mq4 b/Indicators/tests/Indi_Momentum.test.mq4 new file mode 100644 index 000000000..31fb68c33 --- /dev/null +++ b/Indicators/tests/Indi_Momentum.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Momentum indicator class. + */ + +#include "Indi_Momentum.test.mq5" diff --git a/Indicators/tests/Indi_Momentum.test.mq5 b/Indicators/tests/Indi_Momentum.test.mq5 new file mode 100644 index 000000000..0c916fa9e --- /dev/null +++ b/Indicators/tests/Indi_Momentum.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Momentum.mqh" + +/** + * @file + * Test functionality of Indi_Momentum indicator class. + */ + +Indi_Momentum indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_OBV.test.mq4 b/Indicators/tests/Indi_OBV.test.mq4 new file mode 100644 index 000000000..372045b77 --- /dev/null +++ b/Indicators/tests/Indi_OBV.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_OBV indicator class. + */ + +#include "Indi_OBV.test.mq5" diff --git a/Indicators/tests/Indi_OBV.test.mq5 b/Indicators/tests/Indi_OBV.test.mq5 new file mode 100644 index 000000000..ce78cee3a --- /dev/null +++ b/Indicators/tests/Indi_OBV.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_OBV.mqh" + +/** + * @file + * Test functionality of Indi_OBV indicator class. + */ + +Indi_OBV indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_OsMA.test.mq4 b/Indicators/tests/Indi_OsMA.test.mq4 new file mode 100644 index 000000000..476dfe415 --- /dev/null +++ b/Indicators/tests/Indi_OsMA.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_OsMA indicator class. + */ + +#include "Indi_OsMA.test.mq5" diff --git a/Indicators/tests/Indi_OsMA.test.mq5 b/Indicators/tests/Indi_OsMA.test.mq5 new file mode 100644 index 000000000..9139c108b --- /dev/null +++ b/Indicators/tests/Indi_OsMA.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_OsMA.mqh" + +/** + * @file + * Test functionality of Indi_OsMA indicator class. + */ + +Indi_OsMA indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Pattern.test.mq4 b/Indicators/tests/Indi_Pattern.test.mq4 new file mode 100644 index 000000000..155c7b60a --- /dev/null +++ b/Indicators/tests/Indi_Pattern.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Pattern indicator class. + */ + +#include "Indi_Pattern.test.mq5" diff --git a/Indicators/tests/Indi_Pattern.test.mq5 b/Indicators/tests/Indi_Pattern.test.mq5 new file mode 100644 index 000000000..88fd982b7 --- /dev/null +++ b/Indicators/tests/Indi_Pattern.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Pattern.mqh" + +/** + * @file + * Test functionality of Indi_Pattern indicator class. + */ + +Indi_Pattern indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Price.test.mq4 b/Indicators/tests/Indi_Price.test.mq4 new file mode 100644 index 000000000..5f07803bc --- /dev/null +++ b/Indicators/tests/Indi_Price.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Price indicator class. + */ + +#include "Indi_Price.test.mq5" diff --git a/Indicators/tests/Indi_Price.test.mq5 b/Indicators/tests/Indi_Price.test.mq5 new file mode 100644 index 000000000..c05b54743 --- /dev/null +++ b/Indicators/tests/Indi_Price.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Price.mqh" + +/** + * @file + * Test functionality of Indi_Price indicator class. + */ + +Indi_Price indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_PriceChannel.test.mq4 b/Indicators/tests/Indi_PriceChannel.test.mq4 new file mode 100644 index 000000000..23b54fa5e --- /dev/null +++ b/Indicators/tests/Indi_PriceChannel.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_PriceChannel indicator class. + */ + +#include "Indi_PriceChannel.test.mq5" diff --git a/Indicators/tests/Indi_PriceChannel.test.mq5 b/Indicators/tests/Indi_PriceChannel.test.mq5 new file mode 100644 index 000000000..46cdaf509 --- /dev/null +++ b/Indicators/tests/Indi_PriceChannel.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_PriceChannel.mqh" + +/** + * @file + * Test functionality of Indi_PriceChannel indicator class. + */ + +Indi_PriceChannel indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_PriceFeeder.test.mq4 b/Indicators/tests/Indi_PriceFeeder.test.mq4 new file mode 100644 index 000000000..6976c01ec --- /dev/null +++ b/Indicators/tests/Indi_PriceFeeder.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_PriceFeeder indicator class. + */ + +#include "Indi_PriceFeeder.test.mq5" diff --git a/Indicators/tests/Indi_PriceFeeder.test.mq5 b/Indicators/tests/Indi_PriceFeeder.test.mq5 new file mode 100644 index 000000000..c4626b0e6 --- /dev/null +++ b/Indicators/tests/Indi_PriceFeeder.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_PriceFeeder.mqh" + +/** + * @file + * Test functionality of Indi_PriceFeeder indicator class. + */ + +Indi_PriceFeeder indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_PriceVolumeTrend.test.mq4 b/Indicators/tests/Indi_PriceVolumeTrend.test.mq4 new file mode 100644 index 000000000..45a6e2c09 --- /dev/null +++ b/Indicators/tests/Indi_PriceVolumeTrend.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_PriceVolumeTrend indicator class. + */ + +#include "Indi_PriceVolumeTrend.test.mq5" diff --git a/Indicators/tests/Indi_PriceVolumeTrend.test.mq5 b/Indicators/tests/Indi_PriceVolumeTrend.test.mq5 new file mode 100644 index 000000000..5108b95e8 --- /dev/null +++ b/Indicators/tests/Indi_PriceVolumeTrend.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_PriceVolumeTrend.mqh" + +/** + * @file + * Test functionality of Indi_PriceVolumeTrend indicator class. + */ + +Indi_PriceVolumeTrend indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_RS.test.mq4 b/Indicators/tests/Indi_RS.test.mq4 new file mode 100644 index 000000000..5f191c9ea --- /dev/null +++ b/Indicators/tests/Indi_RS.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_RS indicator class. + */ + +#include "Indi_RS.test.mq5" diff --git a/Indicators/tests/Indi_RS.test.mq5 b/Indicators/tests/Indi_RS.test.mq5 new file mode 100644 index 000000000..cd78f2036 --- /dev/null +++ b/Indicators/tests/Indi_RS.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_RS.mqh" + +/** + * @file + * Test functionality of Indi_RS indicator class. + */ + +Indi_RS indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_RSI.test.mq4 b/Indicators/tests/Indi_RSI.test.mq4 new file mode 100644 index 000000000..b7f5e55d3 --- /dev/null +++ b/Indicators/tests/Indi_RSI.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_RSI indicator class. + */ + +#include "Indi_RSI.test.mq5" diff --git a/Indicators/tests/Indi_RSI.test.mq5 b/Indicators/tests/Indi_RSI.test.mq5 new file mode 100644 index 000000000..d40fd5e8b --- /dev/null +++ b/Indicators/tests/Indi_RSI.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_RSI.mqh" + +/** + * @file + * Test functionality of Indi_RSI indicator class. + */ + +Indi_RSI indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_RVI.test.mq4 b/Indicators/tests/Indi_RVI.test.mq4 new file mode 100644 index 000000000..cfd5e372f --- /dev/null +++ b/Indicators/tests/Indi_RVI.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_RVI indicator class. + */ + +#include "Indi_RVI.test.mq5" diff --git a/Indicators/tests/Indi_RVI.test.mq5 b/Indicators/tests/Indi_RVI.test.mq5 new file mode 100644 index 000000000..0cebe859b --- /dev/null +++ b/Indicators/tests/Indi_RVI.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_RVI.mqh" + +/** + * @file + * Test functionality of Indi_RVI indicator class. + */ + +Indi_RVI indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_RateOfChange.test.mq4 b/Indicators/tests/Indi_RateOfChange.test.mq4 new file mode 100644 index 000000000..6ca89fbef --- /dev/null +++ b/Indicators/tests/Indi_RateOfChange.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_RateOfChange indicator class. + */ + +#include "Indi_RateOfChange.test.mq5" diff --git a/Indicators/tests/Indi_RateOfChange.test.mq5 b/Indicators/tests/Indi_RateOfChange.test.mq5 new file mode 100644 index 000000000..e7cc7a024 --- /dev/null +++ b/Indicators/tests/Indi_RateOfChange.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_RateOfChange.mqh" + +/** + * @file + * Test functionality of Indi_RateOfChange indicator class. + */ + +Indi_RateOfChange indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_SAR.test.mq4 b/Indicators/tests/Indi_SAR.test.mq4 new file mode 100644 index 000000000..cb64f79b4 --- /dev/null +++ b/Indicators/tests/Indi_SAR.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_SAR indicator class. + */ + +#include "Indi_SAR.test.mq5" diff --git a/Indicators/tests/Indi_SAR.test.mq5 b/Indicators/tests/Indi_SAR.test.mq5 new file mode 100644 index 000000000..895fbd375 --- /dev/null +++ b/Indicators/tests/Indi_SAR.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_SAR.mqh" + +/** + * @file + * Test functionality of Indi_SAR indicator class. + */ + +Indi_SAR indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_StdDev.test.mq4 b/Indicators/tests/Indi_StdDev.test.mq4 new file mode 100644 index 000000000..e36c47034 --- /dev/null +++ b/Indicators/tests/Indi_StdDev.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_StdDev indicator class. + */ + +#include "Indi_StdDev.test.mq5" diff --git a/Indicators/tests/Indi_StdDev.test.mq5 b/Indicators/tests/Indi_StdDev.test.mq5 new file mode 100644 index 000000000..4929bf2b4 --- /dev/null +++ b/Indicators/tests/Indi_StdDev.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_StdDev.mqh" + +/** + * @file + * Test functionality of Indi_StdDev indicator class. + */ + +Indi_StdDev indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Stochastic.test.mq4 b/Indicators/tests/Indi_Stochastic.test.mq4 new file mode 100644 index 000000000..54658083e --- /dev/null +++ b/Indicators/tests/Indi_Stochastic.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Stochastic indicator class. + */ + +#include "Indi_Stochastic.test.mq5" diff --git a/Indicators/tests/Indi_Stochastic.test.mq5 b/Indicators/tests/Indi_Stochastic.test.mq5 new file mode 100644 index 000000000..09e99ed27 --- /dev/null +++ b/Indicators/tests/Indi_Stochastic.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Stochastic.mqh" + +/** + * @file + * Test functionality of Indi_Stochastic indicator class. + */ + +Indi_Stochastic indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_TEMA.test.mq4 b/Indicators/tests/Indi_TEMA.test.mq4 new file mode 100644 index 000000000..41332b6a6 --- /dev/null +++ b/Indicators/tests/Indi_TEMA.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_TEMA indicator class. + */ + +#include "Indi_TEMA.test.mq5" diff --git a/Indicators/tests/Indi_TEMA.test.mq5 b/Indicators/tests/Indi_TEMA.test.mq5 new file mode 100644 index 000000000..30ab6b3cb --- /dev/null +++ b/Indicators/tests/Indi_TEMA.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_TEMA.mqh" + +/** + * @file + * Test functionality of Indi_TEMA indicator class. + */ + +Indi_TEMA indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_TRIX.test.mq4 b/Indicators/tests/Indi_TRIX.test.mq4 new file mode 100644 index 000000000..be5579c93 --- /dev/null +++ b/Indicators/tests/Indi_TRIX.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_TRIX indicator class. + */ + +#include "Indi_TRIX.test.mq5" diff --git a/Indicators/tests/Indi_TRIX.test.mq5 b/Indicators/tests/Indi_TRIX.test.mq5 new file mode 100644 index 000000000..d6b8d16fa --- /dev/null +++ b/Indicators/tests/Indi_TRIX.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_TRIX.mqh" + +/** + * @file + * Test functionality of Indi_TRIX indicator class. + */ + +Indi_TRIX indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_UltimateOscillator.test.mq4 b/Indicators/tests/Indi_UltimateOscillator.test.mq4 new file mode 100644 index 000000000..ec6d67e78 --- /dev/null +++ b/Indicators/tests/Indi_UltimateOscillator.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_UltimateOscillator indicator class. + */ + +#include "Indi_UltimateOscillator.test.mq5" diff --git a/Indicators/tests/Indi_UltimateOscillator.test.mq5 b/Indicators/tests/Indi_UltimateOscillator.test.mq5 new file mode 100644 index 000000000..44e2c2a37 --- /dev/null +++ b/Indicators/tests/Indi_UltimateOscillator.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_UltimateOscillator.mqh" + +/** + * @file + * Test functionality of Indi_UltimateOscillator indicator class. + */ + +Indi_UltimateOscillator indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_VIDYA.test.mq4 b/Indicators/tests/Indi_VIDYA.test.mq4 new file mode 100644 index 000000000..a222007f1 --- /dev/null +++ b/Indicators/tests/Indi_VIDYA.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_VIDYA indicator class. + */ + +#include "Indi_VIDYA.test.mq5" diff --git a/Indicators/tests/Indi_VIDYA.test.mq5 b/Indicators/tests/Indi_VIDYA.test.mq5 new file mode 100644 index 000000000..c94227252 --- /dev/null +++ b/Indicators/tests/Indi_VIDYA.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_VIDYA.mqh" + +/** + * @file + * Test functionality of Indi_VIDYA indicator class. + */ + +Indi_VIDYA indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_VROC.test.mq4 b/Indicators/tests/Indi_VROC.test.mq4 new file mode 100644 index 000000000..307567add --- /dev/null +++ b/Indicators/tests/Indi_VROC.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_VROC indicator class. + */ + +#include "Indi_VROC.test.mq5" diff --git a/Indicators/tests/Indi_VROC.test.mq5 b/Indicators/tests/Indi_VROC.test.mq5 new file mode 100644 index 000000000..fd0ce8036 --- /dev/null +++ b/Indicators/tests/Indi_VROC.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_VROC.mqh" + +/** + * @file + * Test functionality of Indi_VROC indicator class. + */ + +Indi_VROC indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_Volumes.test.mq4 b/Indicators/tests/Indi_Volumes.test.mq4 new file mode 100644 index 000000000..3b85b25ff --- /dev/null +++ b/Indicators/tests/Indi_Volumes.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_Volumes indicator class. + */ + +#include "Indi_Volumes.test.mq5" diff --git a/Indicators/tests/Indi_Volumes.test.mq5 b/Indicators/tests/Indi_Volumes.test.mq5 new file mode 100644 index 000000000..7ca0e369e --- /dev/null +++ b/Indicators/tests/Indi_Volumes.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_Volumes.mqh" + +/** + * @file + * Test functionality of Indi_Volumes indicator class. + */ + +Indi_Volumes indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_WPR.test.mq4 b/Indicators/tests/Indi_WPR.test.mq4 new file mode 100644 index 000000000..7e3e27097 --- /dev/null +++ b/Indicators/tests/Indi_WPR.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_WPR indicator class. + */ + +#include "Indi_WPR.test.mq5" diff --git a/Indicators/tests/Indi_WPR.test.mq5 b/Indicators/tests/Indi_WPR.test.mq5 new file mode 100644 index 000000000..ebc76e3cf --- /dev/null +++ b/Indicators/tests/Indi_WPR.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_WPR.mqh" + +/** + * @file + * Test functionality of Indi_WPR indicator class. + */ + +Indi_WPR indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_WilliamsAD.test.mq4 b/Indicators/tests/Indi_WilliamsAD.test.mq4 new file mode 100644 index 000000000..c3aa0468a --- /dev/null +++ b/Indicators/tests/Indi_WilliamsAD.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_WilliamsAD indicator class. + */ + +#include "Indi_WilliamsAD.test.mq5" diff --git a/Indicators/tests/Indi_WilliamsAD.test.mq5 b/Indicators/tests/Indi_WilliamsAD.test.mq5 new file mode 100644 index 000000000..a3840617a --- /dev/null +++ b/Indicators/tests/Indi_WilliamsAD.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_WilliamsAD.mqh" + +/** + * @file + * Test functionality of Indi_WilliamsAD indicator class. + */ + +Indi_WilliamsAD indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_ZigZag.test.mq4 b/Indicators/tests/Indi_ZigZag.test.mq4 new file mode 100644 index 000000000..dfe9dc22a --- /dev/null +++ b/Indicators/tests/Indi_ZigZag.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_ZigZag indicator class. + */ + +#include "Indi_ZigZag.test.mq5" diff --git a/Indicators/tests/Indi_ZigZag.test.mq5 b/Indicators/tests/Indi_ZigZag.test.mq5 new file mode 100644 index 000000000..2c2a7e7a9 --- /dev/null +++ b/Indicators/tests/Indi_ZigZag.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_ZigZag.mqh" + +/** + * @file + * Test functionality of Indi_ZigZag indicator class. + */ + +Indi_ZigZag indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} diff --git a/Indicators/tests/Indi_ZigZagColor.test.mq4 b/Indicators/tests/Indi_ZigZagColor.test.mq4 new file mode 100644 index 000000000..750d34430 --- /dev/null +++ b/Indicators/tests/Indi_ZigZagColor.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of Indi_ZigZagColor indicator class. + */ + +#include "Indi_ZigZagColor.test.mq5" diff --git a/Indicators/tests/Indi_ZigZagColor.test.mq5 b/Indicators/tests/Indi_ZigZagColor.test.mq5 new file mode 100644 index 000000000..92b2b5b89 --- /dev/null +++ b/Indicators/tests/Indi_ZigZagColor.test.mq5 @@ -0,0 +1,57 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +// Includes. +#include "../../Test.mqh" +#include "../Indi_ZigZagColor.mqh" + +/** + * @file + * Test functionality of Indi_ZigZagColor indicator class. + */ + +Indi_ZigZagColor indi(PERIOD_CURRENT); + +/** + * Implements Init event handler. + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); + 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()); + } + } + _tick_last = _tick_new; +} From df3e33b472cc05ebfcb99a40ba07a04561629d36 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Fri, 24 Sep 2021 18:39:21 +0200 Subject: [PATCH 04/78] WIP. Indicators' constructors and Indicators Params' constructors refactoring. Some indicators doesn't work in MT4. --- Indicators/Bitwise/Indi_Candle.mqh | 2 +- Indicators/Indi_AC.mqh | 15 ++++---- Indicators/Indi_AD.mqh | 17 +++------ Indicators/Indi_ADX.mqh | 33 ++++-------------- Indicators/Indi_ADXW.mqh | 24 ++++++------- Indicators/Indi_AMA.mqh | 35 +++++-------------- Indicators/Indi_AO.mqh | 17 +++------ Indicators/Indi_ASI.mqh | 14 +++----- Indicators/Indi_ATR.mqh | 14 +++----- Indicators/Indi_Alligator.mqh | 20 ++++------- Indicators/Indi_AppliedPrice.mqh | 17 ++++----- Indicators/Indi_BWMFI.mqh | 18 ++++------ Indicators/Indi_BWZT.mqh | 14 +++----- Indicators/Indi_Bands.mqh | 12 ++----- Indicators/Indi_BearsPower.mqh | 22 ++++-------- Indicators/Indi_BullsPower.mqh | 20 ++++------- Indicators/Indi_CCI.mqh | 25 ++++---------- Indicators/Indi_CHO.mqh | 19 +++------- Indicators/Indi_CHV.mqh | 16 +++------ Indicators/Indi_ColorBars.mqh | 17 ++++----- Indicators/Indi_ColorCandlesDaily.mqh | 17 ++++----- Indicators/Indi_ColorLine.mqh | 22 +++++------- Indicators/Indi_CustomMovingAverage.mqh | 21 ++++------- Indicators/Indi_DEMA.mqh | 46 ++++++------------------- Indicators/Indi_DeMarker.mqh | 19 ++++------ Indicators/Indi_Demo.mqh | 33 +++++------------- Indicators/Indi_DetrendedPrice.mqh | 18 ++++------ Indicators/Indi_Drawer.mqh | 22 +++++------- Indicators/Indi_Drawer.struct.h | 19 ++-------- Indicators/Indi_Envelopes.mqh | 32 ++++++----------- Indicators/Indi_Force.mqh | 23 +++++-------- Indicators/Indi_FractalAdaptiveMA.mqh | 14 +++----- Indicators/Indi_Fractals.mqh | 17 ++++----- Indicators/Indi_Gator.mqh | 29 +++++----------- Indicators/Indi_HeikenAshi.mqh | 20 +++++------ Indicators/Indi_Ichimoku.mqh | 24 ++++--------- Indicators/Indi_MA.mqh | 25 ++++---------- Indicators/Indi_MACD.mqh | 28 +++++---------- Indicators/Indi_MFI.mqh | 22 ++++-------- Indicators/Indi_MassIndex.mqh | 15 +++----- Indicators/Indi_Momentum.mqh | 22 ++++-------- Indicators/Indi_OBV.mqh | 27 ++++----------- Indicators/Indi_OsMA.mqh | 27 ++++----------- Indicators/Indi_Pattern.mqh | 14 +++----- Indicators/Indi_Pivot.mqh | 14 +++----- Indicators/Indi_Price.mqh | 31 +++++++++-------- Indicators/Indi_PriceChannel.mqh | 16 ++++----- Indicators/Indi_PriceFeeder.mqh | 8 +++-- Indicators/Indi_PriceVolumeTrend.mqh | 17 +++------ Indicators/Indi_RS.mqh | 14 +++----- Indicators/Indi_RSI.mqh | 30 +++++----------- Indicators/Indi_RVI.mqh | 19 +++++----- Indicators/Indi_RateOfChange.mqh | 14 +++----- Indicators/Indi_SAR.mqh | 15 +++----- Indicators/Indi_StdDev.mqh | 22 ++++-------- Indicators/Indi_Stochastic.mqh | 26 +++++--------- Indicators/Indi_TEMA.mqh | 13 ++----- Indicators/Indi_TRIX.mqh | 15 +++----- Indicators/Indi_UltimateOscillator.mqh | 24 +++---------- Indicators/Indi_VIDYA.mqh | 14 +++----- Indicators/Indi_VROC.mqh | 15 +++----- Indicators/Indi_Volumes.mqh | 14 +++----- Indicators/Indi_WPR.mqh | 17 ++++----- Indicators/Indi_WilliamsAD.mqh | 15 ++++---- Indicators/Indi_ZigZag.mqh | 18 +++------- Indicators/Indi_ZigZagColor.mqh | 18 ++++------ tests/IndicatorsTest.mq5 | 2 +- 67 files changed, 409 insertions(+), 909 deletions(-) diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index ce39ece9f..a30f9db22 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -37,7 +37,7 @@ struct CandleParams : IndicatorParams { max_modes = 1; SetDataValueType(TYPE_INT); SetDataValueRange(IDATA_RANGE_RANGE); - SetDataSourceType(IDATA_BUILTIN); + shift = _shift; tf = _tf; }; diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index eecbeb1c0..53241a271 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -32,18 +32,13 @@ double iAC(string _symbol, int _tf, int _shift) { return Indi_AC::iAC(_symbol, ( // Structs. struct ACParams : IndicatorParams { // Struct constructor. - void ACParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void ACParams(int _shift = 0) { itype = INDI_AC; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Accelerator"); shift = _shift; - tf = _tf; - }; - void ACParams(ACParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -58,8 +53,10 @@ class Indi_AC : public Indicator { /** * Class constructor. */ - Indi_AC(ACParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_AC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AC, _tf) { params.SetTf(_tf); }; + Indi_AC(ACParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { + params = _params; + } + Indi_AC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AC, _tf){}; /** * Returns the indicator value. @@ -111,7 +108,7 @@ class Indi_AC : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_AC::iAC(GetSymbol(), GetTf(), _shift, GetPointer(this)); + _value = Indi_AC::iAC(GetSymbol(), GetTf(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index afe5b1d50..5e477dc19 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -31,18 +31,13 @@ double iAD(string _symbol, int _tf, int _shift) { return Indi_AD::iAD(_symbol, ( // Structs. struct ADParams : IndicatorParams { // Struct constructor. - ADParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + ADParams(int _shift = 0) { itype = INDI_AD; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\AD"); shift = _shift; - tf = _tf; - }; - ADParams(ADParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -57,8 +52,8 @@ class Indi_AD : public Indicator { /** * Class constructor. */ - Indi_AD(ADParams &_p) : Indicator((IndicatorParams)_p) { params = _p; }; - Indi_AD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AD, _tf) { params.SetTf(_tf); }; + Indi_AD(ADParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; }; + Indi_AD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AD, _tf){}; /** * Returns the indicator value. @@ -110,12 +105,10 @@ class Indi_AD : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_AD::iAD(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), _shift, - GetPointer(this)); + _value = Indi_AD::iAD(GetSymbol(), GetTf(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 99e7d60ad..72793b1f8 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -37,31 +37,13 @@ struct ADXParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void ADXParams(unsigned int _period = 14, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, - ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) - : period(_period), applied_price(PRICE_TYPICAL) { - itype = itype == INDI_NONE ? INDI_ADX : itype; - SetDataSourceType(_idstype); + ADXParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0) + : period(_period), applied_price(_ap) { + itype = INDI_ADX; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetMaxModes(FINAL_INDI_ADX_LINE_ENTRY); SetShift(_shift); - switch (idstype) { - case IDATA_ICUSTOM: - if (custom_indi_name == "") { - SetCustomIndicatorName("Examples\\ADX"); - } - break; - case IDATA_INDICATOR: - if (indi_data_source == NULL) { - SetDataSource(Indi_Price::GetCached(_shift, _tf, applied_price, _period)); - } - break; - } - }; - void ADXParams(ADXParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -76,7 +58,7 @@ class Indi_ADX : public Indicator { /** * Class constructor. */ - Indi_ADX(ADXParams &_p) : params(_p.period, _p.applied_price), Indicator((IndicatorParams)_p) { params = _p; } + Indi_ADX(ADXParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } Indi_ADX(ENUM_TIMEFRAMES _tf) : Indicator(INDI_ADX, _tf) {} /** @@ -132,12 +114,11 @@ class Indi_ADX : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_ADX::iADX(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetAppliedPrice(), _mode, _shift, GetPointer(this)); + _value = Indi_ADX::iADX(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index 7727295af..6d7f4194c 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -36,18 +36,14 @@ // Structs. struct ADXWParams : ADXParams { // Struct constructor. - void ADXWParams(int _period = 14, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, - ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) - : ADXParams(_period, _shift, _tf, _idstype) { - itype = itype == INDI_NONE || itype == INDI_ADX ? INDI_ADXW : itype; - switch (idstype) { - case IDATA_ICUSTOM: - SetCustomIndicatorName("Examples\\ADXW"); - break; - } + void ADXWParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : ADXParams(_period, _ap, _shift) { + itype = INDI_ADXW; + SetCustomIndicatorName("Examples\\ADXW"); }; - void ADXWParams(ADXWParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : ADXParams(_params, _tf) {} - void ADXWParams(ADXParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : ADXParams(_params, _tf) {} + void ADXWParams(ADXWParams &_params) { THIS_REF = _params; } + void ADXWParams(ADXParams &_params) { THIS_REF = _params; } }; /** @@ -61,8 +57,10 @@ class Indi_ADXW : public Indicator { /** * Class constructor. */ - Indi_ADXW(ADXWParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ADXW(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ADXW, _tf) { params.tf = _tf; }; + Indi_ADXW(ADXWParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_ADXW(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ADXW, _tf){}; /** * Built-in version of ADX Wilder. diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index cb2458914..6f124adf1 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -36,37 +36,18 @@ struct IndiAMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. void IndiAMAParams(int _period = 10, int _fast_period = 2, int _slow_period = 30, int _ama_shift = 0, - ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, - ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) + ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0) : period(_period), fast_period(_fast_period), slow_period(_slow_period), ama_shift(_ama_shift), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_AMA : itype; - SetDataSourceType(_idstype); + itype = INDI_AMA; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetMaxModes(1); SetShift(_shift); - tf = _tf; - switch (idstype) { - case IDATA_ICUSTOM: - if (custom_indi_name == "") { - SetCustomIndicatorName("Examples\\AMA"); - } - break; - case IDATA_INDICATOR: - if (GetDataSource() == NULL) { - SetDataSource(Indi_Price::GetCached(_shift, _tf, _ap, _period), false); - SetDataSourceMode(0); - } - break; - } - }; - void IndiAMAParams(IndiAMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; + SetCustomIndicatorName("Examples\\AMA"); }; }; @@ -81,8 +62,11 @@ class Indi_AMA : public Indicator { /** * Class constructor. */ - Indi_AMA(IndiAMAParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { params = _params; }; - Indi_AMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AMA, _tf) { params.tf = _tf; }; + Indi_AMA(IndiAMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : params(_params.period, _tf), Indicator((IndicatorParams)_params) { + params = _params; + }; + Indi_AMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AMA, _tf){}; /** * Built-in version of AMA. @@ -191,9 +175,6 @@ class Indi_AMA : public Indicator { double currentSSC = (CalculateER(i, price, ExtPeriodAMA) * (ExtFastSC - ExtSlowSC)) + ExtSlowSC; //--- calculate AMA double prevAMA = ExtAMABuffer[i - 1].Get(); - - // Print(price[i].Get(), " == ", iOpen(NULL, 0, 2981 - (i))); - ExtAMABuffer[i] = MathPow(currentSSC, 2) * (price[i] - prevAMA) + prevAMA; } //--- return value of prev_calculated for next call diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index d93977120..8f4a63cfb 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -31,7 +31,7 @@ double iAO(string _symbol, int _tf, int _shift) { return Indi_AO::iAO(_symbol, ( // Structs. struct AOParams : IndicatorParams { // Struct constructor. - void AOParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void AOParams(int _shift = 0) { itype = INDI_AO; #ifdef __MQL4__ max_modes = 1; @@ -42,11 +42,6 @@ struct AOParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Awesome_Oscillator"); shift = _shift; - tf = _tf; - }; - void AOParams(AOParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -61,8 +56,8 @@ class Indi_AO : public Indicator { /** * Class constructor. */ - Indi_AO(AOParams &_p) : Indicator((IndicatorParams)_p) { params = _p; }; - Indi_AO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : params(_tf), Indicator(INDI_AO, _tf){}; + Indi_AO(AOParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; }; + Indi_AO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AO, _tf){}; /** * Returns the indicator value. @@ -115,12 +110,10 @@ class Indi_AO : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_AO::iAO(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), _shift, _mode, - GetPointer(this)); + _value = Indi_AO::iAO(GetSymbol(), GetTf(), _shift, _mode, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index 6a44a1f34..c2c196bcc 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -30,20 +30,14 @@ struct ASIParams : IndicatorParams { unsigned int period; double mpc; // Struct constructor. - void ASIParams(double _mpc = 300.0, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void ASIParams(double _mpc = 300.0, int _shift = 0) { itype = INDI_ASI; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ASI"); - SetDataSourceType(IDATA_BUILTIN); mpc = _mpc; shift = _shift; - tf = _tf; - }; - void ASIParams(ASIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -58,8 +52,10 @@ class Indi_ASI : public Indicator { /** * Class constructor. */ - Indi_ASI(ASIParams &_params) : params(_params.mpc), Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ASI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ASI, _tf) { params.tf = _tf; }; + Indi_ASI(ASIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_ASI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ASI, _tf){}; /** * Built-in version of ASI. diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index e005da486..e204a654a 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -34,19 +34,13 @@ double iATR(string _symbol, int _tf, int _period, int _shift) { struct ATRParams : IndicatorParams { unsigned int period; // Struct constructors. - void ATRParams(unsigned int _period = 14, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL) - : period(_period) { + void ATRParams(unsigned int _period = 14, int _shift = 0) : period(_period) { itype = INDI_ATR; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ATR"); - tf = _tf; - }; - void ATRParams(ATRParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -62,8 +56,8 @@ class Indi_ATR : public Indicator { /** * Class constructor. */ - Indi_ATR(ATRParams &_p) : params(_p.period), Indicator((IndicatorParams)_p) { params = _p; } - Indi_ATR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ATR, _tf) { params.SetTf(_tf); }; + Indi_ATR(ATRParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_ATR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ATR, _tf){}; /** * Returns the indicator value. @@ -115,7 +109,7 @@ class Indi_ATR : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_ATR::iATR(GetSymbol(), GetTf(), GetPeriod(), _shift, GetPointer(this)); + _value = Indi_ATR::iATR(GetSymbol(), GetTf(), GetPeriod(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index cb7877526..b15add7cc 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -85,13 +85,8 @@ struct AlligatorParams : IndicatorParams { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); - SetDataSourceType(IDATA_BUILTIN); SetCustomIndicatorName("Examples\\Alligator"); }; - void AlligatorParams(AlligatorParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -104,8 +99,9 @@ class Indi_Alligator : public Indicator { /** * Class constructor. */ - Indi_Alligator(AlligatorParams &_p) : Indicator((IndicatorParams)_p) { params = _p; } - Indi_Alligator(AlligatorParams &_p, ENUM_TIMEFRAMES _tf) : Indicator(INDI_ALLIGATOR, _tf) { params = _p; } + Indi_Alligator(AlligatorParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { + params = _p; + } Indi_Alligator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ADX, _tf){}; /** @@ -179,14 +175,12 @@ class Indi_Alligator : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_Alligator::iAlligator(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), - GetLipsPeriod(), GetLipsShift(), GetMAMethod(), GetAppliedPrice(), _mode, - _shift, GetPointer(this)); + _value = Indi_Alligator::iAlligator(GetSymbol(), GetTf(), GetJawPeriod(), GetJawShift(), GetTeethPeriod(), + GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), + GetAppliedPrice(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), GetAppliedPrice() diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index a83920e50..ed15972dd 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -28,20 +28,14 @@ struct AppliedPriceParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. - AppliedPriceParams(ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + AppliedPriceParams(ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) { itype = INDI_APPLIED_PRICE; max_modes = 1; applied_price = _applied_price; + SetDataSourceType(IDATA_INDICATOR); SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); - SetDataSourceType(IDATA_INDICATOR); shift = _shift; - tf = _tf; - }; - AppliedPriceParams(AppliedPriceParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -56,8 +50,11 @@ class Indi_AppliedPrice : public Indicator { /** * Class constructor. */ - Indi_AppliedPrice(AppliedPriceParams &_params) : params(_params), Indicator((IndicatorParams)_params){}; - Indi_AppliedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : params(PRICE_OPEN, 0, _tf), Indicator(INDI_PRICE, _tf){}; + Indi_AppliedPrice(AppliedPriceParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_AppliedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE, _tf){}; static double iAppliedPriceOnIndicator(Indicator *_indi, ENUM_APPLIED_PRICE _applied_price, int _shift = 0) { double _ohlc[4]; diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index 3929ea7db..16a1309de 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -43,18 +43,13 @@ enum ENUM_MFI_COLOR { // Structs. struct BWMFIParams : IndicatorParams { // Struct constructors. - BWMFIParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + BWMFIParams(int _shift = 0) { itype = INDI_BWMFI; max_modes = FINAL_BWMFI_BUFFER_ENTRY; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\MarketFacilitationIndex"); shift = _shift; - tf = _tf; - }; - BWMFIParams(BWMFIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -69,7 +64,9 @@ class Indi_BWMFI : public Indicator { /** * Class constructor. */ - Indi_BWMFI(IndicatorParams &_p) : Indicator((IndicatorParams)_p) {} + Indi_BWMFI(BWMFIParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { + params = _p; + } Indi_BWMFI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BWMFI, _tf) {} /** @@ -124,12 +121,11 @@ class Indi_BWMFI : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = _value = iBWMFI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), _shift, _mode, - GetPointer(this)); + _value = _value = iBWMFI(GetSymbol(), GetTf(), _shift, _mode, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ VOLUME_TICK /*]*/, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ VOLUME_TICK /*]*/, + _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 8723ecca3..f7d51bf40 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -32,19 +32,13 @@ struct BWZTParams : IndicatorParams { unsigned int second_period; unsigned int sum_period; // Struct constructor. - void BWZTParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void BWZTParams(int _shift = 0) { itype = INDI_BWZT; max_modes = 5; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\BW-ZoneTrade"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void BWZTParams(BWZTParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -59,8 +53,10 @@ class Indi_BWZT : public Indicator { /** * Class constructor. */ - Indi_BWZT(BWZTParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_BWZT(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BWZT, _tf) { params.tf = _tf; }; + Indi_BWZT(BWZTParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_BWZT(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BWZT, _tf){}; /** * Built-in version of BWZT. diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 1ba81ec8f..f30e81416 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -74,10 +74,6 @@ struct BandsParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\BB"); }; - void BandsParams(BandsParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -92,14 +88,10 @@ class Indi_Bands : public Indicator { /** * Class constructor. */ - Indi_Bands(BandsParams &_p) - : params(_p.period, _p.deviation, _p.shift, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Bands(BandsParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.deviation, _p.shift, _p.applied_price), Indicator(INDI_BANDS, _tf) { + Indi_Bands(BandsParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_Bands(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BANDS, _tf) {} /** * Returns the indicator value. diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index ddc259ddb..16bdf4c09 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -33,9 +33,9 @@ double iBearsPower(string _symbol, int _tf, int _period, int _ap, int _shift) { // Structs. struct BearsPowerParams : IndicatorParams { unsigned int period; - ENUM_APPLIED_PRICE applied_price; // (MT5): not used + ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void BearsPowerParams(unsigned int _period, ENUM_APPLIED_PRICE _ap, int _shift = 0) + void BearsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), applied_price(_ap) { itype = INDI_BEARS; max_modes = 1; @@ -44,10 +44,6 @@ struct BearsPowerParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Bears"); }; - void BearsPowerParams(BearsPowerParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -60,13 +56,10 @@ class Indi_BearsPower : public Indicator { /** * Class constructor. */ - Indi_BearsPower(BearsPowerParams &_p) : params(_p.period, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_BearsPower(BearsPowerParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.applied_price), Indicator(INDI_BEARS, _tf) { + Indi_BearsPower(BearsPowerParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_BearsPower(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BEARS, _tf) {} /** * Returns the indicator value. @@ -119,12 +112,11 @@ class Indi_BearsPower : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = _value = iBearsPower(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetPeriod(), GetAppliedPrice(), _shift, GetPointer(this)); + _value = _value = iBearsPower(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index fc08d911b..5a64a98a1 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -35,7 +35,7 @@ struct BullsPowerParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // (MT5): not used // Struct constructor. - void BullsPowerParams(unsigned int _period, ENUM_APPLIED_PRICE _ap, int _shift = 0) + void BullsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), applied_price(_ap) { itype = INDI_BULLS; max_modes = 1; @@ -44,10 +44,6 @@ struct BullsPowerParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Bulls"); }; - void BullsPowerParams(BullsPowerParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -62,13 +58,10 @@ class Indi_BullsPower : public Indicator { /** * Class constructor. */ - Indi_BullsPower(BullsPowerParams &_p) : params(_p.period, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_BullsPower(BullsPowerParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.applied_price), Indicator(INDI_BULLS, _tf) { + Indi_BullsPower(BullsPowerParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_BullsPower(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BULLS, _tf) {} /** * Returns the indicator value. @@ -121,12 +114,11 @@ class Indi_BullsPower : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = iBullsPower(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetAppliedPrice(), _shift, GetPointer(this)); + _value = iBullsPower(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /**/ GetPeriod() /**/, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /**/ GetPeriod() /**/, + _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 76e4642af..bbcc91d61 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -50,10 +50,6 @@ struct CCIParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CCI"); }; - void CCIParams(CCIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -66,14 +62,8 @@ class Indi_CCI : public Indicator { /** * Class constructor. */ - Indi_CCI(CCIParams &_p) : params(_p.period, _p.applied_price, _p.shift), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_CCI(CCIParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.applied_price, _p.shift), Indicator(INDI_CCI, _tf) { - params = _p; - } - + Indi_CCI(CCIParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_CCI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CCI, _tf) {} /** * Returns the indicator value. * @@ -185,19 +175,18 @@ class Indi_CCI : public Indicator { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; // @fixit Somehow shift isn't used neither in MT4 nor MT5. - _value = Indi_CCI::iCCI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetAppliedPrice(), _shift /* + params.shift*/, GetPointer(this)); + _value = + Indi_CCI::iCCI(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _shift /* + params.shift*/, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /* [ */ GetPeriod(), GetAppliedPrice() /* ] */, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.custom_indi_name, /* [ */ GetPeriod(), + GetAppliedPrice() /* ] */, 0, _shift); break; case IDATA_INDICATOR: ValidateSelectedDataSource(); // @fixit Somehow shift isn't used neither in MT4 nor MT5. - _value = Indi_CCI::iCCIOnIndicator(GetDataSource(), Get(CHART_PARAM_SYMBOL), - Get(CHART_PARAM_TF), GetPeriod(), GetDataSourceMode(), + _value = Indi_CCI::iCCIOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), GetDataSourceMode(), _shift /* + params.shift*/); break; } diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 22f51df65..a80e9926a 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -33,8 +33,7 @@ struct CHOParams : IndicatorParams { ENUM_APPLIED_VOLUME input_volume; // Struct constructor. void CHOParams(int _fast_ma = 3, int _slow_ma = 10, ENUM_MA_METHOD _smooth_method = MODE_EMA, - ENUM_APPLIED_VOLUME _input_volume = VOLUME_TICK, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + ENUM_APPLIED_VOLUME _input_volume = VOLUME_TICK, int _shift = 0) { fast_ma = _fast_ma; input_volume = _input_volume; itype = INDI_CHAIKIN; @@ -45,11 +44,6 @@ struct CHOParams : IndicatorParams { shift = _shift; slow_ma = _slow_ma; smooth_method = _smooth_method; - tf = _tf; - }; - void CHOParams(CHOParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -64,12 +58,10 @@ class Indi_CHO : public Indicator { /** * Class constructor. */ - Indi_CHO(CHOParams &_params) - : params(_params.fast_ma, _params.slow_ma, _params.smooth_method, _params.input_volume), - Indicator((IndicatorParams)_params) { + Indi_CHO(CHOParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_CHO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN, _tf) { params.tf = _tf; }; + Indi_CHO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN, _tf){}; /** * Built-in version of Chaikin Oscillator. @@ -186,9 +178,8 @@ class Indi_CHO : public Indicator { GetInputVolume() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetFastMA(), GetSlowMA(), GetSmoothMethod(), - GetInputVolume() /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetFastMA(), + GetSlowMA(), GetSmoothMethod(), GetInputVolume() /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 976f0def4..8e6304cd3 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -35,23 +35,16 @@ struct CHVParams : IndicatorParams { ENUM_CHV_SMOOTH_METHOD smooth_method; // Struct constructor. void CHVParams(int _smooth_period = 10, int _chv_period = 10, - ENUM_CHV_SMOOTH_METHOD _smooth_method = CHV_SMOOTH_METHOD_EMA, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + ENUM_CHV_SMOOTH_METHOD _smooth_method = CHV_SMOOTH_METHOD_EMA, int _shift = 0) { chv_period = _chv_period; itype = INDI_CHAIKIN_V; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CHV"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; smooth_method = _smooth_method; smooth_period = _smooth_period; - tf = _tf; - }; - void CHVParams(CHVParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -66,11 +59,10 @@ class Indi_CHV : public Indicator { /** * Class constructor. */ - Indi_CHV(CHVParams &_params) - : params(_params.smooth_period, _params.chv_period, _params.smooth_method), Indicator((IndicatorParams)_params) { + Indi_CHV(CHVParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_CHV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN_V, _tf) { params.tf = _tf; }; + Indi_CHV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN_V, _tf){}; /** * Built-in version of Chaikin Volatility. @@ -181,7 +173,7 @@ class Indi_CHV : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: _value = Indi_CHV::iCHV(GetSymbol(), GetTf(), /*[*/ GetSmoothPeriod(), GetCHVPeriod(), GetSmoothMethod() /*]*/, - _mode, _shift); + _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetSmoothPeriod(), diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index b5b27e45f..dce43dddd 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -27,19 +27,13 @@ // Structs. struct ColorBarsParams : IndicatorParams { // Struct constructor. - void ColorBarsParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void ColorBarsParams(int _shift = 0) { itype = INDI_COLOR_BARS; max_modes = 5; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorBars"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void ColorBarsParams(ColorBarsParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -54,8 +48,11 @@ class Indi_ColorBars : public Indicator { /** * Class constructor. */ - Indi_ColorBars(ColorBarsParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ColorBars(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_BARS, _tf) { params.tf = _tf; }; + Indi_ColorBars(ColorBarsParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_ColorBars(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_BARS, _tf){}; /** * "Built-in" version of Color Bars. @@ -126,7 +123,7 @@ class Indi_ColorBars : public Indicator { double _value = EMPTY_VALUE; switch (params.idstype) { case IDATA_BUILTIN: - _value = Indi_ColorBars::iColorBars(GetSymbol(), GetTf(), _mode, _shift, GetPointer(this)); + _value = Indi_ColorBars::iColorBars(GetSymbol(), GetTf(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index d9b6a318a..a8ae4f859 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -27,19 +27,13 @@ // Structs. struct ColorCandlesDailyParams : IndicatorParams { // Struct constructor. - void ColorCandlesDailyParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void ColorCandlesDailyParams(int _shift = 0) { itype = INDI_COLOR_CANDLES_DAILY; max_modes = 5; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorCandlesDaily"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void ColorCandlesDailyParams(ColorCandlesDailyParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -54,10 +48,11 @@ class Indi_ColorCandlesDaily : public Indicator { /** * Class constructor. */ - Indi_ColorCandlesDaily(ColorCandlesDailyParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ColorCandlesDaily(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_CANDLES_DAILY, _tf) { - params.tf = _tf; + Indi_ColorCandlesDaily(ColorCandlesDailyParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { + params = _params; }; + Indi_ColorCandlesDaily(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_CANDLES_DAILY, _tf){}; /** * "Built-in" version of Color Candles Daily. @@ -126,7 +121,7 @@ class Indi_ColorCandlesDaily : public Indicator { double _value = EMPTY_VALUE; switch (params.idstype) { case IDATA_BUILTIN: - _value = Indi_ColorCandlesDaily::iCCD(GetSymbol(), GetTf(), _mode, _shift, GetPointer(this)); + _value = Indi_ColorCandlesDaily::iCCD(GetSymbol(), GetTf(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 2ce89655f..544df7a6b 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -28,19 +28,13 @@ // Structs. struct ColorLineParams : IndicatorParams { // Struct constructor. - void ColorLineParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void ColorLineParams(int _shift = 0) { itype = INDI_COLOR_LINE; max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorLine"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void ColorLineParams(ColorLineParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -55,8 +49,11 @@ class Indi_ColorLine : public Indicator { /** * Class constructor. */ - Indi_ColorLine(ColorLineParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ColorLine(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_LINE, _tf) { params.tf = _tf; }; + Indi_ColorLine(ColorLineParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_ColorLine(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_LINE, _tf){}; /** * "Built-in" version of Color Line. @@ -100,7 +97,7 @@ class Indi_ColorLine : public Indicator { //--- check data int i, calculated = BarsCalculated(ExtMAHandle, rates_total); if (calculated < rates_total) { - Print("Not all data of ExtMAHandle is calculated (", calculated, " bars). Error ", GetLastError()); + // Not all data of ExtMAHandle is calculated. return (0); } //--- first calculation or number of bars was changed @@ -172,11 +169,10 @@ class Indi_ColorLine : public Indicator { double _value = EMPTY_VALUE; switch (params.idstype) { case IDATA_BUILTIN: - _value = Indi_ColorLine::iColorLine(GetSymbol(), GetTf(), _mode, _shift, GetPointer(this)); + _value = Indi_ColorLine::iColorLine(GetSymbol(), GetTf(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index a5dab8e2e..e4e51b19d 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -31,23 +31,16 @@ struct CustomMovingAverageParams : IndicatorParams { ENUM_MA_METHOD smooth_method; // Struct constructor. void CustomMovingAverageParams(int _smooth_period = 13, int _smooth_shift = 0, - ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0) { itype = INDI_CUSTOM_MOVING_AVG; max_modes = 3; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Custom Moving Average"); - SetDataSourceType(IDATA_ICUSTOM); shift = _shift; smooth_method = _smooth_method; smooth_period = _smooth_period; smooth_shift = _smooth_shift; - tf = _tf; - }; - void CustomMovingAverageParams(CustomMovingAverageParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -62,12 +55,11 @@ class Indi_CustomMovingAverage : public Indicator { /** * Class constructor. */ - Indi_CustomMovingAverage(CustomMovingAverageParams &_params) : Indicator((IndicatorParams)_params) { + Indi_CustomMovingAverage(CustomMovingAverageParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_CustomMovingAverage(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CUSTOM_MOVING_AVG, _tf) { - params.tf = _tf; - }; + Indi_CustomMovingAverage(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CUSTOM_MOVING_AVG, _tf){}; /** * Returns the indicator's value. @@ -77,9 +69,8 @@ class Indi_CustomMovingAverage : public Indicator { double _value = EMPTY_VALUE; switch (params.idstype) { case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetSmoothPeriod(), GetSmoothShift(), - GetSmoothMethod() /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetSmoothPeriod(), + GetSmoothShift(), GetSmoothMethod() /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 6e6cb9dc8..4095a4604 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -41,33 +41,14 @@ struct DEMAParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void DEMAParams(unsigned int _period, int _ma_shift, ENUM_APPLIED_PRICE _ap, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) + void DEMAParams(unsigned int _period = 14, int _ma_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), ma_shift(_ma_shift), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_DEMA : itype; - SetDataSourceType(_idstype); + itype = INDI_DEMA; + SetCustomIndicatorName("Examples\\DEMA"); SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetMaxModes(1); SetShift(_shift); - tf = _tf; - switch (idstype) { - case IDATA_ICUSTOM: - if (custom_indi_name == "") { - SetCustomIndicatorName("Examples\\DEMA"); - } - break; - case IDATA_INDICATOR: - if (GetDataSource() == NULL) { - SetDataSource(Indi_Price::GetCached(_shift, _tf, _ap, _period), false); - SetDataSourceMode(0); - } - break; - } - }; - void DEMAParams(DEMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -82,14 +63,8 @@ class Indi_DEMA : public Indicator { /** * Class constructor. */ - Indi_DEMA(DEMAParams &_p) - : params(_p.period, _p.ma_shift, _p.applied_price, _p.shift), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_DEMA(DEMAParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.ma_shift, _p.applied_price, _p.shift), Indicator(INDI_DEMA, _tf) { - params = _p; - } + Indi_DEMA(DEMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_DEMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DEMA, _tf) {} /** * Updates the indicator value. @@ -128,7 +103,7 @@ class Indi_DEMA : public Indicator { } return _res[0]; #else - Indi_Price *_indi_price = Indi_Price::GetCached(_shift, _tf, _applied_price, _period); + Indi_Price *_indi_price = Indi_Price::GetCached(_symbol, _tf, _applied_price, _period, _shift); // Note that _applied_price and Indi_Price mode indices are compatible. return Indi_DEMA::iDEMAOnIndicator(_indi_price.GetCache(), _indi_price, 0, _period, _ma_shift, _shift); #endif @@ -200,14 +175,13 @@ class Indi_DEMA : public Indicator { // We're getting DEMA from Price indicator. istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_DEMA::iDEMA(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetMAShift(), GetAppliedPrice(), _shift, _mode, GetPointer(this)); + _value = Indi_DEMA::iDEMA(GetSymbol(), GetTf(), GetPeriod(), GetMAShift(), GetAppliedPrice(), _shift, _mode, + GetPointer(this)); break; case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = - iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /*[*/ GetPeriod(), GetMAShift(), GetAppliedPrice() /*]*/, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.custom_indi_name, /*[*/ GetPeriod(), GetMAShift(), + GetAppliedPrice() /*]*/, _mode, _shift); break; case IDATA_INDICATOR: // Calculating DEMA value from specified indicator. diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index 56674d3f7..49b590777 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -34,18 +34,15 @@ double iDeMarker(string _symbol, int _tf, int _period, int _shift) { struct DeMarkerParams : IndicatorParams { unsigned int period; // Struct constructors. - void DeMarkerParams(unsigned int _period, int _shift = 0) : period(_period) { + void DeMarkerParams(unsigned int _period = 14, int _shift = 0) : period(_period) { itype = INDI_DEMARKER; max_modes = 1; shift = _shift; + itype = INDI_DEMARKER; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\DeMarker"); }; - void DeMarkerParams(DeMarkerParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -58,10 +55,10 @@ class Indi_DeMarker : public Indicator { /** * Class constructor. */ - Indi_DeMarker(DeMarkerParams &_p) : params(_p.period), Indicator((IndicatorParams)_p) { params = _p; } - Indi_DeMarker(DeMarkerParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.period), Indicator(INDI_DEMARKER, _tf) { + Indi_DeMarker(DeMarkerParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_DeMarker(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DEMARKER, _tf) {} /** * Returns the indicator value. @@ -113,13 +110,11 @@ class Indi_DeMarker : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = _value = - Indi_DeMarker::iDeMarker(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - _shift, GetPointer(this)); + _value = _value = Indi_DeMarker::iDeMarker(GetSymbol(), GetTf(), GetPeriod(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index dce9f8197..e00c65b57 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -33,32 +33,14 @@ // Structs. struct DemoIndiParams : IndicatorParams { // Struct constructors. - void DemoIndiParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) { - itype = itype == INDI_NONE ? INDI_DEMO : itype; + void DemoIndiParams(int _shift = 0) { + itype = INDI_DEMO; max_modes = 1; - SetDataSourceType(_idstype); SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetMaxModes(1); SetShift(_shift); - tf = _tf; - switch (idstype) { - case IDATA_ICUSTOM: - if (custom_indi_name == "") { - SetCustomIndicatorName("Examples\\Demo"); - } - break; - case IDATA_INDICATOR: - if (GetDataSource() == NULL) { - SetDataSource(Indi_Price::GetCached(_shift, _tf), false); - SetDataSourceMode(0); - } - break; - } - }; - void DemoIndiParams(DemoIndiParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; + SetCustomIndicatorName("Examples\\Demo"); }; }; @@ -73,8 +55,10 @@ class Indi_Demo : public Indicator { /** * Class constructor. */ - Indi_Demo(DemoIndiParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_Demo(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : params(_tf), Indicator(INDI_DEMO, _tf){}; + Indi_Demo(DemoIndiParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params) { + params = _params; + }; + Indi_Demo(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DEMO, _tf){}; /** * Initialize indicator data drawing on custom data. @@ -98,8 +82,7 @@ class Indi_Demo : public Indicator { * Returns the indicator's value. */ double GetValue(int _mode = 0, int _shift = 0) { - double _value = Indi_Demo::iDemo(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), _shift, - GetPointer(this)); + double _value = Indi_Demo::iDemo(GetSymbol(), GetTf(), _shift, THIS_PTR); istate.is_ready = true; istate.is_changed = false; if (iparams.is_draw) { diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 47555dec4..c973b8467 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -30,24 +30,15 @@ struct DetrendedPriceParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void DetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void DetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; itype = INDI_DETRENDED_PRICE; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\DPO"); - // INDI_DETRENDED_PRICE[1]: bar 1: 1525392000,130,-0.00001143 - // SetDataSourceType(IDATA_ICUSTOM); - SetDataSourceType(IDATA_BUILTIN); period = _period; shift = _shift; - tf = _tf; - }; - void DetrendedPriceParams(DetrendedPriceParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -62,8 +53,11 @@ class Indi_DetrendedPrice : public Indicator { /** * Class constructor. */ - Indi_DetrendedPrice(DetrendedPriceParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_DetrendedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DETRENDED_PRICE, _tf) { params.tf = _tf; }; + Indi_DetrendedPrice(DetrendedPriceParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params) { + params = _params; + }; + Indi_DetrendedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DETRENDED_PRICE, _tf){}; /** * Built-in version of AMA. diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index d6f81854b..b7455819a 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -50,16 +50,12 @@ class Indi_Drawer : public Indicator { /** * Class constructor. */ - Indi_Drawer(const DrawerParams &_params) : params(_params), Indicator((IndicatorParams)_params), redis(true) { + Indi_Drawer(const DrawerParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf), redis(true) { params = _params; Init(); } - Indi_Drawer(const DrawerParams &_params, ENUM_TIMEFRAMES _tf) - : params(_params), Indicator(INDI_DRAWER, _tf), redis(true) { - // @fixme - params.tf = _tf; - Init(); - } + Indi_Drawer(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DRAWER, _tf), redis(true) { Init(); } void Init() { // Drawer is always ready. @@ -310,18 +306,16 @@ class Indi_Drawer : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_Drawer::iDrawer(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetPeriod(), GetAppliedPrice(), _shift, GetPointer(this)); + _value = Indi_Drawer::iDrawer(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /* [ */ GetPeriod(), GetAppliedPrice() /* ] */, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.custom_indi_name, /* [ */ GetPeriod(), + GetAppliedPrice() /* ] */, 0, _shift); break; case IDATA_INDICATOR: - _value = Indi_Drawer::iDrawerOnIndicator(params.indi_data_source, GetPointer(this), - Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetPeriod(), GetAppliedPrice(), _shift); + _value = Indi_Drawer::iDrawerOnIndicator(params.indi_data_source, THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), + GetAppliedPrice(), _shift); break; } istate.is_changed = false; diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index cfbb402c6..260f6155b 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -35,27 +35,12 @@ struct DrawerParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; - // Struct constructors. - void DrawerParams(const DrawerParams &r) { - period = r.period; - applied_price = r.applied_price; - custom_indi_name = r.custom_indi_name; - } - void DrawerParams(unsigned int _period, ENUM_APPLIED_PRICE _ap) : period(_period), applied_price(_ap) { + DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap) { itype = INDI_DRAWER; max_modes = 0; - custom_indi_name = "Examples\\Drawer"; + SetCustomIndicatorName("Examples\\Drawer"); SetDataValueType(TYPE_DOUBLE); }; - void DrawerParams(DrawerParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - if (idstype == IDATA_INDICATOR && indi_data_source == NULL) { - PriceIndiParams price_params(_tf); - SetDataSource(new Indi_Price(price_params), true); - } - }; - void DrawerParams(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : period(12), applied_price(PRICE_WEIGHTED) { tf = _tf; } // Serializers. SERIALIZER_EMPTY_STUB; SerializerNodeType Serialize(Serializer &s); diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index f1511e886..7890efdae 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -52,22 +52,18 @@ struct EnvelopesParams : IndicatorParams { void EnvelopesParams(int _ma_period = 13, int _ma_shift = 0, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, double _deviation = 2, int _shift = 0) : ma_period(_ma_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_price(_ap), deviation(_deviation) { - itype = INDI_ENVELOPES; #ifdef __MQL5__ // There is no LINE_MAIN in MQL5 for Envelopes. max_modes = 2; #else max_modes = 3; #endif + itype = INDI_ENVELOPES; shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Envelopes"); }; - void EnvelopesParams(EnvelopesParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -82,16 +78,10 @@ class Indi_Envelopes : public Indicator { /** * Class constructor. */ - Indi_Envelopes(EnvelopesParams &_p) - : params(_p.ma_period, _p.ma_shift, _p.ma_method, _p.applied_price, _p.deviation), - Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Envelopes(EnvelopesParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.ma_period, _p.ma_shift, _p.ma_method, _p.applied_price, _p.deviation), - Indicator(INDI_ENVELOPES, _tf) { + Indi_Envelopes(EnvelopesParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_Envelopes(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ENVELOPES, _tf) {} /** * Returns the indicator value. @@ -213,19 +203,17 @@ class Indi_Envelopes : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_Envelopes::iEnvelopes(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetMAPeriod(), GetMAMethod(), GetMAShift(), GetAppliedPrice(), - GetDeviation(), _mode, _shift, GetPointer(this)); + _value = Indi_Envelopes::iEnvelopes(GetSymbol(), GetTf(), GetMAPeriod(), GetMAMethod(), GetMAShift(), + GetAppliedPrice(), GetDeviation(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /**/ GetMAPeriod(), GetMAMethod(), GetMAShift(), - GetAppliedPrice(), GetDeviation() /**/, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /**/ GetMAPeriod(), + GetMAMethod(), GetMAShift(), GetAppliedPrice(), GetDeviation() /**/, _mode, _shift); break; case IDATA_INDICATOR: - _value = Indi_Envelopes::iEnvelopesOnIndicator( - GetCache(), GetDataSource(), Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetMAPeriod(), GetMAMethod(), GetDataSourceMode(), GetMAShift(), GetDeviation(), _mode, _shift); + _value = Indi_Envelopes::iEnvelopesOnIndicator(GetCache(), GetDataSource(), GetSymbol(), GetTf(), GetMAPeriod(), + GetMAMethod(), GetDataSourceMode(), GetMAShift(), GetDeviation(), + _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index bc986d20d..4d251749e 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -48,7 +48,8 @@ struct ForceParams : IndicatorParams { ENUM_MA_METHOD ma_method; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void ForceParams(unsigned int _period, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _ap, int _shift = 0) + void ForceParams(unsigned int _period = 13, ENUM_MA_METHOD _ma_method = MODE_SMA, + ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), ma_method(_ma_method), applied_price(_ap) { itype = INDI_FORCE; max_modes = 1; @@ -57,10 +58,6 @@ struct ForceParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Force_Index"); }; - void ForceParams(ForceParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -75,13 +72,10 @@ class Indi_Force : public Indicator { /** * Class constructor. */ - Indi_Force(ForceParams &_p) : params(_p.period, _p.ma_method, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Force(ForceParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.ma_method, _p.applied_price), Indicator(INDI_FORCE, _tf) { + Indi_Force(ForceParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_Force(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FORCE, _tf) {} /** * Returns the indicator value. @@ -133,13 +127,12 @@ class Indi_Force : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_Force::iForce(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetMAMethod(), GetAppliedPrice(), _shift, GetPointer(this)); + _value = + Indi_Force::iForce(GetSymbol(), GetTf(), GetPeriod(), GetMAMethod(), GetAppliedPrice(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod(), GetMAMethod(), GetAppliedPrice(), - VOLUME_TICK /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod(), + GetMAMethod(), GetAppliedPrice(), VOLUME_TICK /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 8d50fe775..5a05699b7 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -31,8 +31,7 @@ struct FrIndiAMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void FrIndiAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void FrIndiAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { frama_shift = _frama_shift; itype = INDI_FRAMA; max_modes = 1; @@ -42,11 +41,6 @@ struct FrIndiAMAParams : IndicatorParams { applied_price = _ap; period = _period; shift = _shift; - tf = _tf; - }; - void FrIndiAMAParams(FrIndiAMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -61,11 +55,11 @@ class Indi_FrAMA : public Indicator { /** * Class constructor. */ - Indi_FrAMA(FrIndiAMAParams &_params) - : params(_params.period, _params.frama_shift), Indicator((IndicatorParams)_params) { + Indi_FrAMA(FrIndiAMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_FrAMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FRAMA, _tf) { params.tf = _tf; }; + Indi_FrAMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FRAMA, _tf){}; /** * Built-in version of FrAMA. diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index ff41504d7..a92758a89 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -33,18 +33,13 @@ double iFractals(string _symbol, int _tf, int _mode, int _shift) { // Structs. struct FractalsParams : IndicatorParams { // Struct constructors. - void FractalsParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void FractalsParams(int _shift = 0) { itype = INDI_FRACTALS; max_modes = FINAL_LO_UP_LINE_ENTRY; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_ARROW); SetCustomIndicatorName("Examples\\Fractals"); shift = _shift; - tf = _tf; - }; - void FractalsParams(FractalsParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -59,7 +54,9 @@ class Indi_Fractals : public Indicator { /** * Class constructor. */ - Indi_Fractals(IndicatorParams &_p) : Indicator((IndicatorParams)_p) {} + Indi_Fractals(IndicatorParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { + params = _p; + } Indi_Fractals(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FRACTALS, _tf) {} /** @@ -114,12 +111,10 @@ class Indi_Fractals : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = _value = Indi_Fractals::iFractals( - Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), _mode, _shift, GetPointer(this)); + _value = _value = Indi_Fractals::iFractals(GetSymbol(), GetTf(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index 6a02f8473..606c15aa7 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -78,8 +78,8 @@ struct GatorParams : IndicatorParams { ENUM_MA_METHOD ma_method; // Averaging method. ENUM_APPLIED_PRICE applied_price; // Applied price. // Struct constructors. - void GatorParams(int _jp, int _js, int _tp, int _ts, int _lp, int _ls, ENUM_MA_METHOD _mm, ENUM_APPLIED_PRICE _ap, - int _shift = 0) + void GatorParams(int _jp = 13, int _js = 8, int _tp = 8, int _ts = 5, int _lp = 5, int _ls = 3, + ENUM_MA_METHOD _mm = MODE_SMMA, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN, int _shift = 0) : jaw_period(_jp), jaw_shift(_js), teeth_period(_tp), @@ -95,10 +95,6 @@ struct GatorParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Gator"); }; - void GatorParams(GatorParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -112,18 +108,10 @@ class Indi_Gator : public Indicator { /** * Class constructor. */ - Indi_Gator(GatorParams &_p) - : params(_p.jaw_period, _p.jaw_shift, _p.teeth_period, _p.teeth_shift, _p.lips_period, _p.lips_shift, - _p.ma_method, _p.applied_price), - Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Gator(GatorParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.jaw_period, _p.jaw_shift, _p.teeth_period, _p.teeth_shift, _p.lips_period, _p.lips_shift, - _p.ma_method, _p.applied_price), - Indicator(INDI_GATOR, _tf) { + Indi_Gator(GatorParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_Gator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_GATOR, _tf) {} /** * Returns the indicator value. @@ -190,13 +178,12 @@ class Indi_Gator : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_Gator::iGator(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), GetLipsPeriod(), - GetLipsShift(), GetMAMethod(), GetAppliedPrice(), _mode, _shift, GetPointer(this)); + _value = Indi_Gator::iGator(GetSymbol(), GetTf(), GetJawPeriod(), GetJawShift(), GetTeethPeriod(), + GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), GetAppliedPrice(), + _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /**/ + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /**/ GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), GetAppliedPrice() diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index da1b11af2..efba05c71 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -49,23 +49,17 @@ enum ENUM_HA_MODE { // Structs. struct HeikenAshiParams : IndicatorParams { // Struct constructors. - void HeikenAshiParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void HeikenAshiParams(int _shift = 0) { itype = INDI_HEIKENASHI; max_modes = FINAL_HA_MODE_ENTRY; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); // @fixit It draws candles! - SetDataSourceType(IDATA_BUILTIN); #ifdef __MQL4__ SetCustomIndicatorName("Heiken Ashi"); #else SetCustomIndicatorName("Examples\\Heiken_Ashi"); #endif shift = _shift; - tf = _tf; - }; - void HeikenAshiParams(HeikenAshiParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -80,7 +74,9 @@ class Indi_HeikenAshi : public Indicator { /** * Class constructor. */ - Indi_HeikenAshi(IndicatorParams &_p) : Indicator((IndicatorParams)_p) {} + Indi_HeikenAshi(IndicatorParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { + params = _p; + } Indi_HeikenAshi(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_HEIKENASHI, _tf) {} /** @@ -167,8 +163,8 @@ class Indi_HeikenAshi : public Indicator { /** * OnCalculate() method for Mass Index indicator. */ - static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtOBuffer, - ValueStorage &ExtHBuffer, ValueStorage &ExtLBuffer, + static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtLBuffer, + ValueStorage &ExtHBuffer, ValueStorage &ExtOBuffer, ValueStorage &ExtCBuffer, ValueStorage &ExtColorBuffer) { int start; //--- preliminary calculations @@ -211,7 +207,7 @@ class Indi_HeikenAshi : public Indicator { double _value = EMPTY_VALUE; switch (params.idstype) { case IDATA_BUILTIN: - _value = Indi_HeikenAshi::iHeikenAshi(GetSymbol(), GetTf(), _mode, _shift, GetPointer(this)); + _value = Indi_HeikenAshi::iHeikenAshi(GetSymbol(), GetTf(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); @@ -219,7 +215,7 @@ class Indi_HeikenAshi : public Indicator { case IDATA_ICUSTOM_LEGACY: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_HeikenAshi::iCustomLegacyHeikenAshi(GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, - _shift, GetPointer(this)); + _shift, THIS_PTR); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index f58d56d5b..b0391b465 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -67,7 +67,7 @@ struct IchimokuParams : IndicatorParams { unsigned int kijun_sen; unsigned int senkou_span_b; // Struct constructors. - void IchimokuParams(unsigned int _ts, unsigned int _ks, unsigned int _ss_b, int _shift = 0) + void IchimokuParams(unsigned int _ts = 9, unsigned int _ks = 26, unsigned int _ss_b = 52, int _shift = 0) : tenkan_sen(_ts), kijun_sen(_ks), senkou_span_b(_ss_b) { itype = INDI_ICHIMOKU; max_modes = FINAL_ICHIMOKU_LINE_ENTRY; @@ -76,10 +76,6 @@ struct IchimokuParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Not sure if not mixed. SetCustomIndicatorName("Examples\\Ichimoku"); }; - void IchimokuParams(IchimokuParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -93,14 +89,10 @@ class Indi_Ichimoku : public Indicator { /** * Class constructor. */ - Indi_Ichimoku(IchimokuParams &_p) - : params(_p.tenkan_sen, _p.kijun_sen, _p.senkou_span_b), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Ichimoku(IchimokuParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.tenkan_sen, _p.kijun_sen, _p.senkou_span_b), Indicator(INDI_ICHIMOKU, _tf) { + Indi_Ichimoku(IchimokuParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_Ichimoku(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ICHIMOKU, _tf) {} /** * Returns the indicator value. @@ -156,14 +148,12 @@ class Indi_Ichimoku : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = - Indi_Ichimoku::iIchimoku(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetTenkanSen(), GetKijunSen(), GetSenkouSpanB(), _mode, _shift, GetPointer(this)); + _value = Indi_Ichimoku::iIchimoku(GetSymbol(), GetTf(), GetTenkanSen(), GetKijunSen(), GetSenkouSpanB(), _mode, + _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetTenkanSen(), GetKijunSen(), GetSenkouSpanB() /*]*/, - _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetTenkanSen(), + GetKijunSen(), GetSenkouSpanB() /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index d76c0ea8a..235a32714 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -62,10 +62,6 @@ struct MAParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Moving Average"); }; - void MAParams(MAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -79,13 +75,8 @@ class Indi_MA : public Indicator { /** * Class constructor. */ - Indi_MA(MAParams &_p) : params(_p.period, _p.shift, _p.ma_method, _p.applied_array), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_MA(MAParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.shift, _p.ma_method, _p.applied_array), Indicator(INDI_MA, _tf) { - params = _p; - } + Indi_MA(MAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_MA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_MA, _tf) {} /** * Returns the indicator value. @@ -641,19 +632,17 @@ class Indi_MA : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_MA::iMA(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetMAShift(), GetMAMethod(), GetAppliedPrice(), _shift, GetPointer(this)); + _value = Indi_MA::iMA(GetSymbol(), GetTf(), GetPeriod(), GetMAShift(), GetMAMethod(), GetAppliedPrice(), _shift, + THIS_PTR); break; case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /* [ */ GetPeriod(), GetMAShift(), GetMAMethod(), - GetAppliedPrice() /* ] */, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.custom_indi_name, /* [ */ GetPeriod(), + GetMAShift(), GetMAMethod(), GetAppliedPrice() /* ] */, 0, _shift); break; case IDATA_INDICATOR: // Calculating MA value from specified indicator. - _value = Indi_MA::iMAOnIndicator(GetCache(), GetDataSource(), GetDataSourceMode(), - Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), + _value = Indi_MA::iMAOnIndicator(GetCache(), GetDataSource(), GetDataSourceMode(), GetSymbol(), GetTf(), GetPeriod(), GetMAShift(), GetMAMethod(), _shift); break; } diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index e4caca10d..e53c2817c 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -38,7 +38,8 @@ struct MACDParams : IndicatorParams { unsigned int signal_period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void MACDParams(unsigned int _efp, unsigned int _esp, unsigned int _sp, ENUM_APPLIED_PRICE _ap, int _shift = 0) + void MACDParams(unsigned int _efp = 12, unsigned int _esp = 26, unsigned int _sp = 9, + ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : ema_fast_period(_efp), ema_slow_period(_esp), signal_period(_sp), applied_price(_ap) { itype = INDI_MACD; max_modes = FINAL_SIGNAL_LINE_ENTRY; @@ -47,10 +48,6 @@ struct MACDParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\MACD"); }; - void MACDParams(MACDParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -64,15 +61,8 @@ class Indi_MACD : public Indicator { /** * Class constructor. */ - Indi_MACD(MACDParams &_p) - : params(_p.ema_fast_period, _p.ema_slow_period, _p.signal_period, _p.applied_price), - Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_MACD(MACDParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.ema_fast_period, _p.ema_slow_period, _p.signal_period, _p.applied_price), Indicator(INDI_MACD, _tf) { - params = _p; - } + Indi_MACD(MACDParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_MACD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_MACD, _tf) {} /** * Returns the indicator value. @@ -128,14 +118,12 @@ class Indi_MACD : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = - Indi_MACD::iMACD(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetEmaFastPeriod(), - GetEmaSlowPeriod(), GetSignalPeriod(), GetAppliedPrice(), _mode, _shift, GetPointer(this)); + _value = Indi_MACD::iMACD(GetSymbol(), GetTf(), GetEmaFastPeriod(), GetEmaSlowPeriod(), GetSignalPeriod(), + GetAppliedPrice(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetEmaFastPeriod(), GetEmaSlowPeriod(), - GetSignalPeriod(), GetAppliedPrice() /*]*/, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetEmaFastPeriod(), + GetEmaSlowPeriod(), GetSignalPeriod(), GetAppliedPrice() /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index 21db3bc2d..39045a780 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -35,7 +35,7 @@ struct MFIParams : IndicatorParams { unsigned int ma_period; ENUM_APPLIED_VOLUME applied_volume; // Ignored in MT4. // Struct constructors. - void MFIParams(unsigned int _ma_period, ENUM_APPLIED_VOLUME _av = NULL, int _shift = 0) + void MFIParams(unsigned int _ma_period = 14, ENUM_APPLIED_VOLUME _av = VOLUME_TICK, int _shift = 0) : ma_period(_ma_period), applied_volume(_av) { itype = INDI_MFI; max_modes = 1; @@ -44,10 +44,6 @@ struct MFIParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\MFI"); }; - void MFIParams(MFIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -61,10 +57,8 @@ class Indi_MFI : public Indicator { /** * Class constructor. */ - Indi_MFI(MFIParams &_p) : params(_p.ma_period, _p.applied_volume), Indicator((IndicatorParams)_p) { params = _p; } - Indi_MFI(MFIParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.ma_period, _p.applied_volume), Indicator(INDI_MFI, _tf) { - params = _p; - } + Indi_MFI(MFIParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_MFI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_MFI, _tf) {} /** * Calculates the Money Flow Index indicator and returns its value. @@ -126,16 +120,14 @@ class Indi_MFI : public Indicator { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; #ifdef __MQL4__ - _value = - Indi_MFI::iMFI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), _shift); + _value = Indi_MFI::iMFI(GetSymbol(), GetTf(), GetPeriod(), _shift); #else // __MQL5__ - _value = Indi_MFI::iMFI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetAppliedVolume(), _shift, GetPointer(this)); + _value = Indi_MFI::iMFI(GetSymbol(), GetTf(), GetPeriod(), GetAppliedVolume(), _shift, THIS_PTR); #endif break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod(), VOLUME_TICK /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod(), + VOLUME_TICK /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index ad1ecc29b..c5b919bb4 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -31,8 +31,7 @@ struct MassIndexParams : IndicatorParams { int second_period; int sum_period; // Struct constructor. - void MassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void MassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0) { itype = INDI_MASS_INDEX; max_modes = 1; period = _period; @@ -40,14 +39,8 @@ struct MassIndexParams : IndicatorParams { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\MI"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; sum_period = _sum_period; - tf = _tf; - }; - void MassIndexParams(MassIndexParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -62,11 +55,11 @@ class Indi_MassIndex : public Indicator { /** * Class constructor. */ - Indi_MassIndex(MassIndexParams &_params) - : params(_params.period, _params.second_period, _params.sum_period), Indicator((IndicatorParams)_params) { + Indi_MassIndex(MassIndexParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_MassIndex(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_MASS_INDEX, _tf) { params.tf = _tf; }; + Indi_MassIndex(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_MASS_INDEX, _tf){}; /** * Built-in version of Mass Index. diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index c93f435d5..a9cb35f8b 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -54,10 +54,6 @@ struct MomentumParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Momentum"); }; - void MomentumParams(MomentumParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -71,13 +67,10 @@ class Indi_Momentum : public Indicator { /** * Class constructor. */ - Indi_Momentum(MomentumParams &_p) : params(_p.period, _p.applied_price, _p.shift), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Momentum(MomentumParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.applied_price, _p.shift), Indicator(INDI_MOMENTUM, _tf) { + Indi_Momentum(MomentumParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_Momentum(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_MOMENTUM, _tf) {} /** * Returns the indicator value. @@ -158,19 +151,18 @@ class Indi_Momentum : public Indicator { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; // @fixit Somehow shift isn't used neither in MT4 nor MT5. - _value = Indi_Momentum::iMomentum(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetPeriod(), GetAppliedPrice(), params.shift + _shift, GetPointer(this)); + _value = Indi_Momentum::iMomentum(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), params.shift + _shift, + THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + 0, _shift); break; case IDATA_INDICATOR: ValidateSelectedDataSource(); // @fixit Somehow shift isn't used neither in MT4 nor MT5. - _value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), Get(CHART_PARAM_SYMBOL), - Get(CHART_PARAM_TF), GetPeriod(), + _value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), GetDataSourceMode(), params.shift + _shift); if (iparams.is_draw) { draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(params.shift + _shift), _value, 1); diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 2ba02b584..1550fbf05 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -57,10 +57,6 @@ struct OBVParams : IndicatorParams { shift = _shift; SetDataValueType(TYPE_DOUBLE); }; - void OBVParams(OBVParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -74,22 +70,13 @@ class Indi_OBV : public Indicator { /** * Class constructor. */ - Indi_OBV(OBVParams &_p) -#ifdef __MQL4__ - : params(_p.applied_price), -#else - : params(_p.applied_volume), -#endif - Indicator((IndicatorParams)_p) { - } - Indi_OBV(OBVParams &_p, ENUM_TIMEFRAMES _tf) + Indi_OBV(OBVParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) #ifdef __MQL4__ : params(_p.applied_price), #else : params(_p.applied_volume), #endif - Indicator(INDI_OBV, _tf) { - params = _p; + Indicator((IndicatorParams)_p, _tf) { } Indi_OBV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_OBV, _tf) {} @@ -149,16 +136,14 @@ class Indi_OBV : public Indicator { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; #ifdef __MQL4__ - _value = Indi_OBV::iOBV(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetAppliedPrice(), _shift); + _value = Indi_OBV::iOBV(GetSymbol(), GetTf(), GetAppliedPrice(), _shift); #else // __MQL5__ - _value = Indi_OBV::iOBV(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetAppliedVolume(), _shift, GetPointer(this)); + _value = Indi_OBV::iOBV(GetSymbol(), GetTf(), GetAppliedVolume(), _shift, THIS_PTR); #endif break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ VOLUME_TICK /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ VOLUME_TICK /*]*/, + 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 8acf31092..0aa42fcfb 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -38,7 +38,7 @@ struct OsMAParams : IndicatorParams { int signal_period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void OsMAParams(int _efp, int _esp, int _sp, ENUM_APPLIED_PRICE _ap, int _shift = 0) + void OsMAParams(int _efp = 12, int _esp = 26, int _sp = 9, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : ema_fast_period(_efp), ema_slow_period(_esp), signal_period(_sp), applied_price(_ap) { itype = INDI_OSMA; max_modes = 1; @@ -47,10 +47,6 @@ struct OsMAParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\OsMA"); }; - void OsMAParams(OsMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -64,15 +60,8 @@ class Indi_OsMA : public Indicator { /** * Class constructor. */ - Indi_OsMA(OsMAParams &_p) - : params(_p.ema_fast_period, _p.ema_slow_period, _p.signal_period, _p.applied_price), - Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_OsMA(OsMAParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.ema_fast_period, _p.ema_slow_period, _p.signal_period, _p.applied_price), Indicator(INDI_OSMA, _tf) { - params = _p; - } + Indi_OsMA(OsMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_OsMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_OSMA, _tf) {} /** * Returns the indicator value. @@ -125,14 +114,12 @@ class Indi_OsMA : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = - Indi_OsMA::iOsMA(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetEmaFastPeriod(), - GetEmaSlowPeriod(), GetSignalPeriod(), GetAppliedPrice(), _shift, GetPointer(this)); + _value = Indi_OsMA::iOsMA(GetSymbol(), GetTf(), GetEmaFastPeriod(), GetEmaSlowPeriod(), GetSignalPeriod(), + GetAppliedPrice(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetEmaFastPeriod(), GetEmaSlowPeriod(), - GetSignalPeriod(), GetAppliedPrice() /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetEmaFastPeriod(), + GetEmaSlowPeriod(), GetSignalPeriod(), GetAppliedPrice() /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index 6ddd9d8f7..5c58a53a5 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -32,18 +32,12 @@ // Structs. struct IndiPatternParams : IndicatorParams { // Struct constructor. - void IndiPatternParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void IndiPatternParams(int _shift = 0) { itype = INDI_PATTERN; max_modes = 5; SetDataValueType(TYPE_INT); SetDataValueRange(IDATA_RANGE_BITWISE); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void IndiPatternParams(IndiPatternParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -58,8 +52,10 @@ class Indi_Pattern : public Indicator { /** * Class constructor. */ - Indi_Pattern(IndiPatternParams &_params) : params(_params), Indicator((IndicatorParams)_params){}; - Indi_Pattern(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PATTERN, _tf) { params.tf = _tf; }; + Indi_Pattern(IndiPatternParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p) { + params = _p; + }; + Indi_Pattern(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PATTERN, _tf){}; /** * Returns the indicator's struct value. diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index a0830313b..3ec1f259a 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -30,19 +30,13 @@ struct IndiPivotParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) { itype = INDI_PIVOT; max_modes = 9; method = _method; SetDataValueType(TYPE_FLOAT); SetDataValueRange(IDATA_RANGE_MIXED); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void IndiPivotParams(IndiPivotParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -57,8 +51,10 @@ class Indi_Pivot : public Indicator { /** * Class constructor. */ - Indi_Pivot(IndiPivotParams &_params) : params(_params), Indicator((IndicatorParams)_params){}; - Indi_Pivot(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PIVOT, _tf) { params.tf = _tf; }; + Indi_Pivot(IndiPivotParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p) { + params = _p; + }; + Indi_Pivot(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PIVOT, _tf){}; /** * Returns the indicator's struct value. diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index 0c426d842..080361140 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -41,13 +41,11 @@ struct PriceIndiParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void PriceIndiParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN) - : applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_PRICE : itype; + void PriceIndiParams(int _shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN) : applied_price(_ap) { + itype = INDI_PRICE; max_modes = FINAL_INDI_PRICE_MODE; SetDataValueType(TYPE_DOUBLE); SetShift(_shift); - tf = _tf; }; }; @@ -62,9 +60,11 @@ class Indi_Price : public Indicator { /** * Class constructor. */ - Indi_Price(PriceIndiParams &_p) : Indicator((IndicatorParams)_p) { params = _p; }; - Indi_Price(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN) - : params(_shift, _tf, _ap), Indicator(INDI_PRICE, _tf){}; + Indi_Price(PriceIndiParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_Price(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE, _tf){}; /** * Returns the indicator value. @@ -84,8 +84,7 @@ class Indi_Price : public Indicator { * Returns the indicator's value. */ double GetValue(ENUM_APPLIED_PRICE _ap, int _shift = 0) { - double _value = - ChartStatic::iPrice(_ap, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), _shift); + double _value = ChartStatic::iPrice(_ap, GetSymbol(), GetTf(), _shift); istate.is_ready = true; istate.is_changed = false; return _value; @@ -125,18 +124,20 @@ class Indi_Price : public Indicator { /** * Returns already cached version of Indi_Price for a given parameters. */ - static Indi_Price *GetCached(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, - ENUM_APPLIED_PRICE _applied_price = PRICE_TYPICAL, unsigned int _period = 0) { + static Indi_Price *GetCached(string _symbol, ENUM_TIMEFRAMES _tf, ENUM_APPLIED_PRICE _applied_price, + unsigned int _period, int _shift) { String _cache_key; - _cache_key.Add((int)_shift); + _cache_key.Add(_symbol); _cache_key.Add((int)_tf); - _cache_key.Add((int)_period); + _cache_key.Add(_period); _cache_key.Add((int)_applied_price); + _cache_key.Add(_shift); string _key = _cache_key.ToString(); Indi_Price *_indi_price; if (!Objects::TryGet(_key, _indi_price)) { - PriceIndiParams _indi_price_params(_shift, _tf, _applied_price); - _indi_price = Objects::Set(_key, new Indi_Price(_indi_price_params)); + PriceIndiParams _indi_price_params(_shift, _applied_price); + _indi_price = Objects::Set(_key, new Indi_Price(_indi_price_params, _tf)); + _indi_price.SetSymbol(_symbol); } return _indi_price; } diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index b0c6d950e..79827ca55 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -28,7 +28,7 @@ struct PriceChannelParams : IndicatorParams { unsigned int period; // Struct constructor. - void PriceChannelParams(unsigned int _period = 22, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void PriceChannelParams(unsigned int _period = 22, int _shift = 0) { itype = INDI_PRICE_CHANNEL; max_modes = 3; period = _period; @@ -37,11 +37,6 @@ struct PriceChannelParams : IndicatorParams { SetCustomIndicatorName("Examples\\Price_Channel"); SetDataSourceType(IDATA_ICUSTOM); shift = _shift; - tf = _tf; - }; - void PriceChannelParams(PriceChannelParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -56,10 +51,11 @@ class Indi_PriceChannel : public Indicator { /** * Class constructor. */ - Indi_PriceChannel(PriceChannelParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { + Indi_PriceChannel(PriceChannelParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_PriceChannel(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_CHANNEL, _tf) { params.tf = _tf; }; + Indi_PriceChannel(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_CHANNEL, _tf){}; /** * Returns the indicator's value. @@ -69,8 +65,8 @@ class Indi_PriceChannel : public Indicator { double _value = EMPTY_VALUE; switch (params.idstype) { case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index 1173d01eb..2ec8b51e0 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -32,12 +32,11 @@ struct PriceFeederIndiParams : IndicatorParams { /** * Struct constructor. */ - void PriceFeederIndiParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void PriceFeederIndiParams(int _shift = 0) { itype = INDI_PRICE_FEEDER; max_modes = 1; SetDataValueType(TYPE_DOUBLE); shift = _shift; - tf = _tf; } /** @@ -65,7 +64,10 @@ class Indi_PriceFeeder : public Indicator { /** * Class constructor. */ - Indi_PriceFeeder(PriceFeederIndiParams& _p) : Indicator((IndicatorParams)_p) { params = _p; }; + Indi_PriceFeeder(PriceFeederIndiParams& _params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; Indi_PriceFeeder(const double& _price_data[], int _total = 0) : params(_price_data, _total), Indicator(INDI_PRICE_FEEDER){}; diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index 4d54beb36..34e0c4777 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -28,21 +28,14 @@ struct PriceVolumeTrendParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void PriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void PriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { applied_volume = _applied_volume; itype = INDI_PRICE_VOLUME_TREND; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\PVT"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void PriceVolumeTrendParams(PriceVolumeTrendParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -57,13 +50,11 @@ class Indi_PriceVolumeTrend : public Indicator { /** * Class constructor. */ - Indi_PriceVolumeTrend(PriceVolumeTrendParams &_params) - : params(_params.applied_volume), Indicator((IndicatorParams)_params) { + Indi_PriceVolumeTrend(PriceVolumeTrendParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_PriceVolumeTrend(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_VOLUME_TREND, _tf) { - params.tf = _tf; - }; + Indi_PriceVolumeTrend(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_VOLUME_TREND, _tf){}; /** * Built-in version of Price Volume Trend. diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index 48eece0ae..6c6613111 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -30,8 +30,7 @@ struct RSParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { applied_volume = _applied_volume; itype = INDI_RS; max_modes = 2; @@ -39,11 +38,6 @@ struct RSParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_MATH); shift = _shift; - tf = _tf; - }; - void RSParams(RSParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -60,11 +54,11 @@ class Indi_RS : public Indicator { /** * Class constructor. */ - Indi_RS(RSParams &_params) : params(_params), Indicator((IndicatorParams)_params) { Init(); }; - Indi_RS(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RS, _tf) { - params.tf = _tf; + Indi_RS(RSParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { + params = _params; Init(); }; + Indi_RS(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RS, _tf) { Init(); }; void Init() { if (params.GetDataSourceType() == IDATA_MATH) { diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index ce168bf34..3072037a8 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -46,12 +46,6 @@ struct RSIParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; - // Struct constructors. - void RSIParams(const RSIParams &r) { - period = r.period; - applied_price = r.applied_price; - custom_indi_name = r.custom_indi_name; - } void RSIParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : period(_period), applied_price(_ap) { itype = INDI_RSI; @@ -61,11 +55,6 @@ struct RSIParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\RSI"); }; - void RSIParams(RSIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; - void RSIParams(ENUM_TIMEFRAMES _tf) : period(12), applied_price(PRICE_WEIGHTED) { tf = _tf; } // Serializers. SERIALIZER_EMPTY_STUB; SerializerNodeType Serialize(Serializer &s) { @@ -95,11 +84,10 @@ class Indi_RSI : public Indicator { /** * Class constructor. */ - Indi_RSI(const RSIParams &_params) : params(_params), Indicator((IndicatorParams)_params) { params = _params; } - Indi_RSI(const RSIParams &_params, ENUM_TIMEFRAMES _tf) : params(_params), Indicator(INDI_RSI, _tf) { - // @fixme - params.tf = _tf; + Indi_RSI(const RSIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { + params = _params; } + Indi_RSI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RSI, _tf) {} /** * Returns the indicator value. @@ -321,18 +309,16 @@ class Indi_RSI : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_RSI::iRSI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetAppliedPrice(), _shift, GetPointer(this)); + _value = Indi_RSI::iRSI(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /* [ */ GetPeriod(), GetAppliedPrice() /* ] */, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.custom_indi_name, /* [ */ GetPeriod(), + GetAppliedPrice() /* ] */, 0, _shift); break; case IDATA_INDICATOR: - _value = - Indi_RSI::iRSIOnIndicator(GetDataSource(), GetPointer(this), Get(CHART_PARAM_SYMBOL), - Get(CHART_PARAM_TF), GetPeriod(), GetAppliedPrice(), _shift); + _value = Indi_RSI::iRSIOnIndicator(GetDataSource(), THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), + GetAppliedPrice(), _shift); break; } istate.is_ready = GetLastError() == ERR_NO_ERROR; diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index 3052880cd..334967117 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -34,7 +34,7 @@ double iRVI(string _symbol, int _tf, int _period, int _mode, int _shift) { struct RVIParams : IndicatorParams { unsigned int period; // Struct constructors. - void RVIParams(unsigned int _period, int _shift = 0) : period(_period) { + void RVIParams(unsigned int _period = 10, int _shift = 0) : period(_period) { itype = INDI_RVI; max_modes = FINAL_SIGNAL_LINE_ENTRY; shift = _shift; @@ -42,10 +42,6 @@ struct RVIParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\RVI"); }; - void RVIParams(RVIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -59,8 +55,10 @@ class Indi_RVI : public Indicator { /** * Class constructor. */ - Indi_RVI(const RVIParams &_p) : params(_p.period), Indicator((IndicatorParams)_p) { params = _p; } - Indi_RVI(const RVIParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.period), Indicator(INDI_RVI, _tf) { params = _p; } + Indi_RVI(const RVIParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { + params = _p; + } + Indi_RVI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RVI, _tf) {} /** * Returns the indicator value. @@ -114,12 +112,11 @@ class Indi_RVI : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_RVI::iRVI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - _mode, _shift, GetPointer(this)); + _value = Indi_RVI::iRVI(GetSymbol(), GetTf(), GetPeriod(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index f2336fde2..80b714eee 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -29,22 +29,15 @@ struct RateOfChangeParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void RateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void RateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; itype = INDI_RATE_OF_CHANGE; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ROC"); - SetDataSourceType(IDATA_BUILTIN); period = _period; shift = _shift; - tf = _tf; - }; - void RateOfChangeParams(RateOfChangeParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -59,10 +52,11 @@ class Indi_RateOfChange : public Indicator { /** * Class constructor. */ - Indi_RateOfChange(RateOfChangeParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { + Indi_RateOfChange(RateOfChangeParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_RateOfChange(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RATE_OF_CHANGE, _tf) { params.tf = _tf; }; + Indi_RateOfChange(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RATE_OF_CHANGE, _tf){}; /** * Built-in version of Rate of Change. diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 71ea42780..48104be63 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -43,10 +43,6 @@ struct SARParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); // @fixit It draws single dot for each bar! SetCustomIndicatorName("Examples\\ParabolicSAR"); }; - void SARParams(SARParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -60,8 +56,8 @@ class Indi_SAR : public Indicator { /** * Class constructor. */ - Indi_SAR(SARParams &_p) : params(_p.step, _p.max), Indicator((IndicatorParams)_p) { params = _p; } - Indi_SAR(SARParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.step, _p.max), Indicator(INDI_SAR, _tf) { params = _p; } + Indi_SAR(SARParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_SAR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_SAR, _tf) {} /** * Returns the indicator value. @@ -113,12 +109,11 @@ class Indi_SAR : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_SAR::iSAR(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetStep(), - GetMax(), _shift, GetPointer(this)); + _value = Indi_SAR::iSAR(GetSymbol(), GetTf(), GetStep(), GetMax(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetStep(), GetMax() /*]*/, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetStep(), + GetMax() /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index b0d0cb1c6..f35a981c3 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -60,10 +60,6 @@ struct StdDevParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\StdDev"); }; - void StdDevParams(StdDevParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -77,14 +73,10 @@ class Indi_StdDev : public Indicator { /** * Class constructor. */ - Indi_StdDev(StdDevParams &_p) - : params(_p.ma_period, _p.ma_shift, _p.ma_method, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_StdDev(StdDevParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.ma_period, _p.ma_shift, _p.ma_method, _p.applied_price), Indicator(INDI_STDDEV, _tf) { + Indi_StdDev(StdDevParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_StdDev(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_STDDEV, _tf) {} /** * Calculates the Standard Deviation indicator and returns its value. @@ -224,9 +216,8 @@ class Indi_StdDev : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = - Indi_StdDev::iStdDev(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetMAPeriod(), - GetMAShift(), GetMAMethod(), GetAppliedPrice(), _shift, GetPointer(this)); + _value = Indi_StdDev::iStdDev(GetSymbol(), GetTf(), GetMAPeriod(), GetMAShift(), GetMAMethod(), + GetAppliedPrice(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = @@ -234,9 +225,8 @@ class Indi_StdDev : public Indicator { params.GetCustomIndicatorName(), /*[*/ GetMAPeriod(), GetMAShift(), GetMAMethod() /*]*/, 0, _shift); break; case IDATA_INDICATOR: - _value = Indi_StdDev::iStdDevOnIndicator(GetDataSource(), Get(CHART_PARAM_SYMBOL), - Get(CHART_PARAM_TF), GetMAPeriod(), GetMAShift(), - GetAppliedPrice(), _shift, GetPointer(this)); + _value = Indi_StdDev::iStdDevOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetMAPeriod(), GetMAShift(), + GetAppliedPrice(), _shift, THIS_PTR); break; } istate.is_ready = _LastError == ERR_NO_ERROR; diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 9c9908f86..1da0f24cd 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -40,8 +40,8 @@ struct StochParams : IndicatorParams { ENUM_MA_METHOD ma_method; ENUM_STO_PRICE price_field; // Struct constructors. - void StochParams(int _kperiod, int _dperiod, int _slowing, ENUM_MA_METHOD _ma_method, ENUM_STO_PRICE _pf, - int _shift = 0) + void StochParams(int _kperiod = 5, int _dperiod = 3, int _slowing = 3, ENUM_MA_METHOD _ma_method = MODE_SMA, + ENUM_STO_PRICE _pf = STO_LOWHIGH, int _shift = 0) : kperiod(_kperiod), dperiod(_dperiod), slowing(_slowing), ma_method(_ma_method), price_field(_pf) { itype = INDI_STOCHASTIC; max_modes = FINAL_SIGNAL_LINE_ENTRY; @@ -50,10 +50,6 @@ struct StochParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\Stochastic"); }; - void StochParams(StochParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -67,14 +63,10 @@ class Indi_Stochastic : public Indicator { /** * Class constructor. */ - Indi_Stochastic(StochParams &_p) - : params(_p.kperiod, _p.dperiod, _p.slowing, _p.ma_method, _p.price_field), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Stochastic(StochParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.kperiod, _p.dperiod, _p.slowing, _p.ma_method, _p.price_field), Indicator(INDI_STOCHASTIC, _tf) { + Indi_Stochastic(StochParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_Stochastic(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_STOCHASTIC, _tf) {} /** * Calculates the Stochastic Oscillator and returns its value. @@ -132,14 +124,12 @@ class Indi_Stochastic : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_Stochastic::iStochastic(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetKPeriod(), GetDPeriod(), GetSlowing(), GetMAMethod(), GetPriceField(), - _mode, _shift, GetPointer(this)); + _value = Indi_Stochastic::iStochastic(GetSymbol(), GetTf(), GetKPeriod(), GetDPeriod(), GetSlowing(), + GetMAMethod(), GetPriceField(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetKPeriod(), GetDPeriod(), GetSlowing() /*]*/, _mode, - _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetKPeriod(), + GetDPeriod(), GetSlowing() /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index 1cbc2d0a1..7502ec28b 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -32,23 +32,16 @@ struct TEMAParams : IndicatorParams { unsigned int tema_shift; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void TEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void TEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; itype = INDI_TEMA; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\TEMA"); - SetDataSourceType(IDATA_BUILTIN); period = _period; shift = _shift; tema_shift = _tema_shift; - tf = _tf; - }; - void TEMAParams(TEMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -63,10 +56,10 @@ class Indi_TEMA : public Indicator { /** * Class constructor. */ - Indi_TEMA(TEMAParams &_params) : params(_params.period, _params.tema_shift), Indicator((IndicatorParams)_params) { + Indi_TEMA(TEMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_TEMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TEMA, _tf) { params.tf = _tf; }; + Indi_TEMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TEMA, _tf){}; /** * Built-in version of TEMA. diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index 13bf287be..900625c87 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -32,22 +32,15 @@ struct TRIXParams : IndicatorParams { unsigned int tema_shift; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; itype = INDI_TRIX; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\TRIX"); - SetDataSourceType(IDATA_BUILTIN); period = _period; shift = _shift; - tf = _tf; - }; - void TRIXParams(TRIXParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -62,8 +55,10 @@ class Indi_TRIX : public Indicator { /** * Class constructor. */ - Indi_TRIX(TRIXParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { params = _params; }; - Indi_TRIX(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TRIX, _tf) { params.tf = _tf; }; + Indi_TRIX(TRIXParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_TRIX(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TRIX, _tf){}; /** * Built-in version of TriX. diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index a23e27313..c892f9f87 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -36,8 +36,7 @@ struct UltimateOscillatorParams : IndicatorParams { // Struct constructor. void UltimateOscillatorParams(int _fast_period = 7, int _middle_period = 14, int _slow_period = 28, int _fast_k = 4, - int _middle_k = 2, int _slow_k = 1, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + int _middle_k = 2, int _slow_k = 1, int _shift = 0) { fast_k = _fast_k; fast_period = _fast_period; itype = INDI_ULTIMATE_OSCILLATOR; @@ -46,24 +45,10 @@ struct UltimateOscillatorParams : IndicatorParams { middle_period = _middle_period; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); - // SetDataSourceType(IDATA_ICUSTOM); - SetDataSourceType(IDATA_BUILTIN); SetCustomIndicatorName("Examples\\Ultimate_Oscillator"); - // IC: INDI_ULTIMATE_OSCILLATOR[1]: bar 1: 1525392000,130,45.93870749 - // IC: INDI_ULTIMATE_OSCILLATOR[1]: bar 1: 1525392120,130,36.36985216 - // IC: INDI_ULTIMATE_OSCILLATOR[1]: bar 1: 1525392180,130,40.82834908 - - // BIN: INDI_ULTIMATE_OSCILLATOR[1]: bar 2: 1525392240,130,53.10341381 - - // SetDataSourceType(IDATA_ICUSTOM); shift = _shift; slow_k = _slow_k; slow_period = _slow_period; - tf = _tf; - }; - void UltimateOscillatorParams(UltimateOscillatorParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -78,12 +63,11 @@ class Indi_UltimateOscillator : public Indicator { /** * Class constructor. */ - Indi_UltimateOscillator(UltimateOscillatorParams &_params) : Indicator((IndicatorParams)_params) { + Indi_UltimateOscillator(UltimateOscillatorParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_UltimateOscillator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ULTIMATE_OSCILLATOR, _tf) { - params.tf = _tf; - }; + Indi_UltimateOscillator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ULTIMATE_OSCILLATOR, _tf){}; /** * Built-in version of Ultimate Oscillator. diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index c10fc8c4d..be072938e 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -34,7 +34,7 @@ struct VIDYAParams : IndicatorParams { // Struct constructor. void VIDYAParams(unsigned int _cmo_period = 9, unsigned int _ma_period = 14, unsigned int _vidya_shift = 0, - ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; cmo_period = _cmo_period; itype = INDI_VIDYA; @@ -43,15 +43,9 @@ struct VIDYAParams : IndicatorParams { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\VIDYA"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; vidya_shift = _vidya_shift; }; - void VIDYAParams(VIDYAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -65,8 +59,10 @@ class Indi_VIDYA : public Indicator { /** * Class constructor. */ - Indi_VIDYA(VIDYAParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_VIDYA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VIDYA, _tf) { params.tf = _tf; }; + Indi_VIDYA(VIDYAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_VIDYA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VIDYA, _tf){}; /** * Built-in version of iVIDyA. diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index a4724806b..05b45cea0 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -29,8 +29,7 @@ struct VROCParams : IndicatorParams { unsigned int period; ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void VROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void VROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { applied_volume = _applied_volume; itype = INDI_VROC; max_modes = 1; @@ -38,13 +37,7 @@ struct VROCParams : IndicatorParams { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\VROC"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void VROCParams(VROCParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -59,8 +52,10 @@ class Indi_VROC : public Indicator { /** * Class constructor. */ - Indi_VROC(VROCParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_VROC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf) { params.tf = _tf; }; + Indi_VROC(VROCParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_VROC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf){}; /** * Built-in version of VROC. diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 80793f12b..c1729c8d8 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -28,21 +28,14 @@ struct VolumesParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void VolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void VolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { applied_volume = _applied_volume; itype = INDI_VOLUMES; max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Volumes"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void VolumesParams(VolumesParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -57,10 +50,11 @@ class Indi_Volumes : public Indicator { /** * Class constructor. */ - Indi_Volumes(VolumesParams &_params) : params(_params.applied_volume), Indicator((IndicatorParams)_params) { + Indi_Volumes(VolumesParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_Volumes(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VOLUMES, _tf) { params.tf = _tf; }; + Indi_Volumes(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VOLUMES, _tf){}; /** * Built-in version of Volumes. diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index 433443763..03d508285 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -34,7 +34,7 @@ double iWPR(string _symbol, int _tf, int _period, int _shift) { struct WPRParams : IndicatorParams { unsigned int period; // Struct constructors. - void WPRParams(unsigned int _period, int _shift = 0) : period(_period) { + void WPRParams(unsigned int _period = 14, int _shift = 0) : period(_period) { itype = INDI_WPR; max_modes = 1; shift = _shift; @@ -42,10 +42,6 @@ struct WPRParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\WPR"); }; - void WPRParams(WPRParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; /** @@ -59,8 +55,8 @@ class Indi_WPR : public Indicator { /** * Class constructor. */ - Indi_WPR(WPRParams &_p) : params(_p.period), Indicator((IndicatorParams)_p) { params = _p; } - Indi_WPR(WPRParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.period), Indicator(INDI_WPR, _tf) { params = _p; } + Indi_WPR(WPRParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_WPR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_WPR, _tf) {} /** * Calculates the Larry Williams' Percent Range and returns its value. @@ -112,12 +108,11 @@ class Indi_WPR : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_WPR::iWPR(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - _shift, GetPointer(this)); + _value = Indi_WPR::iWPR(GetSymbol(), GetTf(), GetPeriod(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index 4088404a6..a783f0056 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -27,19 +27,13 @@ // Structs. struct WilliamsADParams : IndicatorParams { // Struct constructor. - void WilliamsADParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void WilliamsADParams(int _shift = 0) { itype = INDI_WILLIAMS_AD; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\W_AD"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; - tf = _tf; - }; - void WilliamsADParams(WilliamsADParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -54,8 +48,11 @@ class Indi_WilliamsAD : public Indicator { /** * Class constructor. */ - Indi_WilliamsAD(WilliamsADParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_WilliamsAD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_WILLIAMS_AD, _tf) { params.tf = _tf; }; + Indi_WilliamsAD(WilliamsADParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { + params = _params; + }; + Indi_WilliamsAD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_WILLIAMS_AD, _tf){}; /** * Built-in version of Williams' AD. diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index ec4384969..a86526c20 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -33,20 +33,15 @@ struct ZigZagParams : IndicatorParams { unsigned int deviation; unsigned int backstep; // Struct constructors. - void ZigZagParams(unsigned int _depth, unsigned int _deviation, unsigned int _backstep, int _shift = 0) + void ZigZagParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) : depth(_depth), deviation(_deviation), backstep(_backstep) { itype = INDI_ZIGZAG; max_modes = FINAL_ZIGZAG_LINE_ENTRY; shift = _shift; - SetDataSourceType(IDATA_BUILTIN); SetCustomIndicatorName("Examples\\ZigZag"); SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Draws lines between lowest and highest prices! }; - void ZigZagParams(ZigZagParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; - }; }; enum EnSearchMode { @@ -66,13 +61,10 @@ class Indi_ZigZag : public Indicator { /** * Class constructor. */ - Indi_ZigZag(ZigZagParams &_p) : params(_p.depth, _p.deviation, _p.backstep), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_ZigZag(ZigZagParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.depth, _p.deviation, _p.backstep), Indicator(INDI_ZIGZAG, _tf) { + Indi_ZigZag(ZigZagParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator((IndicatorParams)_p, _tf) { params = _p; } + Indi_ZigZag(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ZIGZAG, _tf) {} /** * Returns value for ZigZag indicator. @@ -355,12 +347,12 @@ class Indi_ZigZag : public Indicator { switch (params.idstype) { case IDATA_BUILTIN: _value = Indi_ZigZag::iZigZag(GetSymbol(), GetTf(), GetDepth(), GetDeviation(), GetBackstep(), _mode, _shift, - GetPointer(this)); + THIS_PTR); break; case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_ZigZag::iCustomZigZag(GetSymbol(), GetTf(), params.GetCustomIndicatorName(), GetDepth(), - GetDeviation(), GetBackstep(), _mode, _shift, GetPointer(this)); + GetDeviation(), GetBackstep(), _mode, _shift, THIS_PTR); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 2ec756b94..84f1e8b6c 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -32,22 +32,17 @@ struct ZigZagColorParams : IndicatorParams { // Struct constructor. void ZigZagColorParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, - int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + int _shift = 0) { + itype = INDI_ZIGZAG_COLOR; backstep = _backstep; depth = _depth; deviation = _deviation; - itype = INDI_ZIGZAG_COLOR; max_modes = 3; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ZigZagColor"); SetDataSourceType(IDATA_ICUSTOM); shift = _shift; - tf = _tf; - }; - void ZigZagColorParams(ZigZagColorParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; - tf = _tf; }; }; @@ -62,11 +57,11 @@ class Indi_ZigZagColor : public Indicator { /** * Class constructor. */ - Indi_ZigZagColor(ZigZagColorParams &_params) - : params(_params.depth, _params.deviation, _params.backstep), Indicator((IndicatorParams)_params) { + Indi_ZigZagColor(ZigZagColorParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator((IndicatorParams)_params, _tf) { params = _params; }; - Indi_ZigZagColor(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf) { params.tf = _tf; }; + Indi_ZigZagColor(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf){}; /** * Returns the indicator's value. @@ -76,8 +71,7 @@ class Indi_ZigZagColor : public Indicator { double _value = EMPTY_VALUE; switch (params.idstype) { case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetDepth(), GetDeviation(), GetBackstep() /*]*/, _mode, _shift); break; default: diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index 36a13042e..95cdac397 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -142,7 +142,7 @@ int OnInit() { void OnTick() { chart.OnTick(); - if (chart.IsNewBar() && chart.GetBarTime() <= 1525492300) { + if (chart.IsNewBar()) { Redis *redis = _indi_drawer.Redis(); if (redis.Simulated() && redis.Subscribed("DRAWER")) { From 4fd23a7cf65f69540dd24b48ed11b71986fd5d42 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 25 Sep 2021 16:15:59 +0100 Subject: [PATCH 05/78] Util: Improves syntax to avoid global scope variable conflicts --- Util.h | 73 ++++++++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/Util.h b/Util.h index 7df498fe2..8ba6dbb2a 100644 --- a/Util.h +++ b/Util.h @@ -49,82 +49,63 @@ class Util { * Creates string-based key using given variables. */ template - static string MakeKey(const A a, const B b) { - string _a = SerializerConversions::ValueToString(a); - string _b = SerializerConversions::ValueToString(b); - - return SeparatedMaybe(_a) + _b; + static string MakeKey(const A _a, const B _b) { + return SeparatedMaybe(SerializerConversions::ValueToString(_a)) + SerializerConversions::ValueToString(_b); } /** * Creates string-based key using given variables. */ template - static string MakeKey(const A a, const B b, const C c) { - string _a = SerializerConversions::ValueToString(a); - string _b = SerializerConversions::ValueToString(b); - string _c = SerializerConversions::ValueToString(c); - - return SeparatedMaybe(_a) + SeparatedMaybe(_b) + _c; + static string MakeKey(const A _a, const B _b, const C _c) { + return SeparatedMaybe(SerializerConversions::ValueToString(_a)) + + SeparatedMaybe(SerializerConversions::ValueToString(_b)) + SerializerConversions::ValueToString(_c); } /** * Creates string-based key using given variables. */ template - static string MakeKey(const A a, const B b, const C c, const D d) { - string _a = SerializerConversions::ValueToString(a); - string _b = SerializerConversions::ValueToString(b); - string _c = SerializerConversions::ValueToString(c); - string _d = SerializerConversions::ValueToString(d); - - return SeparatedMaybe(_a) + SeparatedMaybe(_b) + SeparatedMaybe(_c) + _d; + static string MakeKey(const A _a, const B _b, const C _c, const D _d) { + return SeparatedMaybe(SerializerConversions::ValueToString(_a)) + + SeparatedMaybe(SerializerConversions::ValueToString(_b)) + + SeparatedMaybe(SerializerConversions::ValueToString(_c)) + SerializerConversions::ValueToString(_d); } /** * Creates string-based key using given variables. */ template - static string MakeKey(const A a, const B b, const C c, const D d, const E e) { - string _a = SerializerConversions::ValueToString(a); - string _b = SerializerConversions::ValueToString(b); - string _c = SerializerConversions::ValueToString(c); - string _d = SerializerConversions::ValueToString(d); - string _e = SerializerConversions::ValueToString(e); - - return SeparatedMaybe(_a) + SeparatedMaybe(_b) + SeparatedMaybe(_c) + SeparatedMaybe(_d) + _e; + static string MakeKey(const A _a, const B _b, const C _c, const D _d, const E _e) { + return SeparatedMaybe(SerializerConversions::ValueToString(_a)) + + SeparatedMaybe(SerializerConversions::ValueToString(_b)) + + SeparatedMaybe(SerializerConversions::ValueToString(_c)) + + SeparatedMaybe(SerializerConversions::ValueToString(_d)) + SerializerConversions::ValueToString(_e); } /** * Creates string-based key using given variables. */ template - static string MakeKey(const A a, const B b, const C c, const D d, const E e, const F f) { - string _a = SerializerConversions::ValueToString(a); - string _b = SerializerConversions::ValueToString(b); - string _c = SerializerConversions::ValueToString(c); - string _d = SerializerConversions::ValueToString(d); - string _e = SerializerConversions::ValueToString(e); - string _f = SerializerConversions::ValueToString(f); - - return SeparatedMaybe(_a) + SeparatedMaybe(_b) + SeparatedMaybe(_c) + SeparatedMaybe(_d) + SeparatedMaybe(_e) + _f; + static string MakeKey(const A _a, const B _b, const C _c, const D _d, const E _e, const F _f) { + return SeparatedMaybe(SerializerConversions::ValueToString(_a)) + + SeparatedMaybe(SerializerConversions::ValueToString(_b)) + + SeparatedMaybe(SerializerConversions::ValueToString(_c)) + + SeparatedMaybe(SerializerConversions::ValueToString(_d)) + + SeparatedMaybe(SerializerConversions::ValueToString(_e)) + SerializerConversions::ValueToString(_f); } /** * Creates string-based key using given variables. */ template - static string MakeKey(const A a, const B b, const C c, const D d, const E e, const F f, const G g) { - string _a = SerializerConversions::ValueToString(a); - string _b = SerializerConversions::ValueToString(b); - string _c = SerializerConversions::ValueToString(c); - string _d = SerializerConversions::ValueToString(d); - string _e = SerializerConversions::ValueToString(e); - string _f = SerializerConversions::ValueToString(f); - string _g = SerializerConversions::ValueToString(g); - - return SeparatedMaybe(_a) + SeparatedMaybe(_b) + SeparatedMaybe(_c) + SeparatedMaybe(_d) + SeparatedMaybe(_e) + - SeparatedMaybe(_f) + _g; + static string MakeKey(const A _a, const B _b, const C _c, const D _d, const E _e, const F _f, const G _g) { + return SeparatedMaybe(SerializerConversions::ValueToString(_a)) + + SeparatedMaybe(SerializerConversions::ValueToString(_b)) + + SeparatedMaybe(SerializerConversions::ValueToString(_c)) + + SeparatedMaybe(SerializerConversions::ValueToString(_d)) + + SeparatedMaybe(SerializerConversions::ValueToString(_e)) + + SeparatedMaybe(SerializerConversions::ValueToString(_f)) + SerializerConversions::ValueToString(_g); } /** From c71001ac47208d686fb313495cab7dc9cfa0e1c3 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 25 Sep 2021 19:50:30 +0100 Subject: [PATCH 06/78] StgParams: Adds missing default value for shift --- Strategy.struct.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Strategy.struct.h b/Strategy.struct.h index 3c41b81d6..23dfc29b9 100644 --- a/Strategy.struct.h +++ b/Strategy.struct.h @@ -106,6 +106,7 @@ struct StgParams { lot_size_factor(1.0), max_risk(1.0), max_spread(0.0), + shift(0), tp_max(0), sl_max(0), type(0), From 68b5693278b405733be15773df2e8164a57c30bf Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 26 Sep 2021 14:01:40 +0100 Subject: [PATCH 07/78] Order: ProcessConditions: Adds _refresh --- Order.mqh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Order.mqh b/Order.mqh index e961061f7..7cbba164b 100644 --- a/Order.mqh +++ b/Order.mqh @@ -2581,9 +2581,9 @@ class Order : public SymbolInfo { /** * Process order conditions. */ - bool ProcessConditions() { + bool ProcessConditions(bool _refresh = false) { bool _result = true; - if (IsOpen() && ShouldCloseOrder()) { + if (IsOpen(_refresh) && ShouldCloseOrder()) { string _reason = "Close condition"; #ifdef __MQL__ // _reason += StringFormat(": %s", EnumToString(oparams.cond_close)); From 8afea6dd31d4843843563e361a132ef9ff78c0fa Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 26 Sep 2021 14:02:12 +0100 Subject: [PATCH 08/78] EA: ProcessTrades: Processes orders' conditions --- EA.mqh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/EA.mqh b/EA.mqh index ee5d6ce23..49e8dada5 100644 --- a/EA.mqh +++ b/EA.mqh @@ -742,7 +742,9 @@ class EA { Order *_order = oiter.Value().Ptr(); if (!_order.ShouldUpdate()) { continue; - } else if (_order.IsClosed()) { + } + _order.ProcessConditions(); + if (_order.IsClosed()) { _trade.OrderMoveToHistory(_order); continue; } From c86d70e87d3c8a859440102ab87d40aca3c1ea43 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 26 Sep 2021 15:51:51 +0100 Subject: [PATCH 09/78] Indi_CHO/Indi_CHV: Adds missing includes for ValueStorage --- Indicators/Indi_CHO.mqh | 2 ++ Indicators/Indi_CHV.mqh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index a9515f31f..748a08a66 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -24,6 +24,8 @@ #include "../BufferStruct.mqh" #include "../Indicator.mqh" #include "Indi_MA.mqh" +#include "../Storage/ValueStorage.all.h" +#include "../Util.h" // Structs. struct CHOParams : IndicatorParams { diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 03770e765..d762edaff 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -24,6 +24,8 @@ #include "../BufferStruct.mqh" #include "../Indicator.mqh" #include "Indi_MA.mqh" +#include "../Storage/ValueStorage.all.h" +#include "../Util.h" // Enums. enum ENUM_CHV_SMOOTH_METHOD { CHV_SMOOTH_METHOD_SMA = 0, CHV_SMOOTH_METHOD_EMA = 1 }; From 4fe95d837c41d270288f16d820d5e5f229d1baf3 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 26 Sep 2021 16:32:36 +0100 Subject: [PATCH 10/78] Indi_Pivot: GetEntryValue: Fixes typos --- Indicators/Indi_Pivot.mqh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index a0830313b..30f3b9e77 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -113,11 +113,10 @@ class Indi_Pivot : public Indicator { _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, true); - istate.is_ready = true; - if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); idata.Add(_entry, _bar_time); + istate.is_ready = true; } } return _entry; @@ -127,8 +126,8 @@ class Indi_Pivot : public Indicator { * Returns the indicator's entry value. */ MqlParam GetEntryValue(int _shift = 0, int _mode = 0) { - MqlParam _param = {TYPE_INT}; - _param.integer_value = GetEntry(_shift).GetValue(_mode); + MqlParam _param = {TYPE_FLOAT}; + _param.double_value = GetEntry(_shift).GetValue(_mode); return _param; } From 98ffeac28f3ab005e239b40f1ac49f536acbecb5 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 26 Sep 2021 16:40:49 +0100 Subject: [PATCH 11/78] Bar: Removes FINAL_ENUM_PP_TYPE_ENTRY --- Bar.enum.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Bar.enum.h b/Bar.enum.h index 11c5c7911..e4c834f7e 100644 --- a/Bar.enum.h +++ b/Bar.enum.h @@ -38,5 +38,4 @@ enum ENUM_PP_TYPE { PP_FLOOR = 4, // Most basic and popular type of pivots used in Forex trading technical analysis PP_TOM_DEMARK = 5, // Tom DeMark's pivot point (predicted lows and highs of the period) PP_WOODIE = 6, // Woodie's pivot point are giving more weight to the Close price of the previous period - FINAL_ENUM_PP_TYPE_ENTRY }; From 2d445731f3fac8beca43fb35aa4ed6bcf49ac5b4 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 26 Sep 2021 16:46:14 +0100 Subject: [PATCH 12/78] Indicator: GetFlag: Improves shift logic --- Indicator.mqh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Indicator.mqh b/Indicator.mqh index b13030b5f..e0a84e1d5 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -566,8 +566,8 @@ class Indicator : public Chart { /** * Gets an indicator property flag. */ - bool GetFlag(INDICATOR_ENTRY_FLAGS _prop, int _shift = 0) { - IndicatorDataEntry _entry = GetEntry(_shift); + bool GetFlag(INDICATOR_ENTRY_FLAGS _prop, int _shift = -1) { + IndicatorDataEntry _entry = GetEntry(_shift >= 0 ? _shift : iparams.GetShift()); return _entry.CheckFlag(_prop); } From 1604b8d1145755e82922e6f210e2744fc9e5ce9d Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Mon, 27 Sep 2021 14:21:52 +0200 Subject: [PATCH 13/78] Little fixes due to compiler problems. --- Indicators/Indi_BWZT.mqh | 1 + Refs.mqh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 126a6432d..d469c0ef0 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" #include "Indi_AC.mqh" #include "Indi_AO.mqh" diff --git a/Refs.mqh b/Refs.mqh index 1239e88ba..bc71b2138 100644 --- a/Refs.mqh +++ b/Refs.mqh @@ -129,7 +129,7 @@ class Dynamic { */ Dynamic() { #ifdef __MQL__ - if (CheckPointer(&this) == POINTER_DYNAMIC) { + if (CheckPointer(GetPointer(this)) == POINTER_DYNAMIC) { #else // For other languages we just assume that user knows what he does and creates all Dynamic instances on the heap. if (true) { From 2b93278f5618d1038ec00429aaf82214b5117924 Mon Sep 17 00:00:00 2001 From: kenorb Date: Mon, 27 Sep 2021 22:01:18 +0100 Subject: [PATCH 14/78] Chart: Adds new bitwise defines for timeframes --- Chart.define.h | 23 +++++++++++++++++++++++ Chart.enum.h | 14 -------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Chart.define.h b/Chart.define.h index e0903d891..f01ac1c3f 100644 --- a/Chart.define.h +++ b/Chart.define.h @@ -27,6 +27,29 @@ /* Defines */ +// Define type of timeframe periods using bitwise values. +#define M1B 1 << M1, // 1 minute +#define M2B 1 << M2, // 2 minutes (non-standard) +#define M3B 1 << M3, // 3 minutes (non-standard) +#define M4B 1 << M4, // 4 minutes (non-standard) +#define M5B 1 << M5, // 5 minutes +#define M6B 1 << M6, // 6 minutes (non-standard) +#define M10B 1 << M10, // 10 minutes (non-standard) +#define M12B 1 << M12, // 12 minutes (non-standard) +#define M15B 1 << M15, // 15 minutes +#define M20B 1 << M20, // 20 minutes (non-standard) +#define M30B 1 << M30, // 30 minutes +#define H1B 1 << H1, // 1 hour +#define H2B 1 << H2, // 2 hours (non-standard) +#define H3B 1 << H3, // 3 hours (non-standard) +#define H4B 1 << H4, // 4 hours +#define H6B 1 << H6, // 6 hours (non-standard) +#define H8B 1 << H8, // 8 hours (non-standard) +#define H12B 1 << H12, // 12 hours (non-standard) +#define D1B 1 << D1, // Daily +#define W1B 1 << W1, // Weekly +#define MN1B 1 << MN1, // Monthly + #ifndef __MQL4__ // Chart. #define CHART_BAR 0 diff --git a/Chart.enum.h b/Chart.enum.h index f8ad5dc22..1bafacd19 100644 --- a/Chart.enum.h +++ b/Chart.enum.h @@ -88,20 +88,6 @@ enum ENUM_TIMEFRAMES_INDEX { FINAL_ENUM_TIMEFRAMES_INDEX = 21 }; -/* Define type of periods using bitwise operators. */ -enum ENUM_TIMEFRAMES_BITS { - M1B = 1 << 0, // =1: 1 minute - M5B = 1 << 1, // =2: 5 minutes - M15B = 1 << 2, // =4: 15 minutes - M30B = 1 << 3, // =8: 30 minutes - H1B = 1 << 4, // =16: 1 hour - H4B = 1 << 5, // =32: 4 hours - H8B = 1 << 6, // =64: 8 hours - D1B = 1 << 7, // =128: Daily - W1B = 1 << 8, // =256: Weekly - MN1B = 1 << 9, // =512: Monthly -}; - #ifndef __MQLBUILD__ /** * Defines chart timeframes. From c12f665412592be2382c9faf6846a532db28af84 Mon Sep 17 00:00:00 2001 From: kenorb Date: Mon, 27 Sep 2021 23:38:50 +0100 Subject: [PATCH 15/78] GHA: Moves CompileIndicatorsTest to Experts to avoid hang --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be1bba5ff..18c954e3f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,6 +58,7 @@ jobs: - BufferStructTest - BufferTest - ChartTest + - CompileIndicatorsTest - ConditionTest - DatabaseTest - DrawIndicatorTest @@ -188,7 +189,6 @@ jobs: matrix: test: - CollectionTest - - CompileIndicatorsTest - ConfigTest - ConvertTest - DateTimeTest From 191f167dadfc4798b57ff38ed258ad6fbca02874 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 28 Sep 2021 18:45:13 +0200 Subject: [PATCH 16/78] Indicator: Adds template for indicator param struct [WIP] --- Action.mqh | 2 +- Condition.mqh | 2 +- DrawIndicator.mqh | 7 +- EA.mqh | 2 +- Indicator.mqh | 124 ++++++++++--------- Indicator.struct.h | 12 +- Indicator.struct.serialize.h | 6 +- Indicator.struct.signal.h | 3 +- Indicators/Bitwise/Indi_Candle.mqh | 25 ++-- Indicators/Indi_AC.mqh | 21 ++-- Indicators/Indi_AD.mqh | 21 ++-- Indicators/Indi_ADX.mqh | 31 +++-- Indicators/Indi_ADXW.mqh | 23 ++-- Indicators/Indi_AMA.mqh | 46 +++---- Indicators/Indi_AO.mqh | 21 ++-- Indicators/Indi_ASI.mqh | 25 ++-- Indicators/Indi_ATR.mqh | 25 ++-- Indicators/Indi_Alligator.mqh | 52 ++++---- Indicators/Indi_AppliedPrice.mqh | 30 +++-- Indicators/Indi_BWMFI.mqh | 17 ++- Indicators/Indi_BWZT.mqh | 30 +++-- Indicators/Indi_Bands.mqh | 57 ++++----- Indicators/Indi_BearsPower.mqh | 33 ++--- Indicators/Indi_BullsPower.mqh | 35 ++---- Indicators/Indi_CCI.mqh | 47 +++----- Indicators/Indi_CHO.mqh | 41 +++---- Indicators/Indi_CHV.mqh | 37 +++--- Indicators/Indi_ColorBars.mqh | 22 ++-- Indicators/Indi_ColorCandlesDaily.mqh | 24 ++-- Indicators/Indi_ColorLine.mqh | 28 ++--- Indicators/Indi_CustomMovingAverage.mqh | 35 +++--- Indicators/Indi_DEMA.mqh | 51 ++++---- Indicators/Indi_DeMarker.mqh | 27 ++--- Indicators/Indi_Demo.mqh | 23 ++-- Indicators/Indi_DetrendedPrice.mqh | 29 ++--- Indicators/Indi_Drawer.mqh | 62 +++++----- Indicators/Indi_Drawer.struct.h | 2 +- Indicators/Indi_Envelopes.mqh | 56 ++++----- Indicators/Indi_Force.mqh | 38 +++--- Indicators/Indi_FractalAdaptiveMA.mqh | 36 +++--- Indicators/Indi_Fractals.mqh | 17 ++- Indicators/Indi_Gator.mqh | 61 ++++------ Indicators/Indi_HeikenAshi.mqh | 23 ++-- Indicators/Indi_Ichimoku.mqh | 37 +++--- Indicators/Indi_MA.mqh | 52 ++++---- Indicators/Indi_MACD.mqh | 44 +++---- Indicators/Indi_MFI.mqh | 33 +++-- Indicators/Indi_MassIndex.mqh | 36 +++--- Indicators/Indi_Momentum.mqh | 46 +++---- Indicators/Indi_OBV.mqh | 45 ++----- Indicators/Indi_OsMA.mqh | 45 +++---- Indicators/Indi_Pattern.mqh | 31 +++-- Indicators/Indi_Pivot.mqh | 27 ++--- Indicators/Indi_Price.mqh | 16 +-- Indicators/Indi_PriceChannel.mqh | 25 ++-- Indicators/Indi_PriceFeeder.mqh | 25 ++-- Indicators/Indi_PriceVolumeTrend.mqh | 30 ++--- Indicators/Indi_RS.mqh | 23 ++-- Indicators/Indi_RSI.mqh | 96 ++++++--------- Indicators/Indi_RVI.mqh | 25 ++-- Indicators/Indi_RateOfChange.mqh | 31 ++--- Indicators/Indi_SAR.mqh | 29 ++--- Indicators/Indi_StdDev.mqh | 53 ++++---- Indicators/Indi_Stochastic.mqh | 47 +++----- Indicators/Indi_TEMA.mqh | 33 +++-- Indicators/Indi_TRIX.mqh | 29 ++--- Indicators/Indi_UltimateOscillator.mqh | 59 +++++---- Indicators/Indi_VIDYA.mqh | 37 +++--- Indicators/Indi_VROC.mqh | 29 ++--- Indicators/Indi_Volumes.mqh | 27 ++--- Indicators/Indi_WPR.mqh | 25 ++-- Indicators/Indi_WilliamsAD.mqh | 22 ++-- Indicators/Indi_ZigZag.mqh | 41 +++---- Indicators/Indi_ZigZagColor.mqh | 34 +++--- Indicators/README.md | 154 ++++++++++++------------ Indicators/Special/Indi_Math.mqh | 66 +++++----- Storage/ValueStorage.indicator.h | 6 +- Strategy.mqh | 17 +-- 78 files changed, 1167 insertions(+), 1517 deletions(-) diff --git a/Action.mqh b/Action.mqh index 85f9a3a9b..12387359c 100644 --- a/Action.mqh +++ b/Action.mqh @@ -141,7 +141,7 @@ class Action { #ifdef INDICATOR_MQH case ACTION_TYPE_INDICATOR: if (Object::IsValid(_entry.obj)) { - _result = ((Indicator *)_entry.obj).ExecuteAction((ENUM_INDICATOR_ACTION)_entry.action_id); + _result = ((Indicator *)_entry.obj).ExecuteAction((ENUM_INDICATOR_ACTION)_entry.action_id); } else { _result = false; _entry.AddFlags(ACTION_ENTRY_FLAG_IS_INVALID); diff --git a/Condition.mqh b/Condition.mqh index 27183866b..f29051c29 100644 --- a/Condition.mqh +++ b/Condition.mqh @@ -167,7 +167,7 @@ class Condition { #ifdef INDICATOR_MQH case COND_TYPE_INDICATOR: if (Object::IsValid(_entry.obj)) { - _result = ((Indicator *)_entry.obj).CheckCondition((ENUM_INDICATOR_CONDITION)_entry.cond_id, _entry.args); + _result = ((Indicator *)_entry.obj).CheckCondition((ENUM_INDICATOR_CONDITION)_entry.cond_id, _entry.args); } else { // Static method not supported. _result = false; diff --git a/DrawIndicator.mqh b/DrawIndicator.mqh index 35e5557b7..321bf04e0 100644 --- a/DrawIndicator.mqh +++ b/DrawIndicator.mqh @@ -52,11 +52,12 @@ class DrawPoint { DrawPoint(datetime _time = NULL, double _value = 0) : time(_time), value(_value) {} }; +template class DrawIndicator { protected: color color_line; Draw* draw; - Indicator* indi; + Indicator* indi; public: // Object variables. @@ -67,8 +68,8 @@ class DrawIndicator { /** * Class constructor. */ - DrawIndicator(Indicator* _indi) : indi(_indi) { - color_line = Object::IsValid(_indi) ? _indi.GetParams().indi_color : clrRed; + DrawIndicator(Indicator *_indi) : indi(_indi) { + // color_line = Object::IsValid(_indi) ? _indi.GetParams().indi_color : clrRed; // @fixme draw = new Draw(); } diff --git a/EA.mqh b/EA.mqh index 5c39db312..ba4112c78 100644 --- a/EA.mqh +++ b/EA.mqh @@ -373,7 +373,7 @@ class EA { if (eparams.CheckFlagDataStore(EA_DATA_STORE_INDICATOR)) { for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { Strategy *_strati = iter.Value().Ptr(); - Indicator *_indi = _strati.GetIndicator(); + Indicator *_indi = _strati.GetIndicator(); if (_indi != NULL) { ENUM_TIMEFRAMES _itf = _indi.GetParams().tf.GetTf(); IndicatorDataEntry _ientry = _indi.GetEntry(); diff --git a/Indicator.mqh b/Indicator.mqh index b13030b5f..12c8171e9 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -51,7 +51,7 @@ class Chart; #ifndef __MQL4__ // Defines global functions (for MQL4 backward compatibility). -bool IndicatorBuffers(int _count) { return Indicator::SetIndicatorBuffers(_count); } +bool IndicatorBuffers(int _count) { return Indicator::SetIndicatorBuffers(_count); } int IndicatorCounted(int _value = 0) { static int prev_calculated = 0; // https://docs.mql4.com/customind/indicatorcounted @@ -63,12 +63,12 @@ int IndicatorCounted(int _value = 0) { /** * Class to deal with indicators. */ +template class Indicator : public Chart { protected: // Structs. BufferStruct idata; - DrawIndicator* draw; - IndicatorParams iparams; + DrawIndicator* draw; IndicatorState istate; void* mydata; bool is_feeding; // Whether FeedHistoryEntries is already working. @@ -76,7 +76,9 @@ class Indicator : public Chart { DictStruct> indicators; // Indicators list keyed by id. bool indicator_builtin; ARRAY(ValueStorage*, value_storages); + Indicator* indi_src; // // Indicator used as data source. IndicatorCalculateCache cache; + TS iparams; public: /* Indicator enumerations */ @@ -96,20 +98,19 @@ class Indicator : public Chart { /** * Class constructor. */ - Indicator() {} - Indicator(IndicatorParams& _iparams) : Chart(_iparams.GetTf()), draw(NULL), is_feeding(false), is_fed(false) { - iparams = _iparams; + Indicator() : indi_src(NULL) {} + Indicator(TS& _iparams) + : Chart(_iparams.GetTf()), draw(NULL), iparams(_iparams), is_feeding(false), is_fed(false), indi_src(NULL) { SetName(_iparams.name != "" ? _iparams.name : EnumToString(iparams.itype)); Init(); } - Indicator(const IndicatorParams& _iparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : Chart(_tf), draw(NULL), is_feeding(false), is_fed(false) { - iparams = _iparams; + Indicator(const TS& _iparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Chart(_tf), draw(NULL), iparams(_iparams), is_feeding(false), is_fed(false), indi_src(NULL) { SetName(_iparams.name != "" ? _iparams.name : EnumToString(iparams.itype)); Init(); } Indicator(ENUM_INDICATOR_TYPE _itype, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, string _name = "") - : Chart(_tf), draw(NULL), is_feeding(false), is_fed(false) { + : Chart(_tf), draw(NULL), is_feeding(false), is_fed(false), indi_src(NULL) { iparams.SetIndicatorType(_itype); iparams.SetShift(_shift); SetName(_name != "" ? _name : EnumToString(iparams.itype)); @@ -129,13 +130,13 @@ class Indicator : public Chart { } } - if (iparams.indi_data_source != NULL && iparams.indi_managed) { + if (indi_src != NULL && iparams.indi_managed) { // User selected custom, managed data source. - if (CheckPointer(iparams.indi_data_source) == POINTER_INVALID) { + if (CheckPointer(indi_src) == POINTER_INVALID) { DebugBreak(); } - delete iparams.indi_data_source; - iparams.indi_data_source = NULL; + delete indi_src; + indi_src = NULL; } } @@ -151,7 +152,7 @@ class Indicator : public Chart { */ bool InitDraw() { if (iparams.is_draw && !Object::IsValid(draw)) { - draw = new DrawIndicator(&this); + draw = new DrawIndicator(&this); draw.SetColorLine(iparams.indi_color); } return iparams.is_draw; @@ -419,6 +420,39 @@ class Indicator : public Chart { return _is_valid; } + /** + * CopyBuffer() method to be used on Indicator instance with ValueStorage buffer. + * + * Note that data will be copied so that the oldest element will be located at the start of the physical memory + * allocated for the array + */ + /* + static int CopyBuffer(Indicator* _indi, int _mode, int _start, int _count, ValueStorage& _buffer, + int _rates_total) { int _num_copied = 0; int _buffer_size = ArraySize(_buffer); + + if (_buffer_size < _rates_total) { + _buffer_size = ArrayResize(_buffer, _rates_total); + } + + for (int i = _start; i < _count; ++i) { + IndicatorDataEntry _entry = _indi.GetEntry(i); + + if (!_entry.IsValid()) { + break; + } + + T _value = _entry.GetValue(_mode); + + // Print(_value); + + _buffer[_buffer_size - i - 1] = _value; + ++_num_copied; + } + + return _num_copied; + } + */ + /** * Validates currently selected indicator used as data source. */ @@ -494,20 +528,20 @@ class Indicator : public Chart { /** * Whether data source is selected. */ - bool HasDataSource() { return iparams.GetDataSource() != NULL || iparams.GetDataSourceId() != -1; } + bool HasDataSource() { return GetDataSource() != NULL || iparams.GetDataSourceId() != -1; } /** * Returns currently selected data source without any validation. */ - Indicator* GetDataSourceRaw() { return iparams.GetDataSource(); } + Indicator* GetDataSourceRaw() { return GetDataSource(); } /** * Returns currently selected data source doing validation. */ - Indicator* GetDataSource() { - Indicator* _result = NULL; - if (iparams.GetDataSource() != NULL) { - _result = iparams.GetDataSource(); + Indicator* GetDataSource() { + Indicator* _result = NULL; + if (GetDataSource() != NULL) { + _result = GetDataSource(); } else if (iparams.GetDataSourceId() != -1) { int _source_id = iparams.GetDataSourceId(); @@ -694,7 +728,7 @@ class Indicator : public Chart { /* Getters */ - int GetDataSourceMode() { return iparams.GetDataSourceMode(); } + int GetDataSourceMode() { return GetDataSourceMode(); } /** * Returns the highest bar's index (shift). @@ -917,6 +951,15 @@ class Indicator : public Chart { Chart::Set(_param, _value); } + /** + * Sets indicator data source. + */ + template + void SetDataSource(Indicator* _indi, bool _managed = true, int _input_mode = -1) { + indi_src = _indi; + iparams.SetDataSource(-1, _input_mode, _managed); + } + /** * Sets name of the indicator. */ @@ -1144,7 +1187,7 @@ class Indicator : public Chart { ValueStorage* GetValueStorage(int _mode = 0) { if (value_storages[_mode] == NULL) { - value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); + value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); } return value_storages[_mode]; } @@ -1294,6 +1337,7 @@ class Indicator : public Chart { /** * BarsCalculated() method to be used on Indicator instance. */ +/* int BarsCalculated(Indicator* _indi, int _bars_required) { if (_bars_required == 0) { return _bars_required; @@ -1321,38 +1365,6 @@ int BarsCalculated(Indicator* _indi, int _bars_required) { return _valid_history_count; } - -/** - * CopyBuffer() method to be used on Indicator instance with ValueStorage buffer. - * - * Note that data will be copied so that the oldest element will be located at the start of the physical memory - * allocated for the array - */ -template -int CopyBuffer(Indicator* _indi, int _mode, int _start, int _count, ValueStorage& _buffer, int _rates_total) { - int _num_copied = 0; - int _buffer_size = ArraySize(_buffer); - - if (_buffer_size < _rates_total) { - _buffer_size = ArrayResize(_buffer, _rates_total); - } - - for (int i = _start; i < _count; ++i) { - IndicatorDataEntry _entry = _indi.GetEntry(i); - - if (!_entry.IsValid()) { - break; - } - - T _value = _entry.GetValue(_mode); - - // Print(_value); - - _buffer[_buffer_size - i - 1] = _value; - ++_num_copied; - } - - return _num_copied; -} +*/ #endif diff --git a/Indicator.struct.h b/Indicator.struct.h index 51c99d028..e1027704d 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -367,7 +367,6 @@ struct IndicatorParams { color indi_color; // Indicator color. int indi_data_source_id; // Id of the indicator to be used as data source. int indi_data_source_mode; // Mode used as input from data source. - Indicator *indi_data_source; // Custom indicator to be used as data source. bool indi_managed; // Whether indicator should be owned by indicator. ARRAY(DataParamEntry, input_params); // Indicator input params. int indi_mode; // Index of indicator data to be used as data source. @@ -385,7 +384,6 @@ struct IndicatorParams { max_buffers(10), idstype(_idstype), idvrange(IDATA_RANGE_UNKNOWN), - indi_data_source(NULL), indi_data_source_id(-1), indi_data_source_mode(0), itype(_itype), @@ -404,7 +402,6 @@ struct IndicatorParams { max_buffers(10), idstype(_idstype), idvrange(IDATA_RANGE_UNKNOWN), - indi_data_source(NULL), indi_data_source_id(-1), indi_data_source_mode(0), is_draw(false), @@ -417,7 +414,6 @@ struct IndicatorParams { void Init() {} /* Getters */ string GetCustomIndicatorName() { return custom_indi_name; } - Indicator *GetDataSource() { return indi_data_source; } int GetDataSourceId() { return indi_data_source_id; } int GetDataSourceMode() { return indi_data_source_mode; } color GetIndicatorColor() { return indi_color; } @@ -465,15 +461,9 @@ struct IndicatorParams { draw_window = _window; } void SetIndicatorColor(color _clr) { indi_color = _clr; } - void SetDataSource(int _id, int _input_mode = -1) { + void SetDataSource(int _id, int _input_mode = -1, bool _managed = true) { indi_data_source_id = _id; indi_data_source_mode = _input_mode; - idstype = IDATA_INDICATOR; - } - void SetDataSource(Indicator *_indi, bool _managed = true, int _input_mode = -1) { - indi_data_source_id = -1; - indi_data_source = _indi; - indi_data_source_mode = _input_mode; indi_managed = _managed; idstype = IDATA_INDICATOR; } diff --git a/Indicator.struct.serialize.h b/Indicator.struct.serialize.h index 0b47a476a..6c563f941 100644 --- a/Indicator.struct.serialize.h +++ b/Indicator.struct.serialize.h @@ -36,9 +36,9 @@ SerializerNodeType IndicatorDataEntry::Serialize(Serializer &_s) { _s.Pass(THIS_REF, "datetime", timestamp, SERIALIZER_FIELD_FLAG_DYNAMIC); _s.Pass(THIS_REF, "flags", flags, SERIALIZER_FIELD_FLAG_DYNAMIC); for (int i = 0; i < _asize; i++) { - // _s.Pass(THIS_REF, (string)i, values[i], SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE); // Can this - // work? _s.Pass(THIS_REF, (string)i, GetEntry(i), SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE); // - // Can this work? + // _s.Pass(THIS_REF, (string)i, values[i], SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE); // Can + // this work? _s.Pass(THIS_REF, (string)i, GetEntry(i), SERIALIZER_FIELD_FLAG_DYNAMIC | + // SERIALIZER_FIELD_FLAG_FEATURE); // Can this work? if (CheckFlags(INDI_ENTRY_FLAG_IS_DOUBLE)) { _s.Pass(THIS_REF, (string)i, values[i].vdbl, SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE); diff --git a/Indicator.struct.signal.h b/Indicator.struct.signal.h index 1ac6dcd75..954e02172 100644 --- a/Indicator.struct.signal.h +++ b/Indicator.struct.signal.h @@ -56,7 +56,8 @@ struct IndicatorSignal { // Constructors. IndicatorSignal(int _signals = 0) : signals(_signals) {} - IndicatorSignal(ARRAY_REF(IndicatorDataEntry, _data), IndicatorParams &_ip, ChartParams &_cp, int _m1 = 0, int _m2 = 0) + IndicatorSignal(ARRAY_REF(IndicatorDataEntry, _data), IndicatorParams &_ip, ChartParams &_cp, int _m1 = 0, + int _m2 = 0) : signals(0) { CalcSignals(_data, _ip, _cp, _m1, _m2); } diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index bfd955cf2..a5698f29a 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -49,16 +49,13 @@ struct CandleParams : IndicatorParams { /** * Implements Candle Pattern Detector. */ -class Indi_Candle : public Indicator { - protected: - CandleParams params; - +class Indi_Candle : public Indicator { public: /** * Class constructor. */ - Indi_Candle(CandleParams &_params) : params(_params), Indicator((IndicatorParams)_params){}; - Indi_Candle(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CANDLE, _tf) { params.tf = _tf; }; + Indi_Candle(CandleParams &_params) : iparams(_params), Indicator(_params){}; + Indi_Candle(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CANDLE, _tf) { iparams.tf = _tf; }; /** * Returns the indicator's struct value. @@ -66,7 +63,7 @@ class Indi_Candle : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -75,7 +72,7 @@ class Indi_Candle : public Indicator { ResetLastError(); BarOHLC _ohlcs[1]; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: // In this mode, price is fetched from chart. _ohlcs[0] = Chart::GetOHLC(_shift); @@ -84,7 +81,7 @@ class Indi_Candle : public Indicator { // In this mode, price is fetched from given indicator. Such indicator // must have at least 4 buffers and define OHLC in the first 4 buffers. // Indi_Price is an example of such indicator. - if (GetDataSource() == NULL) { + if (indi_src == NULL) { GetLogger().Error( "In order use custom indicator as a source, you need to select one using SetIndicatorData() method, " "which is a part of CandleParams structure.", @@ -98,10 +95,10 @@ class Indi_Candle : public Indicator { return _entry; } - _ohlcs[0].open = GetDataSource().GetValue(_shift, PRICE_OPEN); - _ohlcs[0].high = GetDataSource().GetValue(_shift, PRICE_HIGH); - _ohlcs[0].low = GetDataSource().GetValue(_shift, PRICE_LOW); - _ohlcs[0].close = GetDataSource().GetValue(_shift, PRICE_CLOSE); + _ohlcs[0].open = indi_src.GetValue(_shift, PRICE_OPEN); + _ohlcs[0].high = indi_src.GetValue(_shift, PRICE_HIGH); + _ohlcs[0].low = indi_src.GetValue(_shift, PRICE_LOW); + _ohlcs[0].close = indi_src.GetValue(_shift, PRICE_CLOSE); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -116,7 +113,7 @@ class Indi_Candle : public Indicator { istate.is_ready = true; if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index eecbeb1c0..99aaed938 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -50,16 +50,13 @@ struct ACParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_AC : public Indicator { - protected: - ACParams params; - +class Indi_AC : public Indicator { public: /** * Class constructor. */ - Indi_AC(ACParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_AC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AC, _tf) { params.SetTf(_tf); }; + Indi_AC(ACParams &_params) : Indicator(_params){}; + Indi_AC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AC, _tf){}; /** * Returns the indicator value. @@ -69,7 +66,7 @@ class Indi_AC : public Indicator { * - https://www.mql5.com/en/docs/indicators/iac */ static double iAC(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iAC(_symbol, _tf, _shift); #else // __MQL5__ @@ -108,13 +105,13 @@ class Indi_AC : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_AC::iAC(GetSymbol(), GetTf(), _shift, GetPointer(this)); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -130,17 +127,17 @@ class Indi_AC : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index afe5b1d50..e253c2348 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -49,16 +49,13 @@ struct ADParams : IndicatorParams { /** * Implements the Accumulation/Distribution indicator. */ -class Indi_AD : public Indicator { - protected: - ADParams params; - +class Indi_AD : public Indicator { public: /** * Class constructor. */ - Indi_AD(ADParams &_p) : Indicator((IndicatorParams)_p) { params = _p; }; - Indi_AD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AD, _tf) { params.SetTf(_tf); }; + Indi_AD(ADParams &_p) : Indicator(_p){}; + Indi_AD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AD, _tf) { iparams.SetTf(_tf); }; /** * Returns the indicator value. @@ -68,7 +65,7 @@ class Indi_AD : public Indicator { * - https://www.mql5.com/en/docs/indicators/iad */ static double iAD(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iAD(_symbol, _tf, _shift); #else // __MQL5__ @@ -107,7 +104,7 @@ class Indi_AD : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_AD::iAD(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), _shift, @@ -115,7 +112,7 @@ class Indi_AD : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), _mode, _shift); + iparams.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -131,17 +128,17 @@ class Indi_AD : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index ed2d792a2..00d321947 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -53,9 +53,11 @@ struct ADXParams : IndicatorParams { } break; case IDATA_INDICATOR: - if (indi_data_source == NULL) { + /* @fixme + if (indi_src == NULL) { SetDataSource(Indi_Price::GetCached(_shift, _tf, applied_price, _period)); } + */ break; } }; @@ -68,15 +70,12 @@ struct ADXParams : IndicatorParams { /** * Implements the Average Directional Movement Index indicator. */ -class Indi_ADX : public Indicator { - protected: - ADXParams params; - +class Indi_ADX : public Indicator { public: /** * Class constructor. */ - Indi_ADX(ADXParams &_p) : params(_p.period, _p.applied_price), Indicator((IndicatorParams)_p) { params = _p; } + Indi_ADX(ADXParams &_p) : Indicator(_p) {} Indi_ADX(ENUM_TIMEFRAMES _tf) : Indicator(INDI_ADX, _tf) {} /** @@ -90,7 +89,7 @@ class Indi_ADX : public Indicator { ENUM_APPLIED_PRICE _applied_price, // (MT5): not used int _mode = LINE_MAIN_ADX, // (MT4/MT5): 0 - MODE_MAIN/MAIN_LINE, 1 - // MODE_PLUSDI/PLUSDI_LINE, 2 - MODE_MINUSDI/MINUSDI_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iADX(_symbol, _tf, _period, _applied_price, _mode, _shift); #else // __MQL5__ @@ -129,7 +128,7 @@ class Indi_ADX : public Indicator { double GetValue(int _mode = LINE_MAIN_ADX, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_ADX::iADX(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), @@ -137,7 +136,7 @@ class Indi_ADX : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); + iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -153,18 +152,18 @@ class Indi_ADX : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = Indi_ADX::GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsWithinRange(0.0, 100.0)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -185,14 +184,14 @@ class Indi_ADX : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get applied price value. * * Note: Not used in MT5. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -201,7 +200,7 @@ class Indi_ADX : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -211,6 +210,6 @@ class Indi_ADX : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index 4ca230c58..b66c2b4b4 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -53,22 +53,19 @@ struct ADXWParams : ADXParams { /** * Implements the Average Directional Movement Index indicator by Welles Wilder. */ -class Indi_ADXW : public Indicator { - protected: - ADXWParams params; - +class Indi_ADXW : public Indicator { public: /** * Class constructor. */ - Indi_ADXW(ADXWParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ADXW(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ADXW, _tf) { params.tf = _tf; }; + Indi_ADXW(ADXWParams &_params) : Indicator(_params){}; + Indi_ADXW(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ADXW, _tf){}; /** * Built-in version of ADX Wilder. */ static double iADXWilder(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _mode = LINE_MAIN_ADX, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iADXWilder(_symbol, _tf, _ma_period), _mode, _shift); #else @@ -219,13 +216,13 @@ class Indi_ADXW : public Indicator { double GetValue(int _mode = LINE_MAIN_ADX, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_ADXW::iADXWilder(GetSymbol(), GetTf(), GetPeriod(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); break; default: @@ -242,12 +239,12 @@ class Indi_ADXW : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_DOUBLE, true); @@ -273,7 +270,7 @@ class Indi_ADXW : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /* Setters */ @@ -282,6 +279,6 @@ class Indi_ADXW : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } }; diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index 0041828d0..5f9f8dabd 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -57,10 +57,12 @@ struct IndiAMAParams : IndicatorParams { } break; case IDATA_INDICATOR: - if (GetDataSource() == NULL) { + /* @fixme + if (indi_src == NULL) { SetDataSource(Indi_Price::GetCached(_shift, _tf, _ap, _period), false); SetDataSourceMode(0); } + */ break; } }; @@ -73,22 +75,20 @@ struct IndiAMAParams : IndicatorParams { /** * Implements the AMA indicator. */ -class Indi_AMA : public Indicator { - protected: - IndiAMAParams params; - +class Indi_AMA : public Indicator { public: /** * Class constructor. */ - Indi_AMA(IndiAMAParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { params = _params; }; - Indi_AMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AMA, _tf) { params.tf = _tf; }; + Indi_AMA(IndiAMAParams &_params) : Indicator(_params){}; + Indi_AMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AMA, _tf){}; /** * Built-in version of AMA. */ static double iAMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ama_period, int _fast_ema_period, int _slow_ema_period, - int _ama_shift, ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + int _ama_shift, ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, + Indicator *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN( ::iAMA(_symbol, _tf, _ama_period, _fast_ema_period, _slow_ema_period, _ama_shift, _ap), _mode, _shift); @@ -215,13 +215,13 @@ class Indi_AMA : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_AMA::iAMA(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetFastPeriod(), GetSlowPeriod(), GetAMAShift(), GetAppliedPrice() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod(), GetFastPeriod(), GetSlowPeriod(), GetAMAShift() /*]*/, _mode, _shift); break; @@ -243,17 +243,17 @@ class Indi_AMA : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -274,27 +274,27 @@ class Indi_AMA : public Indicator { /** * Get AMA shift. */ - unsigned int GetAMAShift() { return params.ama_shift; } + unsigned int GetAMAShift() { return iparams.ama_shift; } /** * Get period. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get fast period. */ - unsigned int GetFastPeriod() { return params.fast_period; } + unsigned int GetFastPeriod() { return iparams.fast_period; } /** * Get slow period. */ - unsigned int GetSlowPeriod() { return params.slow_period; } + unsigned int GetSlowPeriod() { return iparams.slow_period; } /** * Get applied price. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -303,7 +303,7 @@ class Indi_AMA : public Indicator { */ void SetAMAShift(unsigned int _ama_shift) { istate.is_changed = true; - params.ama_shift = _ama_shift; + iparams.ama_shift = _ama_shift; } /** @@ -311,7 +311,7 @@ class Indi_AMA : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -319,7 +319,7 @@ class Indi_AMA : public Indicator { */ void SetFastPeriod(unsigned int _fast_period) { istate.is_changed = true; - params.fast_period = _fast_period; + iparams.fast_period = _fast_period; } /** @@ -327,7 +327,7 @@ class Indi_AMA : public Indicator { */ void SetSlowPeriod(unsigned int _slow_period) { istate.is_changed = true; - params.slow_period = _slow_period; + iparams.slow_period = _slow_period; } /** @@ -335,6 +335,6 @@ class Indi_AMA : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index d93977120..29d1f4e63 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -53,16 +53,13 @@ struct AOParams : IndicatorParams { /** * Implements the Awesome oscillator. */ -class Indi_AO : public Indicator { - protected: - AOParams params; - +class Indi_AO : public Indicator { public: /** * Class constructor. */ - Indi_AO(AOParams &_p) : Indicator((IndicatorParams)_p) { params = _p; }; - Indi_AO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : params(_tf), Indicator(INDI_AO, _tf){}; + Indi_AO(AOParams &_p) : Indicator(_p){}; + Indi_AO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AO, _tf){}; /** * Returns the indicator value. @@ -72,7 +69,7 @@ class Indi_AO : public Indicator { * - https://www.mql5.com/en/docs/indicators/iao */ static double iAO(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, int _mode = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ // Note: In MQL4 _mode is not supported. return ::iAO(_symbol, _tf, _shift); @@ -112,7 +109,7 @@ class Indi_AO : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_AO::iAO(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), _shift, _mode, @@ -120,7 +117,7 @@ class Indi_AO : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), _mode, _shift); + iparams.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -136,17 +133,17 @@ class Indi_AO : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.values[0].Get() != EMPTY_VALUE); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index 25019c8df..1f37ea8c8 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -50,22 +50,19 @@ struct ASIParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_ASI : public Indicator { - protected: - ASIParams params; - +class Indi_ASI : public Indicator { public: /** * Class constructor. */ - Indi_ASI(ASIParams &_params) : params(_params.mpc), Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ASI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ASI, _tf) { params.tf = _tf; }; + Indi_ASI(ASIParams &_params) : iparams(_params.mpc), Indicator(_params){}; + Indi_ASI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ASI, _tf){}; /** * Built-in version of ASI. */ static double iASI(string _symbol, ENUM_TIMEFRAMES _tf, double _mpc, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, Util::MakeKey("Indi_ASI", _mpc)); return iASIOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mpc, _mode, _shift, _cache); } @@ -165,12 +162,12 @@ class Indi_ASI : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_ASI::iASI(GetSymbol(), GetTf(), /*[*/ GetMaximumPriceChanging() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetMaximumPriceChanging() /*]*/, 0, _shift); break; default: @@ -187,17 +184,17 @@ class Indi_ASI : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -218,7 +215,7 @@ class Indi_ASI : public Indicator { /** * Get maximum price changing value. */ - double GetMaximumPriceChanging() { return params.mpc; } + double GetMaximumPriceChanging() { return iparams.mpc; } /* Setters */ @@ -227,6 +224,6 @@ class Indi_ASI : public Indicator { */ void GetMaximumPriceChanging(double _mpc) { istate.is_changed = true; - params.mpc = _mpc; + iparams.mpc = _mpc; } }; diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index e005da486..23a903850 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -55,15 +55,12 @@ struct ATRParams : IndicatorParams { * * Note: It doesn't give independent signals. It is used to define volatility (trend strength). */ -class Indi_ATR : public Indicator { - public: - ATRParams params; - +class Indi_ATR : public Indicator { /** * Class constructor. */ - Indi_ATR(ATRParams &_p) : params(_p.period), Indicator((IndicatorParams)_p) { params = _p; } - Indi_ATR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ATR, _tf) { params.SetTf(_tf); }; + Indi_ATR(ATRParams &_p) : Indicator(_p) {} + Indi_ATR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ATR, _tf){}; /** * Returns the indicator value. @@ -73,7 +70,7 @@ class Indi_ATR : public Indicator { * - https://www.mql5.com/en/docs/indicators/iatr */ static double iATR(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iATR(_symbol, _tf, _period, _shift); #else // __MQL5__ @@ -112,13 +109,13 @@ class Indi_ATR : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_ATR::iATR(GetSymbol(), GetTf(), GetPeriod(), _shift, GetPointer(this)); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -134,17 +131,17 @@ class Indi_ATR : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -179,7 +176,7 @@ class Indi_ATR : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /* Setters */ @@ -188,6 +185,6 @@ class Indi_ATR : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } }; diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index cb7877526..0800766e9 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -97,15 +97,11 @@ struct AlligatorParams : IndicatorParams { /** * Implements the Alligator indicator. */ -class Indi_Alligator : public Indicator { - public: - AlligatorParams params; - +class Indi_Alligator : public Indicator { /** * Class constructor. */ - Indi_Alligator(AlligatorParams &_p) : Indicator((IndicatorParams)_p) { params = _p; } - Indi_Alligator(AlligatorParams &_p, ENUM_TIMEFRAMES _tf) : Indicator(INDI_ALLIGATOR, _tf) { params = _p; } + Indi_Alligator(AlligatorParams &_p) : Indicator(_p) {} Indi_Alligator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ADX, _tf){}; /** @@ -129,7 +125,7 @@ class Indi_Alligator : public Indicator { static double iAlligator(string _symbol, ENUM_TIMEFRAMES _tf, int _jaw_period, int _jaw_shift, int _teeth_period, int _teeth_shift, int _lips_period, int _lips_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, ENUM_ALLIGATOR_LINE _mode, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iAlligator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift, _ma_method, _applied_price, _mode, _shift); @@ -176,7 +172,7 @@ class Indi_Alligator : public Indicator { #endif ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_Alligator::iAlligator(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), @@ -186,7 +182,7 @@ class Indi_Alligator : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ + iparams.GetCustomIndicatorName(), /*[*/ GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), GetAppliedPrice() @@ -207,18 +203,18 @@ class Indi_Alligator : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_ALLIGATOR_LINE)_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -243,42 +239,42 @@ class Indi_Alligator : public Indicator { /** * Get jaw period value. */ - int GetJawPeriod() { return params.jaw_period; } + int GetJawPeriod() { return iparams.jaw_period; } /** * Get jaw shift value. */ - int GetJawShift() { return params.jaw_shift; } + int GetJawShift() { return iparams.jaw_shift; } /** * Get teeth period value. */ - int GetTeethPeriod() { return params.teeth_period; } + int GetTeethPeriod() { return iparams.teeth_period; } /** * Get teeth shift value. */ - int GetTeethShift() { return params.teeth_shift; } + int GetTeethShift() { return iparams.teeth_shift; } /** * Get lips period value. */ - int GetLipsPeriod() { return params.lips_period; } + int GetLipsPeriod() { return iparams.lips_period; } /** * Get lips shift value. */ - int GetLipsShift() { return params.lips_shift; } + int GetLipsShift() { return iparams.lips_shift; } /** * Get MA method. */ - ENUM_MA_METHOD GetMAMethod() { return params.ma_method; } + ENUM_MA_METHOD GetMAMethod() { return iparams.ma_method; } /** * Get applied price value. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Class setters */ @@ -287,7 +283,7 @@ class Indi_Alligator : public Indicator { */ void SetJawPeriod(int _jaw_period) { istate.is_changed = true; - params.jaw_period = _jaw_period; + iparams.jaw_period = _jaw_period; } /** @@ -295,7 +291,7 @@ class Indi_Alligator : public Indicator { */ void SetJawShift(int _jaw_shift) { istate.is_changed = true; - params.jaw_shift = _jaw_shift; + iparams.jaw_shift = _jaw_shift; } /** @@ -303,7 +299,7 @@ class Indi_Alligator : public Indicator { */ void SetTeethPeriod(int _teeth_period) { istate.is_changed = true; - params.teeth_period = _teeth_period; + iparams.teeth_period = _teeth_period; } /** @@ -311,7 +307,7 @@ class Indi_Alligator : public Indicator { */ void SetTeethShift(int _teeth_shift) { istate.is_changed = true; - params.teeth_period = _teeth_shift; + iparams.teeth_period = _teeth_shift; } /** @@ -319,7 +315,7 @@ class Indi_Alligator : public Indicator { */ void SetLipsPeriod(int _lips_period) { istate.is_changed = true; - params.lips_period = _lips_period; + iparams.lips_period = _lips_period; } /** @@ -327,7 +323,7 @@ class Indi_Alligator : public Indicator { */ void SetLipsShift(int _lips_shift) { istate.is_changed = true; - params.lips_period = _lips_shift; + iparams.lips_period = _lips_shift; } /** @@ -335,7 +331,7 @@ class Indi_Alligator : public Indicator { */ void SetMAMethod(ENUM_MA_METHOD _ma_method) { istate.is_changed = true; - params.ma_method = _ma_method; + iparams.ma_method = _ma_method; } /** @@ -343,6 +339,6 @@ class Indi_Alligator : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index a83920e50..2342303a6 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -48,18 +48,16 @@ struct AppliedPriceParams : IndicatorParams { /** * Implements the "Applied Price over OHCL Indicator" indicator, e.g. over Indi_Price. */ -class Indi_AppliedPrice : public Indicator { - protected: - AppliedPriceParams params; - +class Indi_AppliedPrice : public Indicator { public: /** * Class constructor. */ - Indi_AppliedPrice(AppliedPriceParams &_params) : params(_params), Indicator((IndicatorParams)_params){}; - Indi_AppliedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : params(PRICE_OPEN, 0, _tf), Indicator(INDI_PRICE, _tf){}; + Indi_AppliedPrice(AppliedPriceParams &_params) : iparams(_params), Indicator(_params){}; + Indi_AppliedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : iparams(PRICE_OPEN, 0, _tf), Indicator(INDI_PRICE, _tf){}; - static double iAppliedPriceOnIndicator(Indicator *_indi, ENUM_APPLIED_PRICE _applied_price, int _shift = 0) { + static double iAppliedPriceOnIndicator(Indicator *_indi, ENUM_APPLIED_PRICE _applied_price, + int _shift = 0) { double _ohlc[4]; _indi[_shift].GetArray(_ohlc, 4); return BarOHLC::GetAppliedPrice(_applied_price, _ohlc[0], _ohlc[1], _ohlc[2], _ohlc[3]); @@ -71,18 +69,18 @@ class Indi_AppliedPrice : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_INDICATOR: if (HasDataSource()) { - // Future validation of GetDataSource() will check if we set mode for source indicator + // Future validation of indi_src will check if we set mode for source indicator // (e.g. for applied price of Indi_Price). iparams.SetDataSourceMode(GetAppliedPrice()); } - if (GetDataSource().GetParams().GetMaxModes() != 4) { + if (indi_src.GetParams().GetMaxModes() != 4) { Print("Indi_AppliedPrice indicator requires that has at least 4 modes/buffers (OHLC)!"); DebugBreak(); } - _value = Indi_AppliedPrice::iAppliedPriceOnIndicator(GetDataSource(), GetAppliedPrice(), _shift); + _value = Indi_AppliedPrice::iAppliedPriceOnIndicator(indi_src, GetAppliedPrice(), _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -98,17 +96,17 @@ class Indi_AppliedPrice : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -129,7 +127,7 @@ class Indi_AppliedPrice : public Indicator { /** * Get applied price. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -138,6 +136,6 @@ class Indi_AppliedPrice : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index 3929ea7db..d92c9410f 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -61,15 +61,12 @@ struct BWMFIParams : IndicatorParams { /** * Implements the Market Facilitation Index by Bill Williams indicator. */ -class Indi_BWMFI : public Indicator { - protected: - BWMFIParams params; - +class Indi_BWMFI : public Indicator { public: /** * Class constructor. */ - Indi_BWMFI(IndicatorParams &_p) : Indicator((IndicatorParams)_p) {} + Indi_BWMFI(BWMFIParams &_p) : Indicator(_p) {} Indi_BWMFI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BWMFI, _tf) {} /** @@ -80,7 +77,7 @@ class Indi_BWMFI : public Indicator { * - https://www.mql5.com/en/docs/indicators/ibwmfi */ static double iBWMFI(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, - ENUM_BWMFI_BUFFER _mode = BWMFI_BUFFER, Indicator *_obj = NULL) { + ENUM_BWMFI_BUFFER _mode = BWMFI_BUFFER, Indicator *_obj = NULL) { #ifdef __MQL4__ // Adjusting shift for MT4. _shift++; @@ -121,7 +118,7 @@ class Indi_BWMFI : public Indicator { double GetValue(ENUM_BWMFI_BUFFER _mode = BWMFI_BUFFER, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = _value = iBWMFI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), _shift, _mode, @@ -129,7 +126,7 @@ class Indi_BWMFI : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ VOLUME_TICK /*]*/, _mode, _shift); + iparams.GetCustomIndicatorName(), /*[*/ VOLUME_TICK /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -145,7 +142,7 @@ class Indi_BWMFI : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -188,7 +185,7 @@ class Indi_BWMFI : public Indicator { _entry.values[BWMFI_HISTCOLOR] = _histcolor; _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.values[BWMFI_BUFFER] != 0 && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 4da952fe2..830dd74b1 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -51,25 +51,23 @@ struct BWZTParams : IndicatorParams { /** * Implements the Bill Williams' Zone Trade. */ -class Indi_BWZT : public Indicator { - protected: - BWZTParams params; - +class Indi_BWZT : public Indicator { public: /** * Class constructor. */ - Indi_BWZT(BWZTParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_BWZT(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BWZT, _tf) { params.tf = _tf; }; + Indi_BWZT(BWZTParams &_params) : Indicator(_params){}; + Indi_BWZT(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BWZT, _tf){}; /** * Built-in version of BWZT. */ - static double iBWZT(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + static double iBWZT(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_BWZT"); - Indicator *_indi_ac = Indi_AC::GetCached(_symbol, _tf); - Indicator *_indi_ao = Indi_AO::GetCached(_symbol, _tf); + Indi_AC *_indi_ac = Indi_AC::GetCached(_symbol, _tf); + Indi_AO *_indi_ao = Indi_AO::GetCached(_symbol, _tf); return iBWZTOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _shift, _cache, _indi_ac, _indi_ao); } @@ -78,7 +76,7 @@ class Indi_BWZT : public Indicator { * Calculates BWZT on the array of values. */ static double iBWZTOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _shift, - IndicatorCalculateCache *_cache, Indicator *_indi_ac, Indicator *_indi_ao, + IndicatorCalculateCache *_cache, Indi_AC *_indi_ac, Indi_AO *_indi_ao, bool _recalculate = false) { _cache.SetPriceBuffer(_open, _high, _low, _close); @@ -105,7 +103,7 @@ class Indi_BWZT : public Indicator { ValueStorage &ExtHBuffer, ValueStorage &ExtLBuffer, ValueStorage &ExtCBuffer, ValueStorage &ExtColorBuffer, ValueStorage &ExtAOBuffer, ValueStorage &ExtACBuffer, int DATA_LIMIT, - Indicator *ExtACHandle, Indicator *ExtAOHandle) { + Indicator *ExtACHandle, Indicator *ExtAOHandle) { if (rates_total < DATA_LIMIT) return (0); // Not all data may be calculated. int calculated = BarsCalculated(ExtACHandle, rates_total); @@ -169,12 +167,12 @@ class Indi_BWZT : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_BWZT::iBWZT(GetSymbol(), GetTf(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -190,17 +188,17 @@ class Indi_BWZT : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 1ba81ec8f..982f76177 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -83,23 +83,13 @@ struct BandsParams : IndicatorParams { /** * Implements the Bollinger Bands® indicator. */ -class Indi_Bands : public Indicator { - protected: - // Structs. - BandsParams params; - +class Indi_Bands : public Indicator { public: /** * Class constructor. */ - Indi_Bands(BandsParams &_p) - : params(_p.period, _p.deviation, _p.shift, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Bands(BandsParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.deviation, _p.shift, _p.applied_price), Indicator(INDI_BANDS, _tf) { - params = _p; - } + Indi_Bands(BandsParams &_p) : Indicator(_p) {} + Indi_Bands(ENUM_TIMEFRAMES _tf) : Indicator(INDI_BANDS, _tf) {} /** * Returns the indicator value. @@ -110,7 +100,7 @@ class Indi_Bands : public Indicator { */ static double iBands(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, double _deviation, int _bands_shift, ENUM_APPLIED_PRICE _applied_price, ENUM_BANDS_LINE _mode = BAND_BASE, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { ResetLastError(); #ifdef __MQL4__ @@ -150,11 +140,12 @@ class Indi_Bands : public Indicator { * * When _applied_price is set to -1, method will */ - static double iBandsOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, + template + static double iBandsOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, double _deviation, int _bands_shift, ENUM_BANDS_LINE _mode, // (MT4/MT5): 0 - MODE_MAIN/BASE_LINE, 1 - // MODE_UPPER/UPPER_BAND, 2 - MODE_LOWER/LOWER_BAND - int _shift, Indicator *_target = NULL) { + int _shift, Indi_Bands *_target = NULL) { double _indi_value_buffer[]; double _std_dev; double _line_value; @@ -242,8 +233,8 @@ class Indi_Bands : public Indicator { * extern double deviation; * extern ENUM_APPLIED_PRICE applied_price; // Required only for MQL4. * - * Also, remember to use params.SetCustomIndicatorName(name) method to choose - * indicator name, e.g.,: params.SetCustomIndicatorName("Examples\\BB"); + * Also, remember to use iparams.SetCustomIndicatorName(name) method to choose + * indicator name, e.g.,: iparams.SetCustomIndicatorName("Examples\\BB"); * * Note that in MQL5 Applied Price must be passed as the last parameter * (before mode and shift). @@ -251,7 +242,7 @@ class Indi_Bands : public Indicator { double GetValue(ENUM_BANDS_LINE _mode, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = @@ -260,12 +251,12 @@ class Indi_Bands : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /* [ */ GetPeriod(), GetBandsShift(), GetDeviation(), + iparams.custom_indi_name, /* [ */ GetPeriod(), GetBandsShift(), GetDeviation(), GetAppliedPrice() /* ] */, _mode, _shift); break; case IDATA_INDICATOR: // Calculating bands value from specified indicator. - _value = Indi_Bands::iBandsOnIndicator(GetDataSource(), Get(CHART_PARAM_SYMBOL), + _value = Indi_Bands::iBandsOnIndicator(indi_src, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), GetDeviation(), GetBandsShift(), _mode, _shift, &this); break; @@ -281,19 +272,19 @@ class Indi_Bands : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_BANDS_LINE)_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0) && _entry.values[BAND_LOWER].GetDbl() < _entry.values[BAND_UPPER].GetDbl()); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -313,6 +304,7 @@ class Indi_Bands : public Indicator { /** * Provides built-in indicators whose can be used as data source. */ + /* @fixme virtual Indicator *FetchDataSource(ENUM_INDICATOR_TYPE _id) { if (_id == INDI_BANDS) { BandsParams bands_params(); @@ -339,28 +331,29 @@ class Indi_Bands : public Indicator { return Indicator::FetchDataSource(_id); } + */ /* Getters */ /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get deviation value. */ - double GetDeviation() { return params.deviation; } + double GetDeviation() { return iparams.deviation; } /** * Get bands shift value. */ - unsigned int GetBandsShift() { return params.bshift; } + unsigned int GetBandsShift() { return iparams.bshift; } /** * Get applied price value. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -369,7 +362,7 @@ class Indi_Bands : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -377,7 +370,7 @@ class Indi_Bands : public Indicator { */ void SetDeviation(double _deviation) { istate.is_changed = true; - params.deviation = _deviation; + iparams.deviation = _deviation; } /** @@ -385,7 +378,7 @@ class Indi_Bands : public Indicator { */ void SetBandsShift(int _bshift) { istate.is_changed = true; - params.bshift = _bshift; + iparams.bshift = _bshift; } /** @@ -393,6 +386,6 @@ class Indi_Bands : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index ddc259ddb..14e41420b 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -53,20 +53,13 @@ struct BearsPowerParams : IndicatorParams { /** * Implements the Bears Power indicator. */ -class Indi_BearsPower : public Indicator { +class Indi_BearsPower : public Indicator { public: - BearsPowerParams params; - /** * Class constructor. */ - Indi_BearsPower(BearsPowerParams &_p) : params(_p.period, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_BearsPower(BearsPowerParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.applied_price), Indicator(INDI_BEARS, _tf) { - params = _p; - } + Indi_BearsPower(BearsPowerParams &_p) : Indicator(_p) {} + Indi_BearsPower(ENUM_TIMEFRAMES _tf) : Indicator(INDI_BEARS, _tf) {} /** * Returns the indicator value. @@ -77,7 +70,7 @@ class Indi_BearsPower : public Indicator { */ static double iBearsPower(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _applied_price, // (MT5): not used - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iBearsPower(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ @@ -116,7 +109,7 @@ class Indi_BearsPower : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = _value = iBearsPower(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), @@ -124,7 +117,7 @@ class Indi_BearsPower : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); + iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -140,17 +133,17 @@ class Indi_BearsPower : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -171,14 +164,14 @@ class Indi_BearsPower : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get applied price value. * * Note: Not used in MT5. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -187,7 +180,7 @@ class Indi_BearsPower : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -197,6 +190,6 @@ class Indi_BearsPower : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index fc08d911b..eb7a784d7 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -53,22 +53,13 @@ struct BullsPowerParams : IndicatorParams { /** * Implements the Bulls Power indicator. */ -class Indi_BullsPower : public Indicator { - protected: - // Struct variables. - BullsPowerParams params; - +class Indi_BullsPower : public Indicator { public: /** * Class constructor. */ - Indi_BullsPower(BullsPowerParams &_p) : params(_p.period, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_BullsPower(BullsPowerParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.applied_price), Indicator(INDI_BULLS, _tf) { - params = _p; - } + Indi_BullsPower(BullsPowerParams &_p) : Indicator(_p) {} + Indi_BullsPower(ENUM_TIMEFRAMES _tf) : Indicator(INDI_BULLS, _tf) {} /** * Returns the indicator value. @@ -79,7 +70,7 @@ class Indi_BullsPower : public Indicator { */ static double iBullsPower(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _applied_price, // (MT5): not used - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iBullsPower(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ @@ -118,7 +109,7 @@ class Indi_BullsPower : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = iBullsPower(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), @@ -126,7 +117,7 @@ class Indi_BullsPower : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /**/ GetPeriod() /**/, _mode, _shift); + iparams.GetCustomIndicatorName(), /**/ GetPeriod() /**/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -142,17 +133,17 @@ class Indi_BullsPower : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -173,14 +164,14 @@ class Indi_BullsPower : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get applied price value. * * Note: Not used in MT5. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -189,7 +180,7 @@ class Indi_BullsPower : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -199,6 +190,6 @@ class Indi_BullsPower : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 76e4642af..14cac7b04 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -59,20 +59,13 @@ struct CCIParams : IndicatorParams { /** * Implements the Commodity Channel Index indicator. */ -class Indi_CCI : public Indicator { +class Indi_CCI : public Indicator { public: - CCIParams params; - /** * Class constructor. */ - Indi_CCI(CCIParams &_p) : params(_p.period, _p.applied_price, _p.shift), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_CCI(CCIParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.applied_price, _p.shift), Indicator(INDI_CCI, _tf) { - params = _p; - } + Indi_CCI(CCIParams &_p) : Indicator(_p) {} + Indi_CCI(ENUM_TIMEFRAMES _tf) : Indicator(INDI_CCI, _tf) {} /** * Returns the indicator value. @@ -82,7 +75,7 @@ class Indi_CCI : public Indicator { * - https://www.mql5.com/en/docs/indicators/icci */ static double iCCI(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _applied_price, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iCCI(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ @@ -115,8 +108,8 @@ class Indi_CCI : public Indicator { #endif } - static double iCCIOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _mode, - int _shift = 0) { + static double iCCIOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, + int _mode, int _shift = 0) { _indi.ValidateDataSourceMode(_mode); double _indi_value_buffer[]; @@ -172,8 +165,8 @@ class Indi_CCI : public Indicator { * extern unsigned int period; * extern ENUM_APPLIED_PRICE applied_price; // Required only for MQL4. * - * Also, remember to use params.SetCustomIndicatorName(name) method to choose - * indicator name, e.g.,: params.SetCustomIndicatorName("Examples\\CCI"); + * Also, remember to use iparams.SetCustomIndicatorName(name) method to choose + * indicator name, e.g.,: iparams.SetCustomIndicatorName("Examples\\CCI"); * * Note that in MQL5 Applied Price must be passed as the last parameter * (before mode and shift). @@ -181,24 +174,24 @@ class Indi_CCI : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; // @fixit Somehow shift isn't used neither in MT4 nor MT5. _value = Indi_CCI::iCCI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetAppliedPrice(), _shift /* + params.shift*/, GetPointer(this)); + GetAppliedPrice(), _shift /* + iparams.shift*/, GetPointer(this)); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /* [ */ GetPeriod(), GetAppliedPrice() /* ] */, 0, _shift); + iparams.custom_indi_name, /* [ */ GetPeriod(), GetAppliedPrice() /* ] */, 0, _shift); break; case IDATA_INDICATOR: ValidateSelectedDataSource(); // @fixit Somehow shift isn't used neither in MT4 nor MT5. - _value = Indi_CCI::iCCIOnIndicator(GetDataSource(), Get(CHART_PARAM_SYMBOL), - Get(CHART_PARAM_TF), GetPeriod(), GetDataSourceMode(), - _shift /* + params.shift*/); + _value = + Indi_CCI::iCCIOnIndicator(indi_src, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), + GetPeriod(), GetDataSourceMode(), _shift /* + iparams.shift*/); break; } istate.is_ready = _LastError == ERR_NO_ERROR; @@ -212,7 +205,7 @@ class Indi_CCI : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -220,7 +213,7 @@ class Indi_CCI : public Indicator { _entry.values[0] = GetValue(0); _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -241,12 +234,12 @@ class Indi_CCI : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get applied price value. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -255,7 +248,7 @@ class Indi_CCI : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -263,6 +256,6 @@ class Indi_CCI : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index a9515f31f..6b87bb1fb 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -56,27 +56,20 @@ struct CHOParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_CHO : public Indicator { - protected: - CHOParams params; - +class Indi_CHO : public Indicator { public: /** * Class constructor. */ - Indi_CHO(CHOParams &_params) - : params(_params.fast_ma, _params.slow_ma, _params.smooth_method, _params.input_volume), - Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_CHO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN, _tf) { params.tf = _tf; }; + Indi_CHO(CHOParams &_params) : Indicator(_params){}; + Indi_CHO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN, _tf){}; /** * Built-in version of Chaikin Oscillator. */ static double iChaikin(string _symbol, ENUM_TIMEFRAMES _tf, int _fast_ma_period, int _slow_ma_period, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_VOLUME _av, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iChaikin(_symbol, _tf, _fast_ma_period, _slow_ma_period, _ma_method, _av), _mode, _shift); @@ -178,14 +171,14 @@ class Indi_CHO : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_CHO::iChaikin(GetSymbol(), GetTf(), /*[*/ GetSlowMA(), GetFastMA(), GetSmoothMethod(), GetInputVolume() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetFastMA(), GetSlowMA(), GetSmoothMethod(), + iparams.GetCustomIndicatorName(), /*[*/ GetFastMA(), GetSlowMA(), GetSmoothMethod(), GetInputVolume() /*]*/, 0, _shift); break; default: @@ -202,17 +195,17 @@ class Indi_CHO : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -233,22 +226,22 @@ class Indi_CHO : public Indicator { /** * Get fast moving average. */ - unsigned int GetFastMA() { return params.fast_ma; } + unsigned int GetFastMA() { return iparams.fast_ma; } /** * Get slow moving average. */ - unsigned int GetSlowMA() { return params.slow_ma; } + unsigned int GetSlowMA() { return iparams.slow_ma; } /** * Get smooth method. */ - ENUM_MA_METHOD GetSmoothMethod() { return params.smooth_method; } + ENUM_MA_METHOD GetSmoothMethod() { return iparams.smooth_method; } /** * Get input volume. */ - ENUM_APPLIED_VOLUME GetInputVolume() { return params.input_volume; } + ENUM_APPLIED_VOLUME GetInputVolume() { return iparams.input_volume; } /* Setters */ @@ -257,7 +250,7 @@ class Indi_CHO : public Indicator { */ void SetFastMA(unsigned int _fast_ma) { istate.is_changed = true; - params.fast_ma = _fast_ma; + iparams.fast_ma = _fast_ma; } /** @@ -265,7 +258,7 @@ class Indi_CHO : public Indicator { */ void SetSlowMA(unsigned int _slow_ma) { istate.is_changed = true; - params.slow_ma = _slow_ma; + iparams.slow_ma = _slow_ma; } /** @@ -273,7 +266,7 @@ class Indi_CHO : public Indicator { */ void SetSmoothMethod(ENUM_MA_METHOD _smooth_method) { istate.is_changed = true; - params.smooth_method = _smooth_method; + iparams.smooth_method = _smooth_method; } /** @@ -281,6 +274,6 @@ class Indi_CHO : public Indicator { */ void SetInputVolume(ENUM_APPLIED_VOLUME _input_volume) { istate.is_changed = true; - params.input_volume = _input_volume; + iparams.input_volume = _input_volume; } }; diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 03770e765..57da08378 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -58,25 +58,20 @@ struct CHVParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_CHV : public Indicator { - protected: - CHVParams params; - +class Indi_CHV : public Indicator { public: /** * Class constructor. */ - Indi_CHV(CHVParams &_params) - : params(_params.smooth_period, _params.chv_period, _params.smooth_method), Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_CHV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN_V, _tf) { params.tf = _tf; }; + Indi_CHV(CHVParams &_params) : Indicator(_params){}; + Indi_CHV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN_V, _tf){}; /** * Built-in version of Chaikin Volatility. */ static double iCHV(string _symbol, ENUM_TIMEFRAMES _tf, int _smooth_period, int _chv_period, - ENUM_CHV_SMOOTH_METHOD _smooth_method, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + ENUM_CHV_SMOOTH_METHOD _smooth_method, int _mode = 0, int _shift = 0, + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG( _symbol, _tf, Util::MakeKey("Indi_CHV", _smooth_period, _chv_period, _smooth_method)); return iCHVOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _smooth_period, _chv_period, _smooth_method, _mode, @@ -174,13 +169,13 @@ class Indi_CHV : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_CHV::iCHV(GetSymbol(), GetTf(), /*[*/ GetSmoothPeriod(), GetCHVPeriod(), GetSmoothMethod() /*]*/, _mode, _shift); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetSmoothPeriod(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetSmoothPeriod(), GetCHVPeriod(), GetSmoothMethod() /*]*/, _mode, _shift); break; default: @@ -197,17 +192,17 @@ class Indi_CHV : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -228,17 +223,17 @@ class Indi_CHV : public Indicator { /** * Get smooth period. */ - unsigned int GetSmoothPeriod() { return params.smooth_period; } + unsigned int GetSmoothPeriod() { return iparams.smooth_period; } /** * Get Chaikin period. */ - unsigned int GetCHVPeriod() { return params.chv_period; } + unsigned int GetCHVPeriod() { return iparams.chv_period; } /** * Get smooth method. */ - ENUM_CHV_SMOOTH_METHOD GetSmoothMethod() { return params.smooth_method; } + ENUM_CHV_SMOOTH_METHOD GetSmoothMethod() { return iparams.smooth_method; } /* Setters */ @@ -247,7 +242,7 @@ class Indi_CHV : public Indicator { */ void SetSmoothPeriod(unsigned int _smooth_period) { istate.is_changed = true; - params.smooth_period = _smooth_period; + iparams.smooth_period = _smooth_period; } /** @@ -255,7 +250,7 @@ class Indi_CHV : public Indicator { */ void SetCHVPeriod(unsigned int _chv_period) { istate.is_changed = true; - params.chv_period = _chv_period; + iparams.chv_period = _chv_period; } /** @@ -263,6 +258,6 @@ class Indi_CHV : public Indicator { */ void SetSmoothMethod(ENUM_CHV_SMOOTH_METHOD _smooth_method) { istate.is_changed = true; - params.smooth_method = _smooth_method; + iparams.smooth_method = _smooth_method; } }; diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index ea61fb171..402e00f8e 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -46,21 +46,19 @@ struct ColorBarsParams : IndicatorParams { /** * Implements Color Bars */ -class Indi_ColorBars : public Indicator { - protected: - ColorBarsParams params; - +class Indi_ColorBars : public Indicator { public: /** * Class constructor. */ - Indi_ColorBars(ColorBarsParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ColorBars(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_BARS, _tf) { params.tf = _tf; }; + Indi_ColorBars(ColorBarsParams &_params) : Indicator(_params){}; + Indi_ColorBars(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_BARS, _tf){}; /** * "Built-in" version of Color Bars. */ - static double iColorBars(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + static double iColorBars(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_ColorCandlesDaily"); return iColorBarsOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _shift, _cache); } @@ -121,12 +119,12 @@ class Indi_ColorBars : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_ColorBars::iColorBars(GetSymbol(), GetTf(), _mode, _shift, GetPointer(this)); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -142,17 +140,17 @@ class Indi_ColorBars : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index b21b93ec6..55d01e571 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -46,23 +46,19 @@ struct ColorCandlesDailyParams : IndicatorParams { /** * Implements Color Bars */ -class Indi_ColorCandlesDaily : public Indicator { - protected: - ColorCandlesDailyParams params; - +class Indi_ColorCandlesDaily : public Indicator { public: /** * Class constructor. */ - Indi_ColorCandlesDaily(ColorCandlesDailyParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ColorCandlesDaily(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_CANDLES_DAILY, _tf) { - params.tf = _tf; - }; + Indi_ColorCandlesDaily(ColorCandlesDailyParams &_params) : Indicator(_params){}; + Indi_ColorCandlesDaily(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_CANDLES_DAILY, _tf){}; /** * "Built-in" version of Color Candles Daily. */ - static double iCCD(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + static double iCCD(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_ColorCandlesDaily"); return iCCDOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _shift, _cache); } @@ -120,12 +116,12 @@ class Indi_ColorCandlesDaily : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_ColorCandlesDaily::iCCD(GetSymbol(), GetTf(), _mode, _shift, GetPointer(this)); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -141,17 +137,17 @@ class Indi_ColorCandlesDaily : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index bfab1ac01..ef4e8891d 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -47,24 +47,22 @@ struct ColorLineParams : IndicatorParams { /** * Implements Color Bars */ -class Indi_ColorLine : public Indicator { - protected: - ColorLineParams params; - +class Indi_ColorLine : public Indicator { public: /** * Class constructor. */ - Indi_ColorLine(ColorLineParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_ColorLine(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_LINE, _tf) { params.tf = _tf; }; + Indi_ColorLine(ColorLineParams &_params) : Indicator(_params){}; + Indi_ColorLine(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_LINE, _tf){}; /** * "Built-in" version of Color Line. */ - static double iColorLine(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + static double iColorLine(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_ColorLine"); - Indicator *_indi_ma = Indi_MA::GetCached(_symbol, _tf, 10, 0, MODE_EMA, PRICE_CLOSE); + Indi_MA *_indi_ma = Indi_MA::GetCached(_symbol, _tf, 10, 0, MODE_EMA, PRICE_CLOSE); return iColorLineOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _shift, _cache, _indi_ma); } @@ -73,7 +71,7 @@ class Indi_ColorLine : public Indicator { * Calculates Color Line on the array of values. */ static double iColorLineOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _shift, - IndicatorCalculateCache *_cache, Indicator *_indi_ma, + IndicatorCalculateCache *_cache, Indi_ColorLine *_indi_ma, bool _recalculate = false) { _cache.SetPriceBuffer(_open, _high, _low, _close); @@ -95,7 +93,7 @@ class Indi_ColorLine : public Indicator { * OnCalculate() method for Color Line indicator. */ static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtColorLineBuffer, - ValueStorage &ExtColorsBuffer, Indicator *ExtMAHandle) { + ValueStorage &ExtColorsBuffer, Indi_ColorLine *ExtMAHandle) { static int ticks = 0, modified = 0; // Check data. int i, calculated = BarsCalculated(ExtMAHandle, rates_total); @@ -179,13 +177,13 @@ class Indi_ColorLine : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_ColorLine::iColorLine(GetSymbol(), GetTf(), _mode, _shift, GetPointer(this)); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), _mode, _shift); + iparams.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -201,17 +199,17 @@ class Indi_ColorLine : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index a5dab8e2e..01847fb56 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -54,20 +54,13 @@ struct CustomMovingAverageParams : IndicatorParams { /** * Implements the Custom Moving Average indicator. */ -class Indi_CustomMovingAverage : public Indicator { - protected: - CustomMovingAverageParams params; - +class Indi_CustomMovingAverage : public Indicator { public: /** * Class constructor. */ - Indi_CustomMovingAverage(CustomMovingAverageParams &_params) : Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_CustomMovingAverage(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CUSTOM_MOVING_AVG, _tf) { - params.tf = _tf; - }; + Indi_CustomMovingAverage(CustomMovingAverageParams &_params) : Indicator(_params){}; + Indi_CustomMovingAverage(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CUSTOM_MOVING_AVG, _tf){}; /** * Returns the indicator's value. @@ -75,10 +68,10 @@ class Indi_CustomMovingAverage : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetSmoothPeriod(), GetSmoothShift(), + iparams.GetCustomIndicatorName(), /*[*/ GetSmoothPeriod(), GetSmoothShift(), GetSmoothMethod() /*]*/, 0, _shift); break; default: @@ -95,17 +88,17 @@ class Indi_CustomMovingAverage : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -126,17 +119,17 @@ class Indi_CustomMovingAverage : public Indicator { /** * Get smooth period. */ - unsigned int GetSmoothPeriod() { return params.smooth_period; } + unsigned int GetSmoothPeriod() { return iparams.smooth_period; } /** * Get smooth shift. */ - unsigned int GetSmoothShift() { return params.smooth_shift; } + unsigned int GetSmoothShift() { return iparams.smooth_shift; } /** * Get smooth method. */ - ENUM_MA_METHOD GetSmoothMethod() { return params.smooth_method; } + ENUM_MA_METHOD GetSmoothMethod() { return iparams.smooth_method; } /* Setters */ @@ -145,7 +138,7 @@ class Indi_CustomMovingAverage : public Indicator { */ void SetSmoothPeriod(unsigned int _smooth_period) { istate.is_changed = true; - params.smooth_period = _smooth_period; + iparams.smooth_period = _smooth_period; } /** @@ -153,7 +146,7 @@ class Indi_CustomMovingAverage : public Indicator { */ void SetSmoothShift(unsigned int _smooth_shift) { istate.is_changed = true; - params.smooth_shift = _smooth_shift; + iparams.smooth_shift = _smooth_shift; } /** @@ -161,6 +154,6 @@ class Indi_CustomMovingAverage : public Indicator { */ void SetSmoothMethod(ENUM_MA_METHOD _smooth_method) { istate.is_changed = true; - params.smooth_method = _smooth_method; + iparams.smooth_method = _smooth_method; } }; diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 32d1a0f82..be1236ca9 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -58,10 +58,12 @@ struct DEMAParams : IndicatorParams { } break; case IDATA_INDICATOR: - if (GetDataSource() == NULL) { + /* @fixme + if (indi_src == NULL) { SetDataSource(Indi_Price::GetCached(_shift, _tf, _ap, _period), false); SetDataSourceMode(0); } + */ break; } }; @@ -74,22 +76,13 @@ struct DEMAParams : IndicatorParams { /** * Implements the Moving Average indicator. */ -class Indi_DEMA : public Indicator { - protected: - DEMAParams params; - +class Indi_DEMA : public Indicator { public: /** * Class constructor. */ - Indi_DEMA(DEMAParams &_p) - : params(_p.period, _p.ma_shift, _p.applied_price, _p.shift), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_DEMA(DEMAParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.ma_shift, _p.applied_price, _p.shift), Indicator(INDI_DEMA, _tf) { - params = _p; - } + Indi_DEMA(DEMAParams &_p) : Indicator(_p) {} + Indi_DEMA(DEMAParams &_p, ENUM_TIMEFRAMES _tf) : Indicator(INDI_DEMA, _tf) {} /** * Updates the indicator value. @@ -98,7 +91,8 @@ class Indi_DEMA : public Indicator { * - https://www.mql5.com/en/docs/indicators/IDEMA */ static double iDEMA(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, unsigned int _ma_shift, - ENUM_APPLIED_PRICE _applied_price, int _shift = 0, int _mode = 0, Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price, int _shift = 0, int _mode = 0, + Indicator *_obj = NULL) { ResetLastError(); #ifdef __MQL5__ int _handle = Object::IsValid(_obj) ? _obj.Get(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL; @@ -134,7 +128,8 @@ class Indi_DEMA : public Indicator { #endif } - static double iDEMAOnIndicator(IndicatorCalculateCache *cache, Indicator *indi, int indi_mode, + template + static double iDEMAOnIndicator(IndicatorCalculateCache *cache, Indicator *indi, int indi_mode, unsigned int ma_period, unsigned int ma_shift, int shift) { return iDEMAOnArray(indi.GetValueStorage(indi_mode), 0, ma_period, ma_shift, shift, cache); } @@ -195,7 +190,7 @@ class Indi_DEMA : public Indicator { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: // We're getting DEMA from Price indicator. @@ -207,12 +202,12 @@ class Indi_DEMA : public Indicator { istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /*[*/ GetPeriod(), GetMAShift(), GetAppliedPrice() /*]*/, _mode, _shift); + iparams.custom_indi_name, /*[*/ GetPeriod(), GetMAShift(), GetAppliedPrice() /*]*/, _mode, _shift); break; case IDATA_INDICATOR: // Calculating DEMA value from specified indicator. - _value = Indi_DEMA::iDEMAOnIndicator(GetCache(), GetDataSource(), GetDataSourceMode(), GetPeriod(), - GetMAShift(), _shift); + _value = + Indi_DEMA::iDEMAOnIndicator(GetCache(), indi_src, GetDataSourceMode(), GetPeriod(), GetMAShift(), _shift); break; } istate.is_ready = _LastError == ERR_NO_ERROR; @@ -226,17 +221,17 @@ class Indi_DEMA : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.IsGt(0) && _entry.IsLt(DBL_MAX)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -259,21 +254,21 @@ class Indi_DEMA : public Indicator { * * Averaging period for the calculation of the moving average. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get DEMA shift value. * * Indicators line offset relate to the chart by timeframe. */ - unsigned int GetMAShift() { return params.ma_shift; } + unsigned int GetMAShift() { return iparams.ma_shift; } /** * Get applied price value. * * The desired price base for calculations. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -284,7 +279,7 @@ class Indi_DEMA : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -292,7 +287,7 @@ class Indi_DEMA : public Indicator { */ void SetMAShift(int _ma_shift) { istate.is_changed = true; - params.ma_shift = _ma_shift; + iparams.ma_shift = _ma_shift; } /** @@ -305,7 +300,7 @@ class Indi_DEMA : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; #endif // INDI_DEMA_MQH diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index 56674d3f7..492b4c9c8 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -51,17 +51,12 @@ struct DeMarkerParams : IndicatorParams { /** * Implements the DeMarker indicator. */ -class Indi_DeMarker : public Indicator { - public: - DeMarkerParams params; - +class Indi_DeMarker : public Indicator { /** * Class constructor. */ - Indi_DeMarker(DeMarkerParams &_p) : params(_p.period), Indicator((IndicatorParams)_p) { params = _p; } - Indi_DeMarker(DeMarkerParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.period), Indicator(INDI_DEMARKER, _tf) { - params = _p; - } + Indi_DeMarker(DeMarkerParams &_p) : Indicator(_p) {} + Indi_DeMarker(ENUM_TIMEFRAMES _tf) : Indicator(INDI_DEMARKER, _tf) {} /** * Returns the indicator value. @@ -71,7 +66,7 @@ class Indi_DeMarker : public Indicator { * - https://www.mql5.com/en/docs/indicators/idemarker */ static double iDeMarker(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iDeMarker(_symbol, _tf, _period, _shift); #else // __MQL5__ @@ -110,7 +105,7 @@ class Indi_DeMarker : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = _value = @@ -119,7 +114,7 @@ class Indi_DeMarker : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); + iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -135,17 +130,17 @@ class Indi_DeMarker : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -166,7 +161,7 @@ class Indi_DeMarker : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /* Setters */ @@ -175,6 +170,6 @@ class Indi_DeMarker : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } }; diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index bd149b74b..bedbb2cb4 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -50,10 +50,12 @@ struct DemoIndiParams : IndicatorParams { } break; case IDATA_INDICATOR: - if (GetDataSource() == NULL) { + /* @fixme + if (indi_src == NULL) { SetDataSource(Indi_Price::GetCached(_shift, _tf), false); SetDataSourceMode(0); } + */ break; } }; @@ -66,23 +68,20 @@ struct DemoIndiParams : IndicatorParams { /** * Demo/Dummy Indicator. */ -class Indi_Demo : public Indicator { - protected: - DemoIndiParams params; - +class Indi_Demo : public Indicator { public: /** * Class constructor. */ - Indi_Demo(DemoIndiParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_Demo(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : params(_tf), Indicator(INDI_DEMO, _tf){}; + Indi_Demo(DemoIndiParams &_params) : Indicator(_params){}; + Indi_Demo(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DEMO, _tf){}; /** * Initialize indicator data drawing on custom data. */ bool InitDraw() { if (iparams.is_draw) { - draw = new DrawIndicator(&this); + draw = new DrawIndicator(&this); } return iparams.is_draw; } @@ -91,7 +90,7 @@ class Indi_Demo : public Indicator { * Returns the indicator value. */ static double iDemo(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { return 0.1 + (0.1 * _obj.GetBarIndex()); } @@ -115,17 +114,17 @@ class Indi_Demo : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.AddFlags(INDI_ENTRY_FLAG_IS_VALID); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 1179224fb..f995865b6 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -54,22 +54,19 @@ struct DetrendedPriceParams : IndicatorParams { /** * Implements Detrended Price Oscillator. */ -class Indi_DetrendedPrice : public Indicator { - protected: - DetrendedPriceParams params; - +class Indi_DetrendedPrice : public Indicator { public: /** * Class constructor. */ - Indi_DetrendedPrice(DetrendedPriceParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_DetrendedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DETRENDED_PRICE, _tf) { params.tf = _tf; }; + Indi_DetrendedPrice(DetrendedPriceParams &_params) : Indicator(_params){}; + Indi_DetrendedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DETRENDED_PRICE, _tf){}; /** * Built-in version of AMA. */ static double iDPO(string _symbol, ENUM_TIMEFRAMES _tf, int _period, ENUM_APPLIED_PRICE _ap, int _mode = 0, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_SHORT(_symbol, _tf, _ap, Util::MakeKey("Indi_DPO", _period, (int)_ap)); return iDPOOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_SHORT, _period, _mode, _shift, _cache); @@ -126,13 +123,13 @@ class Indi_DetrendedPrice : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_DetrendedPrice::iDPO(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetAppliedPrice() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); break; default: @@ -149,17 +146,17 @@ class Indi_DetrendedPrice : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -180,12 +177,12 @@ class Indi_DetrendedPrice : public Indicator { /** * Get period. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get applied price. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -194,7 +191,7 @@ class Indi_DetrendedPrice : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -202,6 +199,6 @@ class Indi_DetrendedPrice : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index d6f81854b..318113aa0 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -41,23 +41,15 @@ double iDrawer(string _symbol, int _tf, int _period, int _ap, int _shift) { /** * Implements the Relative Strength Index indicator. */ -class Indi_Drawer : public Indicator { - public: - DrawerParams params; - DictStruct aux_data; +class Indi_Drawer : public Indicator { Redis redis; /** * Class constructor. */ - Indi_Drawer(const DrawerParams &_params) : params(_params), Indicator((IndicatorParams)_params), redis(true) { - params = _params; - Init(); - } - Indi_Drawer(const DrawerParams &_params, ENUM_TIMEFRAMES _tf) - : params(_params), Indicator(INDI_DRAWER, _tf), redis(true) { + Indi_Drawer(const DrawerParams &_params) : Indicator(_params), redis(true) { Init(); } + Indi_Drawer(ENUM_TIMEFRAMES _tf) : Indicator(INDI_DRAWER, _tf), redis(true) { // @fixme - params.tf = _tf; Init(); } @@ -112,7 +104,7 @@ class Indi_Drawer : public Indicator { } virtual void OnTick() { - Indicator::OnTick(); + Indicator::OnTick(); ActionEntry action(INDI_ACTION_SET_VALUE); ArrayResize(action.args, 3); @@ -163,16 +155,18 @@ class Indi_Drawer : public Indicator { * - https://www.mql5.com/en/docs/indicators/irsi */ static double iDrawer(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, - ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, + Indicator *_obj = NULL) { return 1.0; } /** * Calculates non-SMMA version of Drawer on another indicator (uses iDrawerOnArray). */ - static double iDrawerOnArrayOnIndicator(Indicator *_indi, string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, - unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, - int _shift = 0, Indi_Drawer *_obj = NULL) { + static double iDrawerOnArrayOnIndicator(Indicator *_indi, string _symbol = NULL, + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, + ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, + Indi_Drawer *_obj = NULL) { int i; double indi_values[]; ArrayResize(indi_values, _period); @@ -203,7 +197,7 @@ class Indi_Drawer : public Indicator { * Drawer values. To exactly replicate our Drawer numbers, a formula will need at * least 250 data points." */ - static double iDrawerOnIndicator(Indicator *_indi, Indi_Drawer *_obj, string _symbol = NULL, + static double iDrawerOnIndicator(Indicator *_indi, Indi_Drawer *_obj, string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0) { long _bar_time_curr = _obj.GetBarTime(_shift); @@ -298,8 +292,8 @@ class Indi_Drawer : public Indicator { * extern ENUM_APPLIED_PRICE applied_price; // Required only for MQL4. * extern int shift; * - * Also, remember to use params.SetCustomIndicatorName(name) method to choose - * indicator name, e.g.,: params.SetCustomIndicatorName("Examples\\Drawer"); + * Also, remember to use iparams.SetCustomIndicatorName(name) method to choose + * indicator name, e.g.,: iparams.SetCustomIndicatorName("Examples\\Drawer"); * * Note that in MQL5 Applied Price must be passed as the last parameter * (before mode and shift). @@ -307,7 +301,7 @@ class Indi_Drawer : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_Drawer::iDrawer(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), @@ -316,12 +310,12 @@ class Indi_Drawer : public Indicator { case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /* [ */ GetPeriod(), GetAppliedPrice() /* ] */, 0, _shift); + iparams.custom_indi_name, /* [ */ GetPeriod(), GetAppliedPrice() /* ] */, 0, _shift); break; case IDATA_INDICATOR: - _value = Indi_Drawer::iDrawerOnIndicator(params.indi_data_source, GetPointer(this), - Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetPeriod(), GetAppliedPrice(), _shift); + _value = Indi_Drawer::iDrawerOnIndicator(iparams.indi_src, GetPointer(this), Get(CHART_PARAM_SYMBOL), + Get(CHART_PARAM_TF), GetPeriod(), GetAppliedPrice(), + _shift); break; } istate.is_changed = false; @@ -335,10 +329,10 @@ class Indi_Drawer : public Indicator { unsigned int i; long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(iparams.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (_bar_time < 0) { // Return empty value on invalid bar time. - for (i = 0; i < iparams.max_modes; ++i) { + for (i = 0; i < iparams.GetMaxModes(); ++i) { _entry.values[i] = EMPTY_VALUE; } return _entry; @@ -349,11 +343,11 @@ class Indi_Drawer : public Indicator { // Missing entry (which is correct). _entry.timestamp = GetBarTime(_shift); - for (i = 0; i < iparams.max_modes; ++i) { + for (i = 0; i < iparams.GetMaxModes(); ++i) { _entry.values[i] = 0; } - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); _entry.AddFlags(INDI_ENTRY_FLAG_IS_VALID | INDI_ENTRY_FLAG_INSUFFICIENT_DATA); } return _entry; @@ -377,19 +371,19 @@ class Indi_Drawer : public Indicator { /* Getters */ /** - * Get indicator params. + * Get indicator iparams. */ - DrawerParams GetParams() { return params; } + DrawerParams GetParams() { return iparams; } /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get applied price value. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -398,7 +392,7 @@ class Indi_Drawer : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -406,6 +400,6 @@ class Indi_Drawer : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index cfbb402c6..79bc87da9 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -50,7 +50,7 @@ struct DrawerParams : IndicatorParams { void DrawerParams(DrawerParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { this = _params; tf = _tf; - if (idstype == IDATA_INDICATOR && indi_data_source == NULL) { + if (idstype == IDATA_INDICATOR) { PriceIndiParams price_params(_tf); SetDataSource(new Indi_Price(price_params), true); } diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 99c359845..ce333988d 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -73,25 +73,13 @@ struct EnvelopesParams : IndicatorParams { /** * Implements the Envelopes indicator. */ -class Indi_Envelopes : public Indicator { - protected: - // Structs. - EnvelopesParams params; - +class Indi_Envelopes : public Indicator { public: /** * Class constructor. */ - Indi_Envelopes(EnvelopesParams &_p) - : params(_p.ma_period, _p.ma_shift, _p.ma_method, _p.applied_price, _p.deviation), - Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Envelopes(EnvelopesParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.ma_period, _p.ma_shift, _p.ma_method, _p.applied_price, _p.deviation), - Indicator(INDI_ENVELOPES, _tf) { - params = _p; - } + Indi_Envelopes(EnvelopesParams &_p) : Indicator(_p) {} + Indi_Envelopes(EnvelopesParams &_p, ENUM_TIMEFRAMES _tf) : Indicator(INDI_ENVELOPES, _tf) {} /** * Returns the indicator value. @@ -104,7 +92,7 @@ class Indi_Envelopes : public Indicator { int _ma_shift, ENUM_APPLIED_PRICE _ap, double _deviation, int _mode, // (MT4 _mode): 0 - MODE_MAIN, 1 - MODE_UPPER, 2 - MODE_LOWER; (MT5 _mode): 0 - // UPPER_LINE, 1 - LOWER_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { ResetLastError(); #ifdef __MQL4__ return ::iEnvelopes(_symbol, _tf, _ma_period, _ma_method, _ma_shift, _ap, _deviation, _mode, _shift); @@ -147,8 +135,8 @@ class Indi_Envelopes : public Indicator { #endif } - static double iEnvelopesOnIndicator(IndicatorCalculateCache *_cache, Indicator *_indi, string _symbol, - ENUM_TIMEFRAMES _tf, int _ma_period, + static double iEnvelopesOnIndicator(IndicatorCalculateCache *_cache, Indicator *_indi, + string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, ENUM_MA_METHOD _ma_method, // (MT4/MT5): MODE_SMA, MODE_EMA, MODE_SMMA, MODE_LWMA int _indi_mode, // Source indicator's mode index. May be -1 to use first buffer int _ma_shift, double _deviation, @@ -210,7 +198,7 @@ class Indi_Envelopes : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_Envelopes::iEnvelopes(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), @@ -219,13 +207,13 @@ class Indi_Envelopes : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /**/ GetMAPeriod(), GetMAMethod(), GetMAShift(), + iparams.GetCustomIndicatorName(), /**/ GetMAPeriod(), GetMAMethod(), GetMAShift(), GetAppliedPrice(), GetDeviation() /**/, _mode, _shift); break; case IDATA_INDICATOR: _value = Indi_Envelopes::iEnvelopesOnIndicator( - GetCache(), GetDataSource(), Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetMAPeriod(), GetMAMethod(), GetDataSourceMode(), GetMAShift(), GetDeviation(), _mode, _shift); + GetCache(), indi_src, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetMAPeriod(), + GetMAMethod(), GetDataSourceMode(), GetMAShift(), GetDeviation(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -241,7 +229,7 @@ class Indi_Envelopes : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -255,7 +243,7 @@ class Indi_Envelopes : public Indicator { _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -280,27 +268,27 @@ class Indi_Envelopes : public Indicator { /** * Get MA period value. */ - int GetMAPeriod() { return params.ma_period; } + int GetMAPeriod() { return iparams.ma_period; } /** * Set MA method. */ - ENUM_MA_METHOD GetMAMethod() { return params.ma_method; } + ENUM_MA_METHOD GetMAMethod() { return iparams.ma_method; } /** * Get MA shift value. */ - int GetMAShift() { return params.ma_shift; } + int GetMAShift() { return iparams.ma_shift; } /** * Get applied price value. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /** * Get deviation value. */ - double GetDeviation() { return params.deviation; } + double GetDeviation() { return iparams.deviation; } /* Setters */ @@ -309,7 +297,7 @@ class Indi_Envelopes : public Indicator { */ void SetMAPeriod(int _ma_period) { istate.is_changed = true; - params.ma_period = _ma_period; + iparams.ma_period = _ma_period; } /** @@ -317,7 +305,7 @@ class Indi_Envelopes : public Indicator { */ void SetMAMethod(ENUM_MA_METHOD _ma_method) { istate.is_changed = true; - params.ma_method = _ma_method; + iparams.ma_method = _ma_method; } /** @@ -325,7 +313,7 @@ class Indi_Envelopes : public Indicator { */ void SetMAShift(int _ma_shift) { istate.is_changed = true; - params.ma_shift = _ma_shift; + iparams.ma_shift = _ma_shift; } /** @@ -333,7 +321,7 @@ class Indi_Envelopes : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _ap) { istate.is_changed = true; - params.applied_price = _ap; + iparams.applied_price = _ap; } /** @@ -341,6 +329,6 @@ class Indi_Envelopes : public Indicator { */ void SetDeviation(double _deviation) { istate.is_changed = true; - params.deviation = _deviation; + iparams.deviation = _deviation; } }; diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index bc986d20d..11d3a71d6 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -66,22 +66,14 @@ struct ForceParams : IndicatorParams { /** * Implements the Force Index indicator. */ -class Indi_Force : public Indicator { +class Indi_Force : public Indicator { protected: - // Structs. - ForceParams params; - public: /** * Class constructor. */ - Indi_Force(ForceParams &_p) : params(_p.period, _p.ma_method, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Force(ForceParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.ma_method, _p.applied_price), Indicator(INDI_FORCE, _tf) { - params = _p; - } + Indi_Force(ForceParams &_p) : Indicator(_p) {} + Indi_Force(ENUM_TIMEFRAMES _tf) : Indicator(INDI_FORCE, _tf) {} /** * Returns the indicator value. @@ -91,7 +83,7 @@ class Indi_Force : public Indicator { * - https://www.mql5.com/en/docs/indicators/iforce */ static double iForce(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_MA_METHOD _ma_method, - ENUM_APPLIED_PRICE _applied_price, int _shift = 0, Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price, int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iForce(_symbol, _tf, _period, _ma_method, _applied_price, _shift); #else // __MQL5__ @@ -130,7 +122,7 @@ class Indi_Force : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_Force::iForce(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), @@ -138,7 +130,7 @@ class Indi_Force : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod(), GetMAMethod(), GetAppliedPrice(), + iparams.GetCustomIndicatorName(), /*[*/ GetPeriod(), GetMAMethod(), GetAppliedPrice(), VOLUME_TICK /*]*/, 0, _shift); break; default: @@ -155,17 +147,17 @@ class Indi_Force : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -186,17 +178,17 @@ class Indi_Force : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get MA method. */ - ENUM_MA_METHOD GetMAMethod() { return params.ma_method; } + ENUM_MA_METHOD GetMAMethod() { return iparams.ma_method; } /** * Get applied price value. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -205,7 +197,7 @@ class Indi_Force : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -213,7 +205,7 @@ class Indi_Force : public Indicator { */ void SetMAMethod(ENUM_MA_METHOD _ma_method) { istate.is_changed = true; - params.ma_method = _ma_method; + iparams.ma_method = _ma_method; } /** @@ -221,6 +213,6 @@ class Indi_Force : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 5a813e4d5..23e79e28b 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -53,25 +53,19 @@ struct FrIndiAMAParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_FrAMA : public Indicator { - protected: - FrIndiAMAParams params; - +class Indi_FrAMA : public Indicator { public: /** * Class constructor. */ - Indi_FrAMA(FrIndiAMAParams &_params) - : params(_params.period, _params.frama_shift), Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_FrAMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FRAMA, _tf) { params.tf = _tf; }; + Indi_FrAMA(FrIndiAMAParams &_params) : Indicator(_params){}; + Indi_FrAMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FRAMA, _tf){}; /** * Built-in version of FrAMA. */ static double iFrAMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, ENUM_APPLIED_PRICE _ap, - int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iFrAMA(_symbol, _tf, _ma_period, _ma_shift, _ap), _mode, _shift); #else @@ -145,13 +139,13 @@ class Indi_FrAMA : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_FrAMA::iFrAMA(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetFRAMAShift(), GetAppliedPrice() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod(), GetFRAMAShift() /*]*/, 0, _shift); break; default: @@ -168,17 +162,17 @@ class Indi_FrAMA : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -199,17 +193,17 @@ class Indi_FrAMA : public Indicator { /** * Get period. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get FRAMA shift. */ - unsigned int GetFRAMAShift() { return params.frama_shift; } + unsigned int GetFRAMAShift() { return iparams.frama_shift; } /** * Get applied price. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -218,7 +212,7 @@ class Indi_FrAMA : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -226,7 +220,7 @@ class Indi_FrAMA : public Indicator { */ void SetFRAMAShift(unsigned int _frama_shift) { istate.is_changed = true; - params.frama_shift = _frama_shift; + iparams.frama_shift = _frama_shift; } /** @@ -234,6 +228,6 @@ class Indi_FrAMA : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index ff41504d7..a73a5d3f0 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -51,15 +51,12 @@ struct FractalsParams : IndicatorParams { /** * Implements the Fractals indicator. */ -class Indi_Fractals : public Indicator { - protected: - FractalsParams params; - +class Indi_Fractals : public Indicator { public: /** * Class constructor. */ - Indi_Fractals(IndicatorParams &_p) : Indicator((IndicatorParams)_p) {} + Indi_Fractals(FractalsParams &_p) : Indicator(_p) {} Indi_Fractals(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FRACTALS, _tf) {} /** @@ -72,7 +69,7 @@ class Indi_Fractals : public Indicator { static double iFractals(string _symbol, ENUM_TIMEFRAMES _tf, ENUM_LO_UP_LINE _mode, // (MT4 _mode): 1 - MODE_UPPER, 2 - MODE_LOWER int _shift = 0, // (MT5 _mode): 0 - UPPER_LINE, 1 - LOWER_LINE - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iFractals(_symbol, _tf, _mode, _shift); #else // __MQL5__ @@ -111,7 +108,7 @@ class Indi_Fractals : public Indicator { double GetValue(ENUM_LO_UP_LINE _mode, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = _value = Indi_Fractals::iFractals( @@ -119,7 +116,7 @@ class Indi_Fractals : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), _mode, _shift); + iparams.GetCustomIndicatorName(), _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -135,7 +132,7 @@ class Indi_Fractals : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -153,7 +150,7 @@ class Indi_Fractals : public Indicator { #endif _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(_wrong_value)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index 6a02f8473..1ce94e575 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -104,26 +104,13 @@ struct GatorParams : IndicatorParams { /** * Implements the Gator oscillator. */ -class Indi_Gator : public Indicator { - protected: - GatorParams params; - +class Indi_Gator : public Indicator { public: /** * Class constructor. */ - Indi_Gator(GatorParams &_p) - : params(_p.jaw_period, _p.jaw_shift, _p.teeth_period, _p.teeth_shift, _p.lips_period, _p.lips_shift, - _p.ma_method, _p.applied_price), - Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Gator(GatorParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.jaw_period, _p.jaw_shift, _p.teeth_period, _p.teeth_shift, _p.lips_period, _p.lips_shift, - _p.ma_method, _p.applied_price), - Indicator(INDI_GATOR, _tf) { - params = _p; - } + Indi_Gator(GatorParams &_p) : Indicator(_p) {} + Indi_Gator(ENUM_TIMEFRAMES _tf) : Indicator(INDI_GATOR, _tf) {} /** * Returns the indicator value. @@ -146,7 +133,7 @@ class Indi_Gator : public Indicator { static double iGator(string _symbol, ENUM_TIMEFRAMES _tf, int _jaw_period, int _jaw_shift, int _teeth_period, int _teeth_shift, int _lips_period, int _lips_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, ENUM_GATOR_HISTOGRAM _mode, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iGator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift, _ma_method, _applied_price, _mode, _shift); @@ -187,7 +174,7 @@ class Indi_Gator : public Indicator { double GetValue(ENUM_GATOR_HISTOGRAM _mode, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_Gator::iGator(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), @@ -196,7 +183,7 @@ class Indi_Gator : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /**/ + iparams.GetCustomIndicatorName(), /**/ GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), GetAppliedPrice() @@ -217,7 +204,7 @@ class Indi_Gator : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -238,7 +225,7 @@ class Indi_Gator : public Indicator { !_entry.HasValue(EMPTY_VALUE) && (_entry.values[LINE_UPPER_HISTOGRAM].GetDbl() != 0 || _entry.values[LINE_LOWER_HISTOGRAM].GetDbl() != 0)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -259,42 +246,42 @@ class Indi_Gator : public Indicator { /** * Get jaw period value. */ - unsigned int GetJawPeriod() { return params.jaw_period; } + unsigned int GetJawPeriod() { return iparams.jaw_period; } /** * Get jaw shift value. */ - unsigned int GetJawShift() { return params.jaw_shift; } + unsigned int GetJawShift() { return iparams.jaw_shift; } /** * Get teeth period value. */ - unsigned int GetTeethPeriod() { return params.teeth_period; } + unsigned int GetTeethPeriod() { return iparams.teeth_period; } /** * Get teeth shift value. */ - unsigned int GetTeethShift() { return params.teeth_shift; } + unsigned int GetTeethShift() { return iparams.teeth_shift; } /** * Get lips period value. */ - unsigned int GetLipsPeriod() { return params.lips_period; } + unsigned int GetLipsPeriod() { return iparams.lips_period; } /** * Get lips shift value. */ - unsigned int GetLipsShift() { return params.lips_shift; } + unsigned int GetLipsShift() { return iparams.lips_shift; } /** * Get MA method. */ - ENUM_MA_METHOD GetMAMethod() { return params.ma_method; } + ENUM_MA_METHOD GetMAMethod() { return iparams.ma_method; } /** * Get applied price value. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -303,7 +290,7 @@ class Indi_Gator : public Indicator { */ void SetJawPeriod(int _jaw_period) { istate.is_changed = true; - params.jaw_period = _jaw_period; + iparams.jaw_period = _jaw_period; } /** @@ -311,7 +298,7 @@ class Indi_Gator : public Indicator { */ void SetJawShift(int _jaw_shift) { istate.is_changed = true; - params.jaw_shift = _jaw_shift; + iparams.jaw_shift = _jaw_shift; } /** @@ -319,7 +306,7 @@ class Indi_Gator : public Indicator { */ void SetTeethPeriod(int _teeth_period) { istate.is_changed = true; - params.teeth_period = _teeth_period; + iparams.teeth_period = _teeth_period; } /** @@ -327,7 +314,7 @@ class Indi_Gator : public Indicator { */ void SetTeethShift(int _teeth_shift) { istate.is_changed = true; - params.teeth_period = _teeth_shift; + iparams.teeth_period = _teeth_shift; } /** @@ -335,7 +322,7 @@ class Indi_Gator : public Indicator { */ void SetLipsPeriod(int _lips_period) { istate.is_changed = true; - params.lips_period = _lips_period; + iparams.lips_period = _lips_period; } /** @@ -343,7 +330,7 @@ class Indi_Gator : public Indicator { */ void SetLipsShift(int _lips_shift) { istate.is_changed = true; - params.lips_period = _lips_shift; + iparams.lips_period = _lips_shift; } /** @@ -351,7 +338,7 @@ class Indi_Gator : public Indicator { */ void SetMAMethod(ENUM_MA_METHOD _ma_method) { istate.is_changed = true; - params.ma_method = _ma_method; + iparams.ma_method = _ma_method; } /** @@ -359,6 +346,6 @@ class Indi_Gator : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index bbc9896b1..0edc99784 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -73,22 +73,19 @@ struct HeikenAshiParams : IndicatorParams { /** * Implements the Heiken-Ashi indicator. */ -class Indi_HeikenAshi : public Indicator { - protected: - HeikenAshiParams params; - +class Indi_HeikenAshi : public Indicator { public: /** * Class constructor. */ - Indi_HeikenAshi(IndicatorParams &_p) : Indicator((IndicatorParams)_p) {} + Indi_HeikenAshi(HeikenAshiParams &_p) : Indicator(_p) {} Indi_HeikenAshi(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_HEIKENASHI, _tf) {} /** * Returns value for iHeikenAshi indicator. */ static double iCustomLegacyHeikenAshi(string _symbol, ENUM_TIMEFRAMES _tf, string _name, int _mode, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ // Low and High prices could be in reverse order when using MT4's built-in indicator, so we need to retrieve both // and return correct one. @@ -138,7 +135,7 @@ class Indi_HeikenAshi : public Indicator { * "Built-in" version of Heiken Ashi. */ static double iHeikenAshi(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + Indi_HeikenAshi *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_HeikenAshi"); return iHeikenAshiOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _shift, _cache); } @@ -206,16 +203,16 @@ class Indi_HeikenAshi : public Indicator { double GetValue(ENUM_HA_MODE _mode, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_HeikenAshi::iHeikenAshi(GetSymbol(), GetTf(), _mode, _shift, GetPointer(this)); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, _shift); break; case IDATA_ICUSTOM_LEGACY: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_HeikenAshi::iCustomLegacyHeikenAshi(GetSymbol(), GetTf(), params.GetCustomIndicatorName(), _mode, + _value = Indi_HeikenAshi::iCustomLegacyHeikenAshi(GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, _shift, GetPointer(this)); break; default: @@ -232,19 +229,19 @@ class Indi_HeikenAshi : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_HA_MODE)_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0) && _entry.values[HA_LOW].GetDbl() < _entry.values[HA_HIGH].GetDbl()); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index f58d56d5b..9875b7d69 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -85,22 +85,13 @@ struct IchimokuParams : IndicatorParams { /** * Implements the Ichimoku Kinko Hyo indicator. */ -class Indi_Ichimoku : public Indicator { - protected: - IchimokuParams params; - +class Indi_Ichimoku : public Indicator { public: /** * Class constructor. */ - Indi_Ichimoku(IchimokuParams &_p) - : params(_p.tenkan_sen, _p.kijun_sen, _p.senkou_span_b), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Ichimoku(IchimokuParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.tenkan_sen, _p.kijun_sen, _p.senkou_span_b), Indicator(INDI_ICHIMOKU, _tf) { - params = _p; - } + Indi_Ichimoku(IchimokuParams &_p) : Indicator(_p) {} + Indi_Ichimoku(IchimokuParams &_p, ENUM_TIMEFRAMES _tf) : Indicator(INDI_ICHIMOKU, _tf) {} /** * Returns the indicator value. @@ -114,7 +105,7 @@ class Indi_Ichimoku : public Indicator { * - https://www.mql5.com/en/docs/indicators/iichimoku */ static double iIchimoku(string _symbol, ENUM_TIMEFRAMES _tf, int _tenkan_sen, int _kijun_sen, int _senkou_span_b, - int _mode, int _shift = 0, Indicator *_obj = NULL) { + int _mode, int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iIchimoku(_symbol, _tf, _tenkan_sen, _kijun_sen, _senkou_span_b, _mode, _shift); #else // __MQL5__ @@ -153,7 +144,7 @@ class Indi_Ichimoku : public Indicator { double GetValue(ENUM_ICHIMOKU_LINE _mode, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = @@ -162,7 +153,7 @@ class Indi_Ichimoku : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetTenkanSen(), GetKijunSen(), GetSenkouSpanB() /*]*/, + iparams.GetCustomIndicatorName(), /*[*/ GetTenkanSen(), GetKijunSen(), GetSenkouSpanB() /*]*/, _mode, _shift); break; default: @@ -179,7 +170,7 @@ class Indi_Ichimoku : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -197,7 +188,7 @@ class Indi_Ichimoku : public Indicator { _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -218,17 +209,17 @@ class Indi_Ichimoku : public Indicator { /** * Get period of Tenkan-sen line. */ - unsigned int GetTenkanSen() { return params.tenkan_sen; } + unsigned int GetTenkanSen() { return iparams.tenkan_sen; } /** * Get period of Kijun-sen line. */ - unsigned int GetKijunSen() { return params.kijun_sen; } + unsigned int GetKijunSen() { return iparams.kijun_sen; } /** * Get period of Senkou Span B line. */ - unsigned int GetSenkouSpanB() { return params.senkou_span_b; } + unsigned int GetSenkouSpanB() { return iparams.senkou_span_b; } /* Setters */ @@ -237,7 +228,7 @@ class Indi_Ichimoku : public Indicator { */ void SetTenkanSen(unsigned int _tenkan_sen) { istate.is_changed = true; - params.tenkan_sen = _tenkan_sen; + iparams.tenkan_sen = _tenkan_sen; } /** @@ -245,7 +236,7 @@ class Indi_Ichimoku : public Indicator { */ void SetKijunSen(unsigned int _kijun_sen) { istate.is_changed = true; - params.kijun_sen = _kijun_sen; + iparams.kijun_sen = _kijun_sen; } /** @@ -253,6 +244,6 @@ class Indi_Ichimoku : public Indicator { */ void SetSenkouSpanB(unsigned int _senkou_span_b) { istate.is_changed = true; - params.senkou_span_b = _senkou_span_b; + iparams.senkou_span_b = _senkou_span_b; } }; diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index 319cc5649..ba32389b8 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -71,21 +71,13 @@ struct MAParams : IndicatorParams { /** * Implements the Moving Average indicator. */ -class Indi_MA : public Indicator { - protected: - MAParams params; - +class Indi_MA : public Indicator { public: /** * Class constructor. */ - Indi_MA(MAParams &_p) : params(_p.period, _p.shift, _p.ma_method, _p.applied_array), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_MA(MAParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.shift, _p.ma_method, _p.applied_array), Indicator(INDI_MA, _tf) { - params = _p; - } + Indi_MA(MAParams &_p) : Indicator(_p) {} + Indi_MA(ENUM_TIMEFRAMES _tf) : Indicator(INDI_MA, _tf) {} /** * Returns the indicator value. @@ -96,7 +88,7 @@ class Indi_MA : public Indicator { */ static double iMA(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _ma_period, unsigned int _ma_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_array, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { ResetLastError(); #ifdef __MQL4__ return ::iMA(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_array, _shift); @@ -133,8 +125,8 @@ class Indi_MA : public Indicator { /** * Calculates MA on another indicator. */ - static double iMAOnIndicator(IndicatorCalculateCache *cache, Indicator *indi, int indi_mode, string symbol, - ENUM_TIMEFRAMES tf, unsigned int ma_period, unsigned int ma_shift, + static double iMAOnIndicator(IndicatorCalculateCache *cache, Indicator *indi, int indi_mode, + string symbol, ENUM_TIMEFRAMES tf, unsigned int ma_period, unsigned int ma_shift, ENUM_MA_METHOD ma_method, // (MT4/MT5): MODE_SMA, MODE_EMA, MODE_SMMA, MODE_LWMA int shift = 0) { return iMAOnArray(indi.GetValueStorage(indi_mode), 0, ma_period, ma_shift, ma_method, shift, cache); @@ -637,7 +629,7 @@ class Indi_MA : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_MA::iMA(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), @@ -646,14 +638,14 @@ class Indi_MA : public Indicator { case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /* [ */ GetPeriod(), GetMAShift(), GetMAMethod(), + iparams.custom_indi_name, /* [ */ GetPeriod(), GetMAShift(), GetMAMethod(), GetAppliedPrice() /* ] */, 0, _shift); break; case IDATA_INDICATOR: // Calculating MA value from specified indicator. - _value = Indi_MA::iMAOnIndicator(GetCache(), GetDataSource(), GetDataSourceMode(), - Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetPeriod(), GetMAShift(), GetMAMethod(), _shift); + _value = Indi_MA::iMAOnIndicator(GetCache(), indi_src, GetDataSourceMode(), Get(CHART_PARAM_SYMBOL), + Get(CHART_PARAM_TF), GetPeriod(), GetMAShift(), GetMAMethod(), + _shift); break; } istate.is_ready = _LastError == ERR_NO_ERROR; @@ -668,16 +660,16 @@ class Indi_MA : public Indicator { long _bar_time = GetBarTime(_shift); IndicatorDataEntry _entry = idata.GetByKey(_bar_time); if (!_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) { - _entry.Resize(params.max_modes); + _entry.Resize(iparams.GetMaxModes()); _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && !_entry.HasValue(DBL_MAX)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } else { _entry.AddFlags(INDI_ENTRY_FLAG_INSUFFICIENT_DATA); @@ -717,26 +709,26 @@ class Indi_MA : public Indicator { * * Averaging period for the calculation of the moving average. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get MA shift value. * * Indicators line offset relate to the chart by timeframe. */ - unsigned int GetMAShift() { return params.ma_shift; } + unsigned int GetMAShift() { return iparams.ma_shift; } /** * Set MA method (smoothing type). */ - ENUM_MA_METHOD GetMAMethod() { return params.ma_method; } + ENUM_MA_METHOD GetMAMethod() { return iparams.ma_method; } /** * Get applied price value. * * The desired price base for calculations. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_array; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_array; } /* Setters */ @@ -747,7 +739,7 @@ class Indi_MA : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -755,7 +747,7 @@ class Indi_MA : public Indicator { */ void SetMAShift(int _ma_shift) { istate.is_changed = true; - params.ma_shift = _ma_shift; + iparams.ma_shift = _ma_shift; } /** @@ -765,7 +757,7 @@ class Indi_MA : public Indicator { */ void SetMAMethod(ENUM_MA_METHOD _ma_method) { istate.is_changed = true; - params.ma_method = _ma_method; + iparams.ma_method = _ma_method; } /** @@ -778,7 +770,7 @@ class Indi_MA : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_array) { istate.is_changed = true; - params.applied_array = _applied_array; + iparams.applied_array = _applied_array; } }; #endif // INDI_MA_MQH diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index e4caca10d..b7645624b 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -56,23 +56,13 @@ struct MACDParams : IndicatorParams { /** * Implements the Moving Averages Convergence/Divergence indicator. */ -class Indi_MACD : public Indicator { - protected: - MACDParams params; - +class Indi_MACD : public Indicator { public: /** * Class constructor. */ - Indi_MACD(MACDParams &_p) - : params(_p.ema_fast_period, _p.ema_slow_period, _p.signal_period, _p.applied_price), - Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_MACD(MACDParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.ema_fast_period, _p.ema_slow_period, _p.signal_period, _p.applied_price), Indicator(INDI_MACD, _tf) { - params = _p; - } + Indi_MACD(MACDParams &_p) : Indicator(_p) {} + Indi_MACD(ENUM_TIMEFRAMES _tf) : Indicator(INDI_MACD, _tf) {} /** * Returns the indicator value. @@ -85,7 +75,7 @@ class Indi_MACD : public Indicator { string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _ema_fast_period, unsigned int _ema_slow_period, unsigned int _signal_period, ENUM_APPLIED_PRICE _applied_price, ENUM_SIGNAL_LINE _mode = LINE_MAIN, // (MT4/MT5 _mode): 0 - MODE_MAIN/MAIN_LINE, 1 - MODE_SIGNAL/SIGNAL_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iMACD(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price, _mode, _shift); #else // __MQL5__ @@ -125,7 +115,7 @@ class Indi_MACD : public Indicator { double GetValue(ENUM_SIGNAL_LINE _mode = LINE_MAIN, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = @@ -134,7 +124,7 @@ class Indi_MACD : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetEmaFastPeriod(), GetEmaSlowPeriod(), + iparams.GetCustomIndicatorName(), /*[*/ GetEmaFastPeriod(), GetEmaSlowPeriod(), GetSignalPeriod(), GetAppliedPrice() /*]*/, _mode, _shift); break; default: @@ -151,18 +141,18 @@ class Indi_MACD : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_SIGNAL_LINE)_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -185,28 +175,28 @@ class Indi_MACD : public Indicator { * * Averaging period for the calculation of the moving average. */ - unsigned int GetEmaFastPeriod() { return params.ema_fast_period; } + unsigned int GetEmaFastPeriod() { return iparams.ema_fast_period; } /** * Get slow EMA period value. * * Averaging period for the calculation of the moving average. */ - unsigned int GetEmaSlowPeriod() { return params.ema_slow_period; } + unsigned int GetEmaSlowPeriod() { return iparams.ema_slow_period; } /** * Get signal period value. * * Averaging period for the calculation of the moving average. */ - unsigned int GetSignalPeriod() { return params.signal_period; } + unsigned int GetSignalPeriod() { return iparams.signal_period; } /** * Get applied price value. * * The desired price base for calculations. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -217,7 +207,7 @@ class Indi_MACD : public Indicator { */ void SetEmaFastPeriod(unsigned int _ema_fast_period) { istate.is_changed = true; - params.ema_fast_period = _ema_fast_period; + iparams.ema_fast_period = _ema_fast_period; } /** @@ -227,7 +217,7 @@ class Indi_MACD : public Indicator { */ void SetEmaSlowPeriod(unsigned int _ema_slow_period) { istate.is_changed = true; - params.ema_slow_period = _ema_slow_period; + iparams.ema_slow_period = _ema_slow_period; } /** @@ -237,7 +227,7 @@ class Indi_MACD : public Indicator { */ void SetSignalPeriod(unsigned int _signal_period) { istate.is_changed = true; - params.signal_period = _signal_period; + iparams.signal_period = _signal_period; } /** @@ -250,6 +240,6 @@ class Indi_MACD : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index 21db3bc2d..678693d4a 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -53,18 +53,13 @@ struct MFIParams : IndicatorParams { /** * Implements the Money Flow Index indicator. */ -class Indi_MFI : public Indicator { - protected: - MFIParams params; - +class Indi_MFI : public Indicator { public: /** * Class constructor. */ - Indi_MFI(MFIParams &_p) : params(_p.ma_period, _p.applied_volume), Indicator((IndicatorParams)_p) { params = _p; } - Indi_MFI(MFIParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.ma_period, _p.applied_volume), Indicator(INDI_MFI, _tf) { - params = _p; - } + Indi_MFI(MFIParams &_p) : Indicator(_p) {} + Indi_MFI(ENUM_TIMEFRAMES _tf) : Indicator(INDI_MFI, _tf) {} /** * Calculates the Money Flow Index indicator and returns its value. @@ -74,7 +69,7 @@ class Indi_MFI : public Indicator { * - https://www.mql5.com/en/docs/indicators/imfi */ static double iMFI(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iMFI(_symbol, _tf, _period, _shift); #else // __MQL5__ @@ -83,7 +78,7 @@ class Indi_MFI : public Indicator { } static double iMFI(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_VOLUME _applied_volume, // Not used in MT4. - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indi_MFI *_obj = NULL) { #ifdef __MQL4__ return ::iMFI(_symbol, _tf, _period, _shift); #else // __MQL5__ @@ -122,7 +117,7 @@ class Indi_MFI : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; #ifdef __MQL4__ @@ -135,7 +130,7 @@ class Indi_MFI : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod(), VOLUME_TICK /*]*/, 0, _shift); + iparams.GetCustomIndicatorName(), /*[*/ GetPeriod(), VOLUME_TICK /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -151,17 +146,17 @@ class Indi_MFI : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -184,14 +179,14 @@ class Indi_MFI : public Indicator { * * Period (amount of bars) for calculation of the indicator. */ - unsigned int GetPeriod() { return params.ma_period; } + unsigned int GetPeriod() { return iparams.ma_period; } /** * Get applied volume type. * * Note: Ignored in MT4. */ - ENUM_APPLIED_VOLUME GetAppliedVolume() { return params.applied_volume; } + ENUM_APPLIED_VOLUME GetAppliedVolume() { return iparams.applied_volume; } /* Setters */ @@ -202,7 +197,7 @@ class Indi_MFI : public Indicator { */ void SetPeriod(unsigned int _ma_period) { istate.is_changed = true; - params.ma_period = _ma_period; + iparams.ma_period = _ma_period; } /** @@ -215,6 +210,6 @@ class Indi_MFI : public Indicator { */ void SetAppliedVolume(ENUM_APPLIED_VOLUME _applied_volume) { istate.is_changed = true; - params.applied_volume = _applied_volume; + iparams.applied_volume = _applied_volume; } }; diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index 41dc0804a..77603c9ff 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -54,25 +54,19 @@ struct MassIndexParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_MassIndex : public Indicator { - protected: - MassIndexParams params; - +class Indi_MassIndex : public Indicator { public: /** * Class constructor. */ - Indi_MassIndex(MassIndexParams &_params) - : params(_params.period, _params.second_period, _params.sum_period), Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_MassIndex(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_MASS_INDEX, _tf) { params.tf = _tf; }; + Indi_MassIndex(MassIndexParams &_params) : Indicator(_params){}; + Indi_MassIndex(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_MASS_INDEX, _tf){}; /** * Built-in version of Mass Index. */ static double iMI(string _symbol, ENUM_TIMEFRAMES _tf, int _period, int _second_period, int _sum_period, - int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG( _symbol, _tf, Util::MakeKey("Indi_MassIndex", _period, _second_period, _sum_period)); return iMIOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _period, _second_period, _sum_period, _mode, _shift, @@ -165,13 +159,13 @@ class Indi_MassIndex : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_MassIndex::iMI(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetSecondPeriod(), GetSumPeriod() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod(), GetSecondPeriod(), GetSumPeriod() /*]*/, _mode, _shift); break; default: @@ -188,17 +182,17 @@ class Indi_MassIndex : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -219,17 +213,17 @@ class Indi_MassIndex : public Indicator { /** * Get period. */ - int GetPeriod() { return params.period; } + int GetPeriod() { return iparams.period; } /** * Get second period. */ - int GetSecondPeriod() { return params.second_period; } + int GetSecondPeriod() { return iparams.second_period; } /** * Get sum period. */ - int GetSumPeriod() { return params.sum_period; } + int GetSumPeriod() { return iparams.sum_period; } /* Setters */ @@ -238,7 +232,7 @@ class Indi_MassIndex : public Indicator { */ void SetPeriod(int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -246,7 +240,7 @@ class Indi_MassIndex : public Indicator { */ void SetSecondPeriod(int _second_period) { istate.is_changed = true; - params.second_period = _second_period; + iparams.second_period = _second_period; } /** @@ -254,6 +248,6 @@ class Indi_MassIndex : public Indicator { */ void SetSumPeriod(int _sum_period) { istate.is_changed = true; - params.sum_period = _sum_period; + iparams.sum_period = _sum_period; } }; diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index c93f435d5..36ae96e74 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -63,21 +63,13 @@ struct MomentumParams : IndicatorParams { /** * Implements the Momentum indicator. */ -class Indi_Momentum : public Indicator { - protected: - MomentumParams params; - +class Indi_Momentum : public Indicator { public: /** * Class constructor. */ - Indi_Momentum(MomentumParams &_p) : params(_p.period, _p.applied_price, _p.shift), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Momentum(MomentumParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.period, _p.applied_price, _p.shift), Indicator(INDI_MOMENTUM, _tf) { - params = _p; - } + Indi_Momentum(MomentumParams &_p) : Indicator(_p) {} + Indi_Momentum(ENUM_TIMEFRAMES _tf) : Indicator(INDI_MOMENTUM, _tf) {} /** * Returns the indicator value. @@ -87,7 +79,7 @@ class Indi_Momentum : public Indicator { * - https://www.mql5.com/en/docs/indicators/imomentum */ static double iMomentum(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _ap, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iMomentum(_symbol, _tf, _period, _ap, _shift); #else // __MQL5__ @@ -120,8 +112,8 @@ class Indi_Momentum : public Indicator { #endif } - static double iMomentumOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, - int _mode, int _shift = 0) { + static double iMomentumOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, + unsigned int _period, int _mode, int _shift = 0) { double _indi_value_buffer[]; IndicatorDataEntry _entry(_indi.GetParams().GetMaxModes()); @@ -154,26 +146,26 @@ class Indi_Momentum : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; // @fixit Somehow shift isn't used neither in MT4 nor MT5. _value = Indi_Momentum::iMomentum(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - GetPeriod(), GetAppliedPrice(), params.shift + _shift, GetPointer(this)); + GetPeriod(), GetAppliedPrice(), iparams.shift + _shift, GetPointer(this)); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); + iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); break; case IDATA_INDICATOR: ValidateSelectedDataSource(); // @fixit Somehow shift isn't used neither in MT4 nor MT5. - _value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), Get(CHART_PARAM_SYMBOL), + _value = Indi_Momentum::iMomentumOnIndicator(indi_src, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetDataSourceMode(), params.shift + _shift); + GetDataSourceMode(), iparams.GetShift() + _shift); if (iparams.is_draw) { - draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(params.shift + _shift), _value, 1); + draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + _shift), _value, 1); } break; } @@ -188,17 +180,17 @@ class Indi_Momentum : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -221,14 +213,14 @@ class Indi_Momentum : public Indicator { * * Averaging period (bars count) for the calculation of the price change. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get applied price value. * * The desired price base for calculations. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -239,7 +231,7 @@ class Indi_Momentum : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -252,6 +244,6 @@ class Indi_Momentum : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _ap) { istate.is_changed = true; - params.applied_price = _ap; + iparams.applied_price = _ap; } }; diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 2ba02b584..a55f8215c 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -66,32 +66,13 @@ struct OBVParams : IndicatorParams { /** * Implements the On Balance Volume indicator. */ -class Indi_OBV : public Indicator { - protected: - OBVParams params; - +class Indi_OBV : public Indicator { public: /** * Class constructor. */ - Indi_OBV(OBVParams &_p) -#ifdef __MQL4__ - : params(_p.applied_price), -#else - : params(_p.applied_volume), -#endif - Indicator((IndicatorParams)_p) { - } - Indi_OBV(OBVParams &_p, ENUM_TIMEFRAMES _tf) -#ifdef __MQL4__ - : params(_p.applied_price), -#else - : params(_p.applied_volume), -#endif - Indicator(INDI_OBV, _tf) { - params = _p; - } - Indi_OBV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_OBV, _tf) {} + Indi_OBV(OBVParams &_p) : Indicator(_p) {} + Indi_OBV(ENUM_TIMEFRAMES _tf) : Indicator(INDI_OBV, _tf) {} /** * Returns the indicator value. @@ -106,7 +87,7 @@ class Indi_OBV : public Indicator { #else ENUM_APPLIED_VOLUME _applied = VOLUME_TICK, // MT5 only. #endif - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iOBV(_symbol, _tf, _applied, _shift); #else // __MQL5__ @@ -145,7 +126,7 @@ class Indi_OBV : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; #ifdef __MQL4__ @@ -158,7 +139,7 @@ class Indi_OBV : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ VOLUME_TICK /*]*/, 0, _shift); + iparams.GetCustomIndicatorName(), /*[*/ VOLUME_TICK /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -174,17 +155,17 @@ class Indi_OBV : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -207,12 +188,12 @@ class Indi_OBV : public Indicator { * * The desired price base for calculations. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /** * Get applied volume type (MT5 only). */ - ENUM_APPLIED_VOLUME GetAppliedVolume() { return params.applied_volume; } + ENUM_APPLIED_VOLUME GetAppliedVolume() { return iparams.applied_volume; } /* Setters */ @@ -226,7 +207,7 @@ class Indi_OBV : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } /** @@ -237,6 +218,6 @@ class Indi_OBV : public Indicator { */ void SetAppliedVolume(ENUM_APPLIED_VOLUME _applied_volume) { istate.is_changed = true; - params.applied_volume = _applied_volume; + iparams.applied_volume = _applied_volume; } }; diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 8acf31092..3e40b4822 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -56,23 +56,13 @@ struct OsMAParams : IndicatorParams { /** * Implements the Moving Average of Oscillator indicator. */ -class Indi_OsMA : public Indicator { - protected: - OsMAParams params; - +class Indi_OsMA : public Indicator { public: /** * Class constructor. */ - Indi_OsMA(OsMAParams &_p) - : params(_p.ema_fast_period, _p.ema_slow_period, _p.signal_period, _p.applied_price), - Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_OsMA(OsMAParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.ema_fast_period, _p.ema_slow_period, _p.signal_period, _p.applied_price), Indicator(INDI_OSMA, _tf) { - params = _p; - } + Indi_OsMA(OsMAParams &_p) : Indicator(_p) {} + Indi_OsMA(ENUM_TIMEFRAMES _tf) : Indicator(INDI_OSMA, _tf) {} /** * Returns the indicator value. @@ -82,7 +72,8 @@ class Indi_OsMA : public Indicator { * - https://www.mql5.com/en/docs/indicators/iosma */ static double iOsMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ema_fast_period, int _ema_slow_period, - int _signal_period, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, Indicator *_obj = NULL) { + int _signal_period, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iOsMA(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price, _shift); #else // __MQL5__ @@ -122,7 +113,7 @@ class Indi_OsMA : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = @@ -131,7 +122,7 @@ class Indi_OsMA : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetEmaFastPeriod(), GetEmaSlowPeriod(), + iparams.GetCustomIndicatorName(), /*[*/ GetEmaFastPeriod(), GetEmaSlowPeriod(), GetSignalPeriod(), GetAppliedPrice() /*]*/, 0, _shift); break; default: @@ -148,17 +139,17 @@ class Indi_OsMA : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -181,28 +172,28 @@ class Indi_OsMA : public Indicator { * * Averaging period for the calculation of the moving average. */ - int GetEmaFastPeriod() { return params.ema_fast_period; } + int GetEmaFastPeriod() { return iparams.ema_fast_period; } /** * Get slow EMA period value. * * Averaging period for the calculation of the moving average. */ - int GetEmaSlowPeriod() { return params.ema_slow_period; } + int GetEmaSlowPeriod() { return iparams.ema_slow_period; } /** * Get signal period value. * * Averaging period for the calculation of the moving average. */ - int GetSignalPeriod() { return params.signal_period; } + int GetSignalPeriod() { return iparams.signal_period; } /** * Get applied price value. * * The desired price base for calculations. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -213,7 +204,7 @@ class Indi_OsMA : public Indicator { */ void SetEmaFastPeriod(int _ema_fast_period) { istate.is_changed = true; - params.ema_fast_period = _ema_fast_period; + iparams.ema_fast_period = _ema_fast_period; } /** @@ -223,7 +214,7 @@ class Indi_OsMA : public Indicator { */ void SetEmaSlowPeriod(int _ema_slow_period) { istate.is_changed = true; - params.ema_slow_period = _ema_slow_period; + iparams.ema_slow_period = _ema_slow_period; } /** @@ -233,7 +224,7 @@ class Indi_OsMA : public Indicator { */ void SetSignalPeriod(int _signal_period) { istate.is_changed = true; - params.signal_period = _signal_period; + iparams.signal_period = _signal_period; } /** @@ -246,6 +237,6 @@ class Indi_OsMA : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index 6ddd9d8f7..e93ab80f4 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -50,16 +50,13 @@ struct IndiPatternParams : IndicatorParams { /** * Implements Pattern Detector. */ -class Indi_Pattern : public Indicator { - protected: - IndiPatternParams params; - +class Indi_Pattern : public Indicator { public: /** * Class constructor. */ - Indi_Pattern(IndiPatternParams &_params) : params(_params), Indicator((IndicatorParams)_params){}; - Indi_Pattern(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PATTERN, _tf) { params.tf = _tf; }; + Indi_Pattern(IndiPatternParams &_params) : iparams(_params), Indicator(_params){}; + Indi_Pattern(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PATTERN, _tf) { iparams.tf = _tf; }; /** * Returns the indicator's struct value. @@ -67,7 +64,7 @@ class Indi_Pattern : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.GetMaxModes()); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -78,10 +75,10 @@ class Indi_Pattern : public Indicator { int i; int _value = WRONG_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: // In this mode, price is fetched from chart. - for (i = 0; i < params.GetMaxModes(); ++i) { + for (i = 0; i < iparams.GetMaxModes(); ++i) { _ohlcs[i] = Chart::GetOHLC(_shift + i); if (!_ohlcs[i].IsValid()) { // Return empty entry on invalid candles. @@ -93,7 +90,7 @@ class Indi_Pattern : public Indicator { // In this mode, price is fetched from given indicator. Such indicator // must have at least 4 buffers and define OHLC in the first 4 buffers. // Indi_Price is an example of such indicator. - if (GetDataSource() == NULL) { + if (indi_src == NULL) { GetLogger().Error( "In order use custom indicator as a source, you need to select one using SetIndicatorData() method, " "which is a part of PatternParams structure.", @@ -106,11 +103,11 @@ class Indi_Pattern : public Indicator { return _value; } - for (i = 0; i < params.GetMaxModes(); ++i) { - _ohlcs[i].open = GetDataSource().GetValue(_shift + i, PRICE_OPEN); - _ohlcs[i].high = GetDataSource().GetValue(_shift + i, PRICE_HIGH); - _ohlcs[i].low = GetDataSource().GetValue(_shift + i, PRICE_LOW); - _ohlcs[i].close = GetDataSource().GetValue(_shift + i, PRICE_CLOSE); + for (i = 0; i < iparams.GetMaxModes(); ++i) { + _ohlcs[i].open = indi_src.GetValue(_shift + i, PRICE_OPEN); + _ohlcs[i].high = indi_src.GetValue(_shift + i, PRICE_HIGH); + _ohlcs[i].low = indi_src.GetValue(_shift + i, PRICE_LOW); + _ohlcs[i].close = indi_src.GetValue(_shift + i, PRICE_CLOSE); if (!_ohlcs[i].IsValid()) { // Return empty entry on invalid candles. return _entry; @@ -123,7 +120,7 @@ class Indi_Pattern : public Indicator { PatternEntry pattern(_ohlcs); - for (int _mode = 0; _mode < params.GetMaxModes(); _mode++) { + for (int _mode = 0; _mode < iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = pattern[_mode + 1]; } @@ -132,7 +129,7 @@ class Indi_Pattern : public Indicator { if (_entry.IsValid()) { istate.is_ready = true; - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index a0830313b..e5e1a7c53 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -49,16 +49,13 @@ struct IndiPivotParams : IndicatorParams { /** * Implements Pivot Detector. */ -class Indi_Pivot : public Indicator { - protected: - IndiPivotParams params; - +class Indi_Pivot : public Indicator { public: /** * Class constructor. */ - Indi_Pivot(IndiPivotParams &_params) : params(_params), Indicator((IndicatorParams)_params){}; - Indi_Pivot(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PIVOT, _tf) { params.tf = _tf; }; + Indi_Pivot(IndiPivotParams &_params) : iparams(_params), Indicator(_params){}; + Indi_Pivot(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PIVOT, _tf) { iparams.tf = _tf; }; /** * Returns the indicator's struct value. @@ -66,7 +63,7 @@ class Indi_Pivot : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -76,7 +73,7 @@ class Indi_Pivot : public Indicator { BarOHLC _ohlc; int _value = WRONG_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: // In this mode, price is fetched from chart. _ohlc = Chart::GetOHLC(_shift); @@ -98,10 +95,10 @@ class Indi_Pivot : public Indicator { return _value; } - _ohlc.open = GetDataSource().GetValue(_shift, PRICE_OPEN); - _ohlc.high = GetDataSource().GetValue(_shift, PRICE_HIGH); - _ohlc.low = GetDataSource().GetValue(_shift, PRICE_LOW); - _ohlc.close = GetDataSource().GetValue(_shift, PRICE_CLOSE); + _ohlc.open = indi_src.GetValue(_shift, PRICE_OPEN); + _ohlc.high = indi_src.GetValue(_shift, PRICE_HIGH); + _ohlc.low = indi_src.GetValue(_shift, PRICE_LOW); + _ohlc.close = indi_src.GetValue(_shift, PRICE_CLOSE); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -116,7 +113,7 @@ class Indi_Pivot : public Indicator { istate.is_ready = true; if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -137,7 +134,7 @@ class Indi_Pivot : public Indicator { /** * Get pivot point calculation method. */ - ENUM_PP_TYPE GetMethod() { return params.method; } + ENUM_PP_TYPE GetMethod() { return iparams.method; } /* Setters */ @@ -146,7 +143,7 @@ class Indi_Pivot : public Indicator { */ void SetMethod(ENUM_PP_TYPE _method) { istate.is_changed = true; - params.method = _method; + iparams.method = _method; } /** diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index 659669c41..4de2ebaef 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -54,24 +54,20 @@ struct PriceIndiParams : IndicatorParams { /** * Price Indicator. */ -class Indi_Price : public Indicator { - protected: - PriceIndiParams params; - +class Indi_Price : public Indicator { public: /** * Class constructor. */ - Indi_Price(PriceIndiParams &_p) : Indicator((IndicatorParams)_p) { params = _p; }; - Indi_Price(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN) - : params(_shift, _tf, _ap), Indicator(INDI_PRICE, _tf){}; + Indi_Price(PriceIndiParams &_p) : Indicator(_p){}; + Indi_Price(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE, _tf){}; /** * Returns the indicator value. */ static double iPrice(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, Indi_Price *_obj = NULL) { - ENUM_APPLIED_PRICE _ap = _obj == NULL ? PRICE_MEDIAN : _obj.params.applied_price; + ENUM_APPLIED_PRICE _ap = _obj == NULL ? PRICE_MEDIAN : _obj.iparams.applied_price; return ChartStatic::iPrice(_ap, _symbol, _tf, _shift); } @@ -97,7 +93,7 @@ class Indi_Price : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -107,7 +103,7 @@ class Indi_Price : public Indicator { _entry.values[INDI_PRICE_MODE_CLOSE] = GetValue(PRICE_CLOSE, _shift); _entry.values[INDI_PRICE_MODE_LOW] = GetValue(PRICE_LOW, _shift); _entry.AddFlags(INDI_ENTRY_FLAG_IS_VALID); - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } return _entry; diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index b0c6d950e..dc36568d0 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -48,18 +48,13 @@ struct PriceChannelParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_PriceChannel : public Indicator { - protected: - PriceChannelParams params; - +class Indi_PriceChannel : public Indicator { public: /** * Class constructor. */ - Indi_PriceChannel(PriceChannelParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_PriceChannel(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_CHANNEL, _tf) { params.tf = _tf; }; + Indi_PriceChannel(PriceChannelParams &_params) : Indicator(_params){}; + Indi_PriceChannel(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_CHANNEL, _tf){}; /** * Returns the indicator's value. @@ -67,10 +62,10 @@ class Indi_PriceChannel : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); + iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -86,17 +81,17 @@ class Indi_PriceChannel : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -117,7 +112,7 @@ class Indi_PriceChannel : public Indicator { /** * Get period. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /* Setters */ @@ -126,6 +121,6 @@ class Indi_PriceChannel : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } }; diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index 1173d01eb..f2de6f8a9 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -57,45 +57,42 @@ struct PriceFeederIndiParams : IndicatorParams { /** * Price Indicator. */ -class Indi_PriceFeeder : public Indicator { - protected: - PriceFeederIndiParams params; - +class Indi_PriceFeeder : public Indicator { public: /** * Class constructor. */ - Indi_PriceFeeder(PriceFeederIndiParams& _p) : Indicator((IndicatorParams)_p) { params = _p; }; + Indi_PriceFeeder(PriceFeederIndiParams& _p) : Indicator(_p){}; Indi_PriceFeeder(const double& _price_data[], int _total = 0) - : params(_price_data, _total), Indicator(INDI_PRICE_FEEDER){}; + : iparams(_price_data, _total), Indicator(INDI_PRICE_FEEDER){}; - void SetPrices(const double& _price_data[], int _total = 0) { params = PriceFeederIndiParams(_price_data, _total); } + void SetPrices(const double& _price_data[], int _total = 0) { iparams = PriceFeederIndiParams(_price_data, _total); } /** * Checks whether indicator has a valid value for a given shift. */ - virtual bool HasValidEntry(int _shift = 0) { return _shift >= 0 && _shift < ArraySize(params.price_data); } + virtual bool HasValidEntry(int _shift = 0) { return _shift >= 0 && _shift < ArraySize(iparams.price_data); } /** * Returns the indicator's value. */ double GetValue(ENUM_APPLIED_PRICE _ap, int _shift = 0) { - int data_size = ArraySize(params.price_data); + int data_size = ArraySize(iparams.price_data); if (_shift >= data_size || _shift < 0) return DBL_MIN; - double _value = params.price_data[data_size - _shift - 1]; + double _value = iparams.price_data[data_size - _shift - 1]; istate.is_ready = true; istate.is_changed = false; return _value; } void OnTick() { - Indicator::OnTick(); + Indicator::OnTick(); if (iparams.is_draw) { IndicatorDataEntry _entry = GetEntry(0); - for (int i = 0; i < (int)iparams.max_modes; ++i) { + for (int i = 0; i < (int)iparams.GetMaxModes(); ++i) { draw.DrawLineTo(GetName() + "_" + IntegerToString(i), GetBarTime(0), _entry.values[i].GetDbl()); } } @@ -107,14 +104,14 @@ class Indi_PriceFeeder : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); _entry.values[0].Set(GetValue(PRICE_OPEN, _shift)); _entry.AddFlags(INDI_ENTRY_FLAG_IS_VALID); - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } return _entry; diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index ebb585331..24099ed7e 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -49,27 +49,19 @@ struct PriceVolumeTrendParams : IndicatorParams { /** * Implements the Price Volume Trend indicator. */ -class Indi_PriceVolumeTrend : public Indicator { - protected: - PriceVolumeTrendParams params; - +class Indi_PriceVolumeTrend : public Indicator { public: /** * Class constructor. */ - Indi_PriceVolumeTrend(PriceVolumeTrendParams &_params) - : params(_params.applied_volume), Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_PriceVolumeTrend(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_VOLUME_TREND, _tf) { - params.tf = _tf; - }; + Indi_PriceVolumeTrend(PriceVolumeTrendParams &_params) : Indicator(_params){}; + Indi_PriceVolumeTrend(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_VOLUME_TREND, _tf){}; /** * Built-in version of Price Volume Trend. */ static double iPVT(string _symbol, ENUM_TIMEFRAMES _tf, ENUM_APPLIED_VOLUME _av, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, Util::MakeKey("Indi_PriceVolumeTrend", (int)_av)); return iPVTOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _av, _mode, _shift, _cache); } @@ -134,13 +126,13 @@ class Indi_PriceVolumeTrend : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_PriceVolumeTrend::iPVT(GetSymbol(), GetTf(), /*[*/ GetAppliedVolume() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetAppliedVolume() /*]*/, 0, _shift); break; default: @@ -157,17 +149,17 @@ class Indi_PriceVolumeTrend : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -188,7 +180,7 @@ class Indi_PriceVolumeTrend : public Indicator { /** * Get applied volume. */ - ENUM_APPLIED_VOLUME GetAppliedVolume() { return params.applied_volume; } + ENUM_APPLIED_VOLUME GetAppliedVolume() { return iparams.applied_volume; } /* Setters */ @@ -197,6 +189,6 @@ class Indi_PriceVolumeTrend : public Indicator { */ void SetPeriod(ENUM_APPLIED_VOLUME _applied_volume) { istate.is_changed = true; - params.applied_volume = _applied_volume; + iparams.applied_volume = _applied_volume; } }; diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index 48eece0ae..79e98f6d9 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -50,24 +50,21 @@ struct RSParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_RS : public Indicator { - protected: - RSParams params; - Ref iprice; +class Indi_RS : public Indicator { DictStruct> imath; public: /** * Class constructor. */ - Indi_RS(RSParams &_params) : params(_params), Indicator((IndicatorParams)_params) { Init(); }; + Indi_RS(RSParams &_params) : iparams(_params), Indicator(_params) { Init(); }; Indi_RS(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RS, _tf) { - params.tf = _tf; + iparams.tf = _tf; Init(); }; void Init() { - if (params.GetDataSourceType() == IDATA_MATH) { + if (iparams.GetDataSourceType() == IDATA_MATH) { PriceIndiParams _iprice_params(); iprice = new Indi_Price(_iprice_params); @@ -90,7 +87,7 @@ class Indi_RS : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_MATH: _value = imath[_mode].Ptr().GetValue(); break; @@ -108,17 +105,17 @@ class Indi_RS : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, true); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -139,7 +136,7 @@ class Indi_RS : public Indicator { /** * Get applied volume. */ - ENUM_APPLIED_VOLUME GetAppliedVolume() { return params.applied_volume; } + ENUM_APPLIED_VOLUME GetAppliedVolume() { return iparams.applied_volume; } /* Setters */ @@ -148,6 +145,6 @@ class Indi_RS : public Indicator { */ void SetAppliedVolume(ENUM_APPLIED_VOLUME _applied_volume) { istate.is_changed = true; - params.applied_volume = _applied_volume; + iparams.applied_volume = _applied_volume; } }; diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index ce168bf34..f5b331e50 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -43,9 +43,11 @@ double iRSIOnArray(double &_arr[], int _total, int _period, int _shift) { // Structs. struct RSIParams : IndicatorParams { + protected: unsigned int period; ENUM_APPLIED_PRICE applied_price; + public: // Struct constructors. void RSIParams(const RSIParams &r) { period = r.period; @@ -66,6 +68,12 @@ struct RSIParams : IndicatorParams { tf = _tf; }; void RSIParams(ENUM_TIMEFRAMES _tf) : period(12), applied_price(PRICE_WEIGHTED) { tf = _tf; } + // Getters. + ENUM_APPLIED_PRICE GetAppliedPrice() { return applied_price; } + unsigned int GetPeriod() { return period; } + // Setters. + void SetPeriod(unsigned int _period) { period = _period; } + void SetAppliedPrice(ENUM_APPLIED_PRICE _ap) { applied_price = _ap; } // Serializers. SERIALIZER_EMPTY_STUB; SerializerNodeType Serialize(Serializer &s) { @@ -87,19 +95,13 @@ struct RSIGainLossData { /** * Implements the Relative Strength Index indicator. */ -class Indi_RSI : public Indicator { +class Indi_RSI : public Indicator { public: - RSIParams params; - DictStruct aux_data; - /** * Class constructor. */ - Indi_RSI(const RSIParams &_params) : params(_params), Indicator((IndicatorParams)_params) { params = _params; } - Indi_RSI(const RSIParams &_params, ENUM_TIMEFRAMES _tf) : params(_params), Indicator(INDI_RSI, _tf) { - // @fixme - params.tf = _tf; - } + Indi_RSI(const RSIParams &_params) : Indicator(_params) {} + Indi_RSI(ENUM_TIMEFRAMES _tf) : Indicator(INDI_RSI, _tf) {} /** * Returns the indicator value. @@ -109,7 +111,8 @@ class Indi_RSI : public Indicator { * - https://www.mql5.com/en/docs/indicators/irsi */ static double iRSI(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, - ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, + Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iRSI(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ @@ -145,9 +148,11 @@ class Indi_RSI : public Indicator { /** * Calculates non-SMMA version of RSI on another indicator (uses iRSIOnArray). */ - static double iRSIOnArrayOnIndicator(Indicator *_indi, string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, - unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, - int _shift = 0, Indi_RSI *_obj = NULL) { + template + static double iRSIOnArrayOnIndicator(Indicator *_indi, string _symbol = NULL, + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, + ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, + Indi_RSI *_obj = NULL) { int i; double indi_values[]; ArrayResize(indi_values, _period); @@ -178,7 +183,8 @@ class Indi_RSI : public Indicator { * RSI values. To exactly replicate our RSI numbers, a formula will need at * least 250 data points." */ - static double iRSIOnIndicator(Indicator *_indi, Indi_RSI *_obj, string _symbol = NULL, + template + static double iRSIOnIndicator(Indicator *_indi, Indi_RSI *_obj, string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0) { long _bar_time_curr = _obj.GetBarTime(_shift); @@ -309,8 +315,8 @@ class Indi_RSI : public Indicator { * extern ENUM_APPLIED_PRICE applied_price; // Required only for MQL4. * extern int shift; * - * Also, remember to use params.SetCustomIndicatorName(name) method to choose - * indicator name, e.g.,: params.SetCustomIndicatorName("Examples\\RSI"); + * Also, remember to use iparams.SetCustomIndicatorName(name) method to choose + * indicator name, e.g.,: iparams.SetCustomIndicatorName("Examples\\RSI"); * * Note that in MQL5 Applied Price must be passed as the last parameter * (before mode and shift). @@ -318,21 +324,22 @@ class Indi_RSI : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_RSI::iRSI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetAppliedPrice(), _shift, GetPointer(this)); + _value = Indi_RSI::iRSI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), + iparams.GetPeriod(), iparams.GetAppliedPrice(), _shift, GetPointer(this)); break; case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.custom_indi_name, /* [ */ GetPeriod(), GetAppliedPrice() /* ] */, 0, _shift); + iparams.custom_indi_name, /* [ */ iparams.GetPeriod(), iparams.GetAppliedPrice() /* ] */, 0, + _shift); break; case IDATA_INDICATOR: - _value = - Indi_RSI::iRSIOnIndicator(GetDataSource(), GetPointer(this), Get(CHART_PARAM_SYMBOL), - Get(CHART_PARAM_TF), GetPeriod(), GetAppliedPrice(), _shift); + _value = Indi_RSI::iRSIOnIndicator(indi_src, GetPointer(this), Get(CHART_PARAM_SYMBOL), + Get(CHART_PARAM_TF), iparams.GetPeriod(), + iparams.GetAppliedPrice(), _shift); break; } istate.is_ready = GetLastError() == ERR_NO_ERROR; @@ -347,18 +354,18 @@ class Indi_RSI : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_DOUBLE, iparams.GetDataValueType() == TYPE_DOUBLE); _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -374,44 +381,10 @@ class Indi_RSI : public Indicator { return _param; } - /* Getters */ - - /** - * Get indicator params. - */ - RSIParams GetParams() { return params; } - - /** - * Get period value. - */ - unsigned int GetPeriod() { return params.period; } - - /** - * Get applied price value. - */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } - - /* Setters */ - - /** - * Set period value. - */ - void SetPeriod(unsigned int _period) { - istate.is_changed = true; - params.period = _period; - } - - /** - * Set applied price value. - */ - void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { - istate.is_changed = true; - params.applied_price = _applied_price; - } - /** * Provides built-in indicators whose can be used as data source. */ + /* @fixme virtual Indicator *FetchDataSource(ENUM_INDICATOR_TYPE _id) { if (_id == INDI_BANDS) { BandsParams bands_params(); @@ -438,4 +411,5 @@ class Indi_RSI : public Indicator { return Indicator::FetchDataSource(_id); } + */ }; diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index 3052880cd..6c86fe5c0 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -51,16 +51,13 @@ struct RVIParams : IndicatorParams { /** * Implements the Relative Vigor Index indicator. */ -class Indi_RVI : public Indicator { - protected: - RVIParams params; - +class Indi_RVI : public Indicator { public: /** * Class constructor. */ - Indi_RVI(const RVIParams &_p) : params(_p.period), Indicator((IndicatorParams)_p) { params = _p; } - Indi_RVI(const RVIParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.period), Indicator(INDI_RVI, _tf) { params = _p; } + Indi_RVI(const RVIParams &_p) : Indicator(_p) {} + Indi_RVI(ENUM_TIMEFRAMES _tf) : Indicator(INDI_RVI, _tf) {} /** * Returns the indicator value. @@ -72,7 +69,7 @@ class Indi_RVI : public Indicator { static double iRVI( string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 10, ENUM_SIGNAL_LINE _mode = LINE_MAIN, // (MT4/MT5): 0 - MODE_MAIN/MAIN_LINE, 1 - MODE_SIGNAL/SIGNAL_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iRVI(_symbol, _tf, _period, _mode, _shift); #else // __MQL5__ @@ -111,7 +108,7 @@ class Indi_RVI : public Indicator { double GetValue(ENUM_SIGNAL_LINE _mode = LINE_MAIN, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_RVI::iRVI(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), @@ -119,7 +116,7 @@ class Indi_RVI : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); + iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -135,17 +132,17 @@ class Indi_RVI : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_SIGNAL_LINE)_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -166,7 +163,7 @@ class Indi_RVI : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /* Setters */ @@ -175,6 +172,6 @@ class Indi_RVI : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } }; diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index 264c81fb4..6132ca7f3 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -51,24 +51,19 @@ struct RateOfChangeParams : IndicatorParams { /** * Implements the Rate of Change indicator. */ -class Indi_RateOfChange : public Indicator { - protected: - RateOfChangeParams params; - +class Indi_RateOfChange : public Indicator { public: /** * Class constructor. */ - Indi_RateOfChange(RateOfChangeParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_RateOfChange(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RATE_OF_CHANGE, _tf) { params.tf = _tf; }; + Indi_RateOfChange(RateOfChangeParams &_params) : Indicator(_params){}; + Indi_RateOfChange(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RATE_OF_CHANGE, _tf){}; /** * Built-in version of Rate of Change. */ static double iROC(string _symbol, ENUM_TIMEFRAMES _tf, int _period, ENUM_APPLIED_PRICE _ap, int _mode = 0, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_SHORT(_symbol, _tf, _ap, Util::MakeKey("Indi_RateOfChange", _period, (int)_ap)); return iROCOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_SHORT, _period, _mode, _shift, _cache); @@ -120,13 +115,13 @@ class Indi_RateOfChange : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_RateOfChange::iROC(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetAppliedPrice() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); break; default: @@ -143,17 +138,17 @@ class Indi_RateOfChange : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -174,12 +169,12 @@ class Indi_RateOfChange : public Indicator { /** * Get applied price. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /** * Get period. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /* Setters */ @@ -188,7 +183,7 @@ class Indi_RateOfChange : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } /** @@ -196,6 +191,6 @@ class Indi_RateOfChange : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } }; diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 71ea42780..ec11af942 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -52,16 +52,13 @@ struct SARParams : IndicatorParams { /** * Implements the Parabolic Stop and Reverse system indicator. */ -class Indi_SAR : public Indicator { - protected: - SARParams params; - +class Indi_SAR : public Indicator { public: /** * Class constructor. */ - Indi_SAR(SARParams &_p) : params(_p.step, _p.max), Indicator((IndicatorParams)_p) { params = _p; } - Indi_SAR(SARParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.step, _p.max), Indicator(INDI_SAR, _tf) { params = _p; } + Indi_SAR(SARParams &_p) : Indicator(_p) {} + Indi_SAR(ENUM_TIMEFRAMES _tf) : Indicator(INDI_SAR, _tf) {} /** * Returns the indicator value. @@ -71,7 +68,7 @@ class Indi_SAR : public Indicator { * - https://www.mql5.com/en/docs/indicators/isar */ static double iSAR(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, double _step = 0.02, - double _max = 0.2, int _shift = 0, Indicator *_obj = NULL) { + double _max = 0.2, int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iSAR(_symbol, _tf, _step, _max, _shift); #else // __MQL5__ @@ -110,7 +107,7 @@ class Indi_SAR : public Indicator { double GetValue(int _mode, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_SAR::iSAR(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetStep(), @@ -118,7 +115,7 @@ class Indi_SAR : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetStep(), GetMax() /*]*/, _mode, _shift); + iparams.GetCustomIndicatorName(), /*[*/ GetStep(), GetMax() /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -134,17 +131,17 @@ class Indi_SAR : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -165,12 +162,12 @@ class Indi_SAR : public Indicator { /** * Get step of price increment. */ - double GetStep() { return params.step; } + double GetStep() { return iparams.step; } /** * Get the maximum step. */ - double GetMax() { return params.max; } + double GetMax() { return iparams.max; } /* Setters */ @@ -179,7 +176,7 @@ class Indi_SAR : public Indicator { */ void SetStep(double _step) { istate.is_changed = true; - params.step = _step; + iparams.step = _step; } /** @@ -187,6 +184,6 @@ class Indi_SAR : public Indicator { */ void SetMax(double _max) { istate.is_changed = true; - params.max = _max; + iparams.max = _max; } }; diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index b0d0cb1c6..ece1242a5 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -69,22 +69,13 @@ struct StdDevParams : IndicatorParams { /** * Implements the Standard Deviation indicator. */ -class Indi_StdDev : public Indicator { - protected: - StdDevParams params; - +class Indi_StdDev : public Indicator { public: /** * Class constructor. */ - Indi_StdDev(StdDevParams &_p) - : params(_p.ma_period, _p.ma_shift, _p.ma_method, _p.applied_price), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_StdDev(StdDevParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.ma_period, _p.ma_shift, _p.ma_method, _p.applied_price), Indicator(INDI_STDDEV, _tf) { - params = _p; - } + Indi_StdDev(StdDevParams &_p) : Indicator(_p) {} + Indi_StdDev(ENUM_TIMEFRAMES _tf) : Indicator(INDI_STDDEV, _tf) {} /** * Calculates the Standard Deviation indicator and returns its value. @@ -94,7 +85,7 @@ class Indi_StdDev : public Indicator { * - https://www.mql5.com/en/docs/indicators/istddev */ static double iStdDev(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, ENUM_MA_METHOD _ma_method, - ENUM_APPLIED_PRICE _applied_price, int _shift = 0, Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price, int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iStdDev(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_price, _shift); #else // __MQL5__ @@ -130,8 +121,10 @@ class Indi_StdDev : public Indicator { /** * Note that this method operates on current price (set by _applied_price). */ - static double iStdDevOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, - ENUM_APPLIED_PRICE _applied_price, int _shift = 0, Indicator *_obj = NULL) { + template + static double iStdDevOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, + int _ma_shift, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, + Indi_StdDev *_obj = NULL) { double _indi_value_buffer[]; double _std_dev; int i; @@ -221,7 +214,7 @@ class Indi_StdDev : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = @@ -229,12 +222,12 @@ class Indi_StdDev : public Indicator { GetMAShift(), GetMAMethod(), GetAppliedPrice(), _shift, GetPointer(this)); break; case IDATA_ICUSTOM: - _value = - iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetMAPeriod(), GetMAShift(), GetMAMethod() /*]*/, 0, _shift); + _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), + iparams.GetCustomIndicatorName(), /*[*/ GetMAPeriod(), GetMAShift(), GetMAMethod() /*]*/, 0, + _shift); break; case IDATA_INDICATOR: - _value = Indi_StdDev::iStdDevOnIndicator(GetDataSource(), Get(CHART_PARAM_SYMBOL), + _value = Indi_StdDev::iStdDevOnIndicator(indi_src, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetMAPeriod(), GetMAShift(), GetAppliedPrice(), _shift, GetPointer(this)); break; @@ -250,7 +243,7 @@ class Indi_StdDev : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -258,7 +251,7 @@ class Indi_StdDev : public Indicator { _entry.values[0].Set(GetValue(_shift)); _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -281,26 +274,26 @@ class Indi_StdDev : public Indicator { * * Averaging period for the calculation of the moving average. */ - int GetMAPeriod() { return params.ma_period; } + int GetMAPeriod() { return iparams.ma_period; } /** * Get MA shift value. * * Indicators line offset relate to the chart by timeframe. */ - unsigned int GetMAShift() { return params.ma_shift; } + unsigned int GetMAShift() { return iparams.ma_shift; } /** * Set MA method (smoothing type). */ - ENUM_MA_METHOD GetMAMethod() { return params.ma_method; } + ENUM_MA_METHOD GetMAMethod() { return iparams.ma_method; } /** * Get applied price value. * * The desired price base for calculations. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -311,7 +304,7 @@ class Indi_StdDev : public Indicator { */ void SetMAPeriod(int _ma_period) { istate.is_changed = true; - params.ma_period = _ma_period; + iparams.ma_period = _ma_period; } /** @@ -319,7 +312,7 @@ class Indi_StdDev : public Indicator { */ void SetMAShift(int _ma_shift) { istate.is_changed = true; - params.ma_shift = _ma_shift; + iparams.ma_shift = _ma_shift; } /** @@ -329,7 +322,7 @@ class Indi_StdDev : public Indicator { */ void SetMAMethod(ENUM_MA_METHOD _ma_method) { istate.is_changed = true; - params.ma_method = _ma_method; + iparams.ma_method = _ma_method; } /** @@ -342,6 +335,6 @@ class Indi_StdDev : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 9c9908f86..f274ab466 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -59,22 +59,13 @@ struct StochParams : IndicatorParams { /** * Implements the Stochastic Oscillator. */ -class Indi_Stochastic : public Indicator { - protected: - StochParams params; - +class Indi_Stochastic : public Indicator { public: /** * Class constructor. */ - Indi_Stochastic(StochParams &_p) - : params(_p.kperiod, _p.dperiod, _p.slowing, _p.ma_method, _p.price_field), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_Stochastic(StochParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.kperiod, _p.dperiod, _p.slowing, _p.ma_method, _p.price_field), Indicator(INDI_STOCHASTIC, _tf) { - params = _p; - } + Indi_Stochastic(StochParams &_p) : Indicator(_p) {} + Indi_Stochastic(ENUM_TIMEFRAMES _tf) : Indicator(INDI_STOCHASTIC, _tf) {} /** * Calculates the Stochastic Oscillator and returns its value. @@ -89,7 +80,7 @@ class Indi_Stochastic : public Indicator { ENUM_STO_PRICE _price_field, // (MT4 _price_field): 0 - Low/High, 1 - Close/Close // (MT5 _price_field): STO_LOWHIGH - Low/High, STO_CLOSECLOSE - Close/Close int _mode, // (MT4): 0 - MODE_MAIN/MAIN_LINE, 1 - MODE_SIGNAL/SIGNAL_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iStochastic(_symbol, _tf, _kperiod, _dperiod, _slowing, _ma_method, _price_field, _mode, _shift); #else // __MQL5__ @@ -129,7 +120,7 @@ class Indi_Stochastic : public Indicator { double GetValue(ENUM_SIGNAL_LINE _mode = LINE_MAIN, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_Stochastic::iStochastic(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), @@ -138,7 +129,7 @@ class Indi_Stochastic : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetKPeriod(), GetDPeriod(), GetSlowing() /*]*/, _mode, + iparams.GetCustomIndicatorName(), /*[*/ GetKPeriod(), GetDPeriod(), GetSlowing() /*]*/, _mode, _shift); break; default: @@ -155,18 +146,18 @@ class Indi_Stochastic : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_SIGNAL_LINE)_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGe(0)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -187,27 +178,27 @@ class Indi_Stochastic : public Indicator { /** * Get period of the %K line. */ - int GetKPeriod() { return params.kperiod; } + int GetKPeriod() { return iparams.kperiod; } /** * Get period of the %D line. */ - int GetDPeriod() { return params.dperiod; } + int GetDPeriod() { return iparams.dperiod; } /** * Get slowing value. */ - int GetSlowing() { return params.slowing; } + int GetSlowing() { return iparams.slowing; } /** * Set MA method. */ - ENUM_MA_METHOD GetMAMethod() { return params.ma_method; } + ENUM_MA_METHOD GetMAMethod() { return iparams.ma_method; } /** * Get price field parameter. */ - ENUM_STO_PRICE GetPriceField() { return params.price_field; } + ENUM_STO_PRICE GetPriceField() { return iparams.price_field; } /* Setters */ @@ -216,7 +207,7 @@ class Indi_Stochastic : public Indicator { */ void SetKPeriod(int _kperiod) { istate.is_changed = true; - params.kperiod = _kperiod; + iparams.kperiod = _kperiod; } /** @@ -224,7 +215,7 @@ class Indi_Stochastic : public Indicator { */ void SetDPeriod(int _dperiod) { istate.is_changed = true; - params.dperiod = _dperiod; + iparams.dperiod = _dperiod; } /** @@ -232,7 +223,7 @@ class Indi_Stochastic : public Indicator { */ void SetSlowing(int _slowing) { istate.is_changed = true; - params.slowing = _slowing; + iparams.slowing = _slowing; } /** @@ -240,7 +231,7 @@ class Indi_Stochastic : public Indicator { */ void SetMAMethod(ENUM_MA_METHOD _ma_method) { istate.is_changed = true; - params.ma_method = _ma_method; + iparams.ma_method = _ma_method; } /** @@ -248,6 +239,6 @@ class Indi_Stochastic : public Indicator { */ void SetPriceField(ENUM_STO_PRICE _price_field) { istate.is_changed = true; - params.price_field = _price_field; + iparams.price_field = _price_field; } }; diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index 6c84ca1a3..fb45f2022 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -55,24 +55,19 @@ struct TEMAParams : IndicatorParams { /** * Implements the Triple Exponential Moving Average indicator. */ -class Indi_TEMA : public Indicator { - protected: - TEMAParams params; - +class Indi_TEMA : public Indicator { public: /** * Class constructor. */ - Indi_TEMA(TEMAParams &_params) : params(_params.period, _params.tema_shift), Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_TEMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TEMA, _tf) { params.tf = _tf; }; + Indi_TEMA(TEMAParams &_params) : Indicator(_params){}; + Indi_TEMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TEMA, _tf){}; /** * Built-in version of TEMA. */ static double iTEMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, ENUM_APPLIED_PRICE _ap, - int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + int _mode = 0, int _shift = 0, Indi_TEMA *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iTEMA(_symbol, _tf, _ma_period, _ma_shift, _ap), _mode, _shift); #else @@ -139,13 +134,13 @@ class Indi_TEMA : public Indicator { double GetValue(int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_TEMA::iTEMA(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetTEMAShift(), GetAppliedPrice() /*]*/, 0, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod(), GetTEMAShift() /*]*/, 0, _shift); break; default: @@ -162,7 +157,7 @@ class Indi_TEMA : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { @@ -170,7 +165,7 @@ class Indi_TEMA : public Indicator { _entry.values[0] = GetValue(_shift); _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -191,17 +186,17 @@ class Indi_TEMA : public Indicator { /** * Get period. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get TEMA shift. */ - unsigned int GetTEMAShift() { return params.tema_shift; } + unsigned int GetTEMAShift() { return iparams.tema_shift; } /** * Get applied price. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -210,7 +205,7 @@ class Indi_TEMA : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -218,7 +213,7 @@ class Indi_TEMA : public Indicator { */ void SetTEMAShift(unsigned int _tema_shift) { istate.is_changed = true; - params.tema_shift = _tema_shift; + iparams.tema_shift = _tema_shift; } /** @@ -226,6 +221,6 @@ class Indi_TEMA : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index 9d00d9d79..418d224fa 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -54,22 +54,19 @@ struct TRIXParams : IndicatorParams { /** * Implements the Triple Exponential Average indicator. */ -class Indi_TRIX : public Indicator { - protected: - TRIXParams params; - +class Indi_TRIX : public Indicator { public: /** * Class constructor. */ - Indi_TRIX(TRIXParams &_params) : params(_params.period), Indicator((IndicatorParams)_params) { params = _params; }; - Indi_TRIX(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TRIX, _tf) { params.tf = _tf; }; + Indi_TRIX(TRIXParams &_params) : Indicator(_params){}; + Indi_TRIX(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TRIX, _tf){}; /** * Built-in version of TriX. */ static double iTriX(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, ENUM_APPLIED_PRICE _ap, int _mode = 0, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iTriX(_symbol, _tf, _ma_period, _ap), _mode, _shift); #else @@ -138,13 +135,13 @@ class Indi_TRIX : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_TRIX::iTriX(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetAppliedPrice() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); break; default: @@ -161,17 +158,17 @@ class Indi_TRIX : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -192,12 +189,12 @@ class Indi_TRIX : public Indicator { /** * Get period. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get applied price. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -206,7 +203,7 @@ class Indi_TRIX : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -214,6 +211,6 @@ class Indi_TRIX : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 1c22bd851..615d1faf4 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -70,26 +70,20 @@ struct UltimateOscillatorParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_UltimateOscillator : public Indicator { - protected: - UltimateOscillatorParams params; - +class Indi_UltimateOscillator : public Indicator { public: /** * Class constructor. */ - Indi_UltimateOscillator(UltimateOscillatorParams &_params) : Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_UltimateOscillator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ULTIMATE_OSCILLATOR, _tf) { - params.tf = _tf; - }; + Indi_UltimateOscillator(UltimateOscillatorParams &_params) : Indicator(_params){}; + Indi_UltimateOscillator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ULTIMATE_OSCILLATOR, _tf){}; /** * Built-in version of Ultimate Oscillator. */ static double iUO(string _symbol, ENUM_TIMEFRAMES _tf, int _fast_period, int _middle_period, int _slow_period, - int _fast_k, int _middle_k, int _slow_k, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + int _fast_k, int _middle_k, int _slow_k, int _mode = 0, int _shift = 0, + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG( _symbol, _tf, Util::MakeKey("Indi_UltimateOscillator", _fast_period, _middle_period, _slow_period, _fast_k, _middle_k, @@ -108,8 +102,9 @@ class Indi_UltimateOscillator : public Indicator { */ static double iUOOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _fast_period, int _middle_period, int _slow_period, int _fast_k, int _middle_k, int _slow_k, int _mode, int _shift, - IndicatorCalculateCache *_cache, Indicator *_indi_atr_fast, - Indicator *_indi_atr_middle, Indicator *_indi_atr_slow, bool _recalculate = false) { + IndicatorCalculateCache *_cache, Indicator *_indi_atr_fast, + Indicator *_indi_atr_middle, Indicator *_indi_atr_slow, + bool _recalculate = false) { _cache.SetPriceBuffer(_open, _high, _low, _close); if (!_cache.HasBuffers()) { @@ -135,8 +130,8 @@ class Indi_UltimateOscillator : public Indicator { ValueStorage &ExtBPBuffer, ValueStorage &ExtFastATRBuffer, ValueStorage &ExtMiddleATRBuffer, ValueStorage &ExtSlowATRBuffer, int InpFastPeriod, int InpMiddlePeriod, int InpSlowPeriod, int InpFastK, int InpMiddleK, - int InpSlowK, Indicator *ExtFastATRhandle, Indicator *ExtMiddleATRhandle, - Indicator *ExtSlowATRhandle) { + int InpSlowK, Indi_ATR *ExtFastATRhandle, Indi_ATR *ExtMiddleATRhandle, + Indi_ATR *ExtSlowATRhandle) { double ExtDivider = InpFastK + InpMiddleK + InpSlowK; double true_low; int ExtMaxPeriod = InpSlowPeriod; @@ -225,14 +220,14 @@ class Indi_UltimateOscillator : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_UltimateOscillator::iUO(GetSymbol(), GetTf(), /*[*/ GetFastPeriod(), GetMiddlePeriod(), GetSlowPeriod(), GetFastK(), GetMiddleK(), GetSlowK() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetFastPeriod(), GetMiddlePeriod(), GetSlowPeriod(), GetFastK(), GetMiddleK(), GetSlowK() /*]*/, @@ -252,17 +247,17 @@ class Indi_UltimateOscillator : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -283,32 +278,32 @@ class Indi_UltimateOscillator : public Indicator { /** * Get fast period. */ - int GetFastPeriod() { return params.fast_period; } + int GetFastPeriod() { return iparams.fast_period; } /** * Get middle period. */ - int GetMiddlePeriod() { return params.middle_period; } + int GetMiddlePeriod() { return iparams.middle_period; } /** * Get slow period. */ - int GetSlowPeriod() { return params.slow_period; } + int GetSlowPeriod() { return iparams.slow_period; } /** * Get fast k. */ - int GetFastK() { return params.fast_k; } + int GetFastK() { return iparams.fast_k; } /** * Get middle k. */ - int GetMiddleK() { return params.middle_k; } + int GetMiddleK() { return iparams.middle_k; } /** * Get slow k. */ - int GetSlowK() { return params.slow_k; } + int GetSlowK() { return iparams.slow_k; } /* Setters */ @@ -317,7 +312,7 @@ class Indi_UltimateOscillator : public Indicator { */ void SetFastPeriod(int _fast_period) { istate.is_changed = true; - params.fast_period = _fast_period; + iparams.fast_period = _fast_period; } /** @@ -325,7 +320,7 @@ class Indi_UltimateOscillator : public Indicator { */ void SetMiddlePeriod(int _middle_period) { istate.is_changed = true; - params.middle_period = _middle_period; + iparams.middle_period = _middle_period; } /** @@ -333,7 +328,7 @@ class Indi_UltimateOscillator : public Indicator { */ void SetSlowPeriod(int _slow_period) { istate.is_changed = true; - params.slow_period = _slow_period; + iparams.slow_period = _slow_period; } /** @@ -341,7 +336,7 @@ class Indi_UltimateOscillator : public Indicator { */ void SetFastK(int _fast_k) { istate.is_changed = true; - params.fast_k = _fast_k; + iparams.fast_k = _fast_k; } /** @@ -349,7 +344,7 @@ class Indi_UltimateOscillator : public Indicator { */ void SetMiddleK(int _middle_k) { istate.is_changed = true; - params.middle_k = _middle_k; + iparams.middle_k = _middle_k; } /** @@ -357,6 +352,6 @@ class Indi_UltimateOscillator : public Indicator { */ void SetSlowK(int _slow_k) { istate.is_changed = true; - params.slow_k = _slow_k; + iparams.slow_k = _slow_k; } }; diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index 7c9f9727e..e608af1bf 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -57,22 +57,19 @@ struct VIDYAParams : IndicatorParams { /** * Implements the Variable Index Dynamic Average indicator. */ -class Indi_VIDYA : public Indicator { - protected: - VIDYAParams params; - +class Indi_VIDYA : public Indicator { public: /** * Class constructor. */ - Indi_VIDYA(VIDYAParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_VIDYA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VIDYA, _tf) { params.tf = _tf; }; + Indi_VIDYA(VIDYAParams &_params) : Indicator(_params){}; + Indi_VIDYA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VIDYA, _tf){}; /** * Built-in version of iVIDyA. */ static double iVIDyA(string _symbol, ENUM_TIMEFRAMES _tf, int _cmo_period, int _ema_period, int _ma_shift, - ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iVIDyA(_symbol, _tf, _cmo_period, _ema_period, _ma_shift, _ap), _mode, _shift); #else @@ -157,13 +154,13 @@ class Indi_VIDYA : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_VIDYA::iVIDyA(GetSymbol(), GetTf(), /*[*/ GetCMOPeriod(), GetMAPeriod(), GetVIDYAShift(), GetAppliedPrice() /*]*/, 0, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), /*[*/ + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetCMOPeriod(), GetMAPeriod(), GetVIDYAShift() /*]*/, @@ -183,17 +180,17 @@ class Indi_VIDYA : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -214,22 +211,22 @@ class Indi_VIDYA : public Indicator { /** * Get CMO period. */ - unsigned int GetCMOPeriod() { return params.cmo_period; } + unsigned int GetCMOPeriod() { return iparams.cmo_period; } /** * Get MA period. */ - unsigned int GetMAPeriod() { return params.ma_period; } + unsigned int GetMAPeriod() { return iparams.ma_period; } /** * Get VIDYA shift. */ - unsigned int GetVIDYAShift() { return params.vidya_shift; } + unsigned int GetVIDYAShift() { return iparams.vidya_shift; } /** * Get applied price. */ - ENUM_APPLIED_PRICE GetAppliedPrice() { return params.applied_price; } + ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; } /* Setters */ @@ -238,7 +235,7 @@ class Indi_VIDYA : public Indicator { */ void SetCMOPeriod(unsigned int _cmo_period) { istate.is_changed = true; - params.cmo_period = _cmo_period; + iparams.cmo_period = _cmo_period; } /** @@ -246,7 +243,7 @@ class Indi_VIDYA : public Indicator { */ void SetMAPeriod(unsigned int _ma_period) { istate.is_changed = true; - params.ma_period = _ma_period; + iparams.ma_period = _ma_period; } /** @@ -254,7 +251,7 @@ class Indi_VIDYA : public Indicator { */ void SetVIDYAShift(unsigned int _vidya_shift) { istate.is_changed = true; - params.vidya_shift = _vidya_shift; + iparams.vidya_shift = _vidya_shift; } /** @@ -262,6 +259,6 @@ class Indi_VIDYA : public Indicator { */ void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) { istate.is_changed = true; - params.applied_price = _applied_price; + iparams.applied_price = _applied_price; } }; diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index 5a1d21654..1c9be8a17 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -51,22 +51,19 @@ struct VROCParams : IndicatorParams { /** * Implements the Volume Rate of Change indicator. */ -class Indi_VROC : public Indicator { - protected: - VROCParams params; - +class Indi_VROC : public Indicator { public: /** * Class constructor. */ - Indi_VROC(VROCParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_VROC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf) { params.tf = _tf; }; + Indi_VROC(VROCParams &_params) : Indicator(_params){}; + Indi_VROC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf){}; /** * Built-in version of VROC. */ static double iVROC(string _symbol, ENUM_TIMEFRAMES _tf, int _period, ENUM_APPLIED_VOLUME _av, int _mode = 0, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, Util::MakeKey("Indi_VROC", _period, (int)_av)); return iVROCOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _period, _av, _mode, _shift, _cache); } @@ -140,13 +137,13 @@ class Indi_VROC : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_VROC::iVROC(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetAppliedVolume() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod(), GetAppliedVolume() /*]*/, _mode, _shift); break; default: @@ -163,17 +160,17 @@ class Indi_VROC : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -194,12 +191,12 @@ class Indi_VROC : public Indicator { /** * Get period volume. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /** * Get applied volume. */ - ENUM_APPLIED_VOLUME GetAppliedVolume() { return params.applied_volume; } + ENUM_APPLIED_VOLUME GetAppliedVolume() { return iparams.applied_volume; } /* Setters */ @@ -208,7 +205,7 @@ class Indi_VROC : public Indicator { */ void SetPeriod(ENUM_APPLIED_VOLUME _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } /** @@ -216,6 +213,6 @@ class Indi_VROC : public Indicator { */ void SetAppliedVolume(ENUM_APPLIED_VOLUME _applied_volume) { istate.is_changed = true; - params.applied_volume = _applied_volume; + iparams.applied_volume = _applied_volume; } }; diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 2fec77e98..de1e88ffe 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -49,24 +49,19 @@ struct VolumesParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_Volumes : public Indicator { - protected: - VolumesParams params; - +class Indi_Volumes : public Indicator { public: /** * Class constructor. */ - Indi_Volumes(VolumesParams &_params) : params(_params.applied_volume), Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_Volumes(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VOLUMES, _tf) { params.tf = _tf; }; + Indi_Volumes(VolumesParams &_params) : Indicator(_params){}; + Indi_Volumes(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VOLUMES, _tf){}; /** * Built-in version of Volumes. */ static double iVolumes(string _symbol, ENUM_TIMEFRAMES _tf, ENUM_APPLIED_VOLUME _av, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, Util::MakeKey("Indi_Volumes", (int)_av)); return iVolumesOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _av, _mode, _shift, _cache); } @@ -133,12 +128,12 @@ class Indi_Volumes : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_Volumes::iVolumes(GetSymbol(), GetTf(), /*[*/ GetAppliedVolume() /*]*/, _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetAppliedVolume() /*]*/, _mode, _shift); break; default: @@ -155,17 +150,17 @@ class Indi_Volumes : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -186,7 +181,7 @@ class Indi_Volumes : public Indicator { /** * Get applied volume. */ - ENUM_APPLIED_VOLUME GetAppliedVolume() { return params.applied_volume; } + ENUM_APPLIED_VOLUME GetAppliedVolume() { return iparams.applied_volume; } /* Setters */ @@ -195,6 +190,6 @@ class Indi_Volumes : public Indicator { */ void SetAppliedVolume(ENUM_APPLIED_VOLUME _applied_volume) { istate.is_changed = true; - params.applied_volume = _applied_volume; + iparams.applied_volume = _applied_volume; } }; diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index 433443763..ad96b1ca8 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -51,16 +51,13 @@ struct WPRParams : IndicatorParams { /** * Implements the Larry Williams' Percent Range. */ -class Indi_WPR : public Indicator { - protected: - WPRParams params; - +class Indi_WPR : public Indicator { public: /** * Class constructor. */ - Indi_WPR(WPRParams &_p) : params(_p.period), Indicator((IndicatorParams)_p) { params = _p; } - Indi_WPR(WPRParams &_p, ENUM_TIMEFRAMES _tf) : params(_p.period), Indicator(INDI_WPR, _tf) { params = _p; } + Indi_WPR(WPRParams &_p) : Indicator(_p) {} + Indi_WPR(ENUM_TIMEFRAMES _tf) : Indicator(INDI_WPR, _tf) {} /** * Calculates the Larry Williams' Percent Range and returns its value. @@ -70,7 +67,7 @@ class Indi_WPR : public Indicator { * - https://www.mql5.com/en/docs/indicators/iwpr */ static double iWPR(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, Indicator *_obj = NULL) { #ifdef __MQL4__ return ::iWPR(_symbol, _tf, _period, _shift); #else // __MQL5__ @@ -109,7 +106,7 @@ class Indi_WPR : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_WPR::iWPR(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), @@ -117,7 +114,7 @@ class Indi_WPR : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); + iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -133,17 +130,17 @@ class Indi_WPR : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -164,7 +161,7 @@ class Indi_WPR : public Indicator { /** * Get period value. */ - unsigned int GetPeriod() { return params.period; } + unsigned int GetPeriod() { return iparams.period; } /* Setters */ @@ -173,6 +170,6 @@ class Indi_WPR : public Indicator { */ void SetPeriod(unsigned int _period) { istate.is_changed = true; - params.period = _period; + iparams.period = _period; } }; diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index 9719ca282..57c360de2 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -46,21 +46,19 @@ struct WilliamsADParams : IndicatorParams { /** * Implements the Volume Rate of Change indicator. */ -class Indi_WilliamsAD : public Indicator { - protected: - WilliamsADParams params; - +class Indi_WilliamsAD : public Indicator { public: /** * Class constructor. */ - Indi_WilliamsAD(WilliamsADParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_WilliamsAD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_WILLIAMS_AD, _tf) { params.tf = _tf; }; + Indi_WilliamsAD(WilliamsADParams &_params) : Indicator(_params){}; + Indi_WilliamsAD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_WILLIAMS_AD, _tf){}; /** * Built-in version of Williams' AD. */ - static double iWAD(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + static double iWAD(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, + Indicator *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_WilliamsAD"); return iWADOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _shift, _cache); } @@ -133,12 +131,12 @@ class Indi_WilliamsAD : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_WilliamsAD::iWAD(GetSymbol(), GetTf(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), params.GetCustomIndicatorName(), 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), 0, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); @@ -154,17 +152,17 @@ class Indi_WilliamsAD : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index e4e804c22..4490df8b8 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -59,27 +59,20 @@ enum EnSearchMode { /** * Implements ZigZag indicator. */ -class Indi_ZigZag : public Indicator { - protected: - ZigZagParams params; - +class Indi_ZigZag : public Indicator { public: /** * Class constructor. */ - Indi_ZigZag(ZigZagParams &_p) : params(_p.depth, _p.deviation, _p.backstep), Indicator((IndicatorParams)_p) { - params = _p; - } - Indi_ZigZag(ZigZagParams &_p, ENUM_TIMEFRAMES _tf) - : params(_p.depth, _p.deviation, _p.backstep), Indicator(INDI_ZIGZAG, _tf) { - params = _p; - } + Indi_ZigZag(ZigZagParams &_p) : Indicator(_p) {} + Indi_ZigZag(ENUM_TIMEFRAMES _tf) : Indicator(INDI_ZIGZAG, _tf) {} /** * Returns value for ZigZag indicator. */ static double iCustomZigZag(string _symbol, ENUM_TIMEFRAMES _tf, string _name, int _depth, int _deviation, - int _backstep, ENUM_ZIGZAG_LINE _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + int _backstep, ENUM_ZIGZAG_LINE _mode = 0, int _shift = 0, + Indicator *_obj = NULL) { #ifdef __MQL5__ int _handle = Object::IsValid(_obj) ? _obj.Get(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL; double _res[]; @@ -116,7 +109,7 @@ class Indi_ZigZag : public Indicator { * Returns value for ZigZag indicator. */ static double iZigZag(string _symbol, ENUM_TIMEFRAMES _tf, int _depth, int _deviation, int _backstep, - ENUM_ZIGZAG_LINE _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + ENUM_ZIGZAG_LINE _mode = 0, int _shift = 0, Indi_ZigZag *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, Util::MakeKey("Indi_ZigZag", _depth, _deviation, _backstep)); return iZigZagOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _depth, _deviation, _backstep, _mode, _shift, @@ -347,14 +340,14 @@ class Indi_ZigZag : public Indicator { double GetValue(ENUM_ZIGZAG_LINE _mode, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: _value = Indi_ZigZag::iZigZag(GetSymbol(), GetTf(), GetDepth(), GetDeviation(), GetBackstep(), _mode, _shift, GetPointer(this)); break; case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_ZigZag::iCustomZigZag(GetSymbol(), GetTf(), params.GetCustomIndicatorName(), GetDepth(), + _value = Indi_ZigZag::iCustomZigZag(GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), GetDepth(), GetDeviation(), GetBackstep(), _mode, _shift, GetPointer(this)); break; default: @@ -371,17 +364,17 @@ class Indi_ZigZag : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_ZIGZAG_LINE)_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -402,17 +395,17 @@ class Indi_ZigZag : public Indicator { /** * Get depth. */ - unsigned int GetDepth() { return params.depth; } + unsigned int GetDepth() { return iparams.depth; } /** * Get deviation. */ - unsigned int GetDeviation() { return params.deviation; } + unsigned int GetDeviation() { return iparams.deviation; } /** * Get backstep. */ - unsigned int GetBackstep() { return params.backstep; } + unsigned int GetBackstep() { return iparams.backstep; } /* Setters */ @@ -421,7 +414,7 @@ class Indi_ZigZag : public Indicator { */ void SetDepth(unsigned int _depth) { istate.is_changed = true; - params.depth = _depth; + iparams.depth = _depth; } /** @@ -429,7 +422,7 @@ class Indi_ZigZag : public Indicator { */ void SetDeviation(unsigned int _deviation) { istate.is_changed = true; - params.deviation = _deviation; + iparams.deviation = _deviation; } /** @@ -437,6 +430,6 @@ class Indi_ZigZag : public Indicator { */ void SetBackstep(unsigned int _backstep) { istate.is_changed = true; - params.backstep = _backstep; + iparams.backstep = _backstep; } }; diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 2ec756b94..e66edd87c 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -54,19 +54,13 @@ struct ZigZagColorParams : IndicatorParams { /** * Implements the Volume Rate of Change indicator. */ -class Indi_ZigZagColor : public Indicator { - protected: - ZigZagColorParams params; - +class Indi_ZigZagColor : public Indicator { public: /** * Class constructor. */ - Indi_ZigZagColor(ZigZagColorParams &_params) - : params(_params.depth, _params.deviation, _params.backstep), Indicator((IndicatorParams)_params) { - params = _params; - }; - Indi_ZigZagColor(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf) { params.tf = _tf; }; + Indi_ZigZagColor(ZigZagColorParams &_params) : Indicator(_params){}; + Indi_ZigZagColor(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf){}; /** * Returns the indicator's value. @@ -74,10 +68,10 @@ class Indi_ZigZagColor : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_ICUSTOM: _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - params.GetCustomIndicatorName(), + iparams.GetCustomIndicatorName(), /*[*/ GetDepth(), GetDeviation(), GetBackstep() /*]*/, _mode, _shift); break; default: @@ -94,17 +88,17 @@ class Indi_ZigZagColor : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.values[0].Get() != EMPTY_VALUE); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -125,17 +119,17 @@ class Indi_ZigZagColor : public Indicator { /** * Get depth. */ - unsigned int GetDepth() { return params.depth; } + unsigned int GetDepth() { return iparams.depth; } /** * Get deviation. */ - unsigned int GetDeviation() { return params.deviation; } + unsigned int GetDeviation() { return iparams.deviation; } /** * Get backstep. */ - unsigned int GetBackstep() { return params.backstep; } + unsigned int GetBackstep() { return iparams.backstep; } /* Setters */ @@ -144,7 +138,7 @@ class Indi_ZigZagColor : public Indicator { */ void SetDepth(unsigned int _depth) { istate.is_changed = true; - params.depth = _depth; + iparams.depth = _depth; } /** @@ -152,7 +146,7 @@ class Indi_ZigZagColor : public Indicator { */ void SetDeviation(unsigned int _deviation) { istate.is_changed = true; - params.deviation = _deviation; + iparams.deviation = _deviation; } /** @@ -160,6 +154,6 @@ class Indi_ZigZagColor : public Indicator { */ void SetBackstep(unsigned int _backstep) { istate.is_changed = true; - params.backstep = _backstep; + iparams.backstep = _backstep; } }; diff --git a/Indicators/README.md b/Indicators/README.md index ee7353588..439bfea2d 100644 --- a/Indicators/README.md +++ b/Indicators/README.md @@ -33,8 +33,8 @@ Example using a static call: Example usage: IndicatorParams iparams; - ADX_Params params(14, PRICE_HIGH); - Indi_ADX *adx = new Indi_ADX(params, iparams); + ADX_Params iparams(14, PRICE_HIGH); + Indi_ADX *adx = new Indi_ADX(iparams, iparams); Print("ADX: ", adx.GetValue(LINE_MAIN_ADX)); delete adx; @@ -60,8 +60,8 @@ Example using a static call: Example usage: IndicatorParams iparams; - ATR_Params params(14); - Indi_ATR *atr = new Indi_ATR(params, iparams); + ATR_Params iparams(14); + Indi_ATR *atr = new Indi_ATR(iparams, iparams); Print("ATR: ", atr.GetValue()); delete atr; @@ -74,8 +74,8 @@ Example using a static call: Example usage: IndicatorParams iparams; - Alligator_Params params(13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN); - Indi_Alligator *alligator = new Indi_Alligator(params, iparams); + Alligator_Params iparams(13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN); + Indi_Alligator *alligator = new Indi_Alligator(iparams, iparams); Print("Alligator: ", alligator.GetValue(LINE_JAW)); delete alligator; @@ -103,8 +103,8 @@ Example using a static call: Example usage: IndicatorParams iparams; - Bands_Params params(20, 2, 0, PRICE_LOW); - Indi_Bands *bands = new Indi_Bands(params, iparams); + Bands_Params iparams(20, 2, 0, PRICE_LOW); + Indi_Bands *bands = new Indi_Bands(iparams, iparams); Print("Bands: ", bands.GetValue(BAND_BASE)); delete bands; @@ -117,12 +117,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - BearsPower_Params params(13, PRICE_CLOSE); - Indi_BearsPower *bp = new Indi_BearsPower(params, iparams); + BearsPower_Params iparams(13, PRICE_CLOSE); + Indi_BearsPower *bp = new Indi_BearsPower(iparams, iparams); Print("BearsPower: ", bp.GetValue()); delete bp; -Example changing params: +Example changing iparams: bp.SetPeriod(bp.GetPeriod()+1); bp.SetAppliedPrice(PRICE_MEDIAN); @@ -136,12 +136,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - BullsPower_Params params(13, PRICE_CLOSE); - Indi_BullsPower *bp = new Indi_BullsPower(params, iparams); + BullsPower_Params iparams(13, PRICE_CLOSE); + Indi_BullsPower *bp = new Indi_BullsPower(iparams, iparams); Print("BullsPower: ", bp.GetValue()); delete bp; -Example changing params: +Example changing iparams: bp.SetPeriod(bp.GetPeriod()+1); bp.SetAppliedPrice(PRICE_MEDIAN); @@ -155,12 +155,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - CCI_Params params(14, PRICE_CLOSE); - Indi_CCI *cci = new Indi_CCI(params, iparams); + CCI_Params iparams(14, PRICE_CLOSE); + Indi_CCI *cci = new Indi_CCI(iparams, iparams); Print("CCI: ", cci.GetValue()); delete cci; -Example changing params: +Example changing iparams: cci.SetPeriod(cci.GetPeriod()+1); @@ -173,27 +173,27 @@ Example using a static call: Example usage: IndicatorParams iparams; - DeMarker_Params params; - params.period = 14; - Indi_DeMarker *dm = new Indi_DeMarker(params, iparams); + DeMarker_Params iparams; + iparams.period = 14; + Indi_DeMarker *dm = new Indi_DeMarker(iparams, iparams); Print("DeMarker: ", dm.GetValue()); delete dm; Example using a static call: - double dm_value = Indi_DeMarker::iDeMarker(_Symbol, PERIOD_CURRENT, params.period); + double dm_value = Indi_DeMarker::iDeMarker(_Symbol, PERIOD_CURRENT, iparams.period); ## Envelopes Example usage: IndicatorParams iparams; - Envelopes_Params params(13, 0, MODE_SMA, PRICE_CLOSE, 2); - Indi_Envelopes *env = new Indi_Envelopes(params, iparams); + Envelopes_Params iparams(13, 0, MODE_SMA, PRICE_CLOSE, 2); + Indi_Envelopes *env = new Indi_Envelopes(iparams, iparams); Print("Envelopes: ", env.GetValue(LINE_UPPER)); delete env; -Example changing params: +Example changing iparams: env.SetMAPeriod(env.GetMAPeriod()+1); env.SetMAMethod(MODE_SMA); @@ -210,12 +210,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - Force_Params params(13, MODE_SMA, PRICE_CLOSE); - Indi_Force *force = new Indi_Force(params, iparams); + Force_Params iparams(13, MODE_SMA, PRICE_CLOSE); + Indi_Force *force = new Indi_Force(iparams, iparams); Print("Force: ", force.GetValue()); delete force; -Example changing params: +Example changing iparams: force.SetPeriod(force.GetPeriod()+1); force.SetMAMethod(MODE_SMA); @@ -243,12 +243,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - Gator_Params params(13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN); - Indi_Gator *gator = new Indi_Gator(params, iparams); + Gator_Params iparams(13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN); + Indi_Gator *gator = new Indi_Gator(iparams, iparams); Print("Gator: ", gator.GetValue(LINE_JAW)); delete gator; -Example changing params: +Example changing iparams: gator.SetJawPeriod(gator.GetJawPeriod()+1); gator.SetJawShift(gator.GetJawShift()+1); @@ -279,12 +279,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - Ichimoku_Params params(9, 26, 52); - Indi_Ichimoku *ichimoku = new Indi_Ichimoku(params, iparams); + Ichimoku_Params iparams(9, 26, 52); + Indi_Ichimoku *ichimoku = new Indi_Ichimoku(iparams, iparams); Print("Ichimoku: ", ichimoku.GetValue(LINE_TENKANSEN)); delete ichimoku; -Example changing params: +Example changing iparams: ichimoku.SetTenkanSen(ichimoku.GetTenkanSen()+1); ichimoku.SetKijunSen(ichimoku.GetKijunSen()+1); @@ -299,12 +299,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - MA_Params params(13, 10, MODE_SMA, PRICE_CLOSE); - Indi_MA *ma = new Indi_MA(params, iparams); + MA_Params iparams(13, 10, MODE_SMA, PRICE_CLOSE); + Indi_MA *ma = new Indi_MA(iparams, iparams); Print("MA: ", ma.GetValue()); delete ma; -Example changing params: +Example changing iparams: ma.SetPeriod(ma.GetPeriod()+1); ma.SetMAShift(ma.GetMAShift()+1); @@ -320,12 +320,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - MACD_Params params(12, 26, 9, PRICE_CLOSE); - Indi_MACD *macd = new Indi_MACD(params, iparams); + MACD_Params iparams(12, 26, 9, PRICE_CLOSE); + Indi_MACD *macd = new Indi_MACD(iparams, iparams); Print("MACD: ", macd.GetValue(LINE_MAIN)); delete macd; -Example changing params: +Example changing iparams: macd.SetEmaFastPeriod(macd.GetEmaFastPeriod()+1); macd.SetEmaSlowPeriod(macd.GetEmaSlowPeriod()+1); @@ -341,13 +341,13 @@ Example using a static call: Example usage: IndicatorParams iparams; - MFI_Params params; - params.ma_period = 14; - params.applied_volume = VOLUME_TICK; // Used in MT5 only. - Indi_MFI *mfi = new Indi_MFI(params, iparams); + MFI_Params iparams; + iparams.ma_period = 14; + iparams.applied_volume = VOLUME_TICK; // Used in MT5 only. + Indi_MFI *mfi = new Indi_MFI(iparams, iparams); Print("MFI: ", mfi.GetValue()); -Example changing params: +Example changing iparams: mfi.SetPeriod(mfi.GetPeriod()+1); mfi.SetAppliedVolume(VOLUME_REAL); @@ -361,12 +361,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - Momentum_Params params(12, PRICE_CLOSE); - Indi_Momentum *mom = new Indi_Momentum(params, iparams); + Momentum_Params iparams(12, PRICE_CLOSE); + Indi_Momentum *mom = new Indi_Momentum(iparams, iparams); Print("Momentum: ", mom.GetValue()); delete mom; -Example changing params: +Example changing iparams: mom.SetPeriod(mom.GetPeriod()+1); mom.SetAppliedPrice(PRICE_MEDIAN); @@ -380,14 +380,14 @@ Example using a static call: Example usage: IndicatorParams iparams; - OBV_Params params; - params.applied_price = PRICE_CLOSE; // Used in MT4. - params.applied_volume = VOLUME_TICK; // Used in MT5. - Indi_OBV *obv = new Indi_OBV(params, iparams); + OBV_Params iparams; + iparams.applied_price = PRICE_CLOSE; // Used in MT4. + iparams.applied_volume = VOLUME_TICK; // Used in MT5. + Indi_OBV *obv = new Indi_OBV(iparams, iparams); Print("OBV: ", obv.GetValue()); delete obv; -Example changing params: +Example changing iparams: obv.SetAppliedPrice(PRICE_MEDIAN); obv.SetAppliedVolume(VOLUME_REAL); @@ -401,13 +401,13 @@ Example using a static call: Example usage: IndicatorParams iparams; - OsMA_Params params(12, 26, 9, PRICE_CLOSE); - params.applied_price = PRICE_CLOSE; - Indi_OsMA *osma = new Indi_OsMA(params, iparams); + OsMA_Params iparams(12, 26, 9, PRICE_CLOSE); + iparams.applied_price = PRICE_CLOSE; + Indi_OsMA *osma = new Indi_OsMA(iparams, iparams); Print("OsMA: ", osma.GetValue()); delete osma; -Example changing params: +Example changing iparams: osma.SetEmaFastPeriod(osma.GetEmaFastPeriod()+1); osma.SetEmaSlowPeriod(osma.GetEmaSlowPeriod()+1); @@ -423,12 +423,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - RSI_Params params(14, PRICE_CLOSE); - Indi_RSI *rsi = new Indi_RSI(params, iparams); + RSI_Params iparams(14, PRICE_CLOSE); + Indi_RSI *rsi = new Indi_RSI(iparams, iparams); Print("RSI: ", rsi.GetValue()); delete rsi; -Example changing params: +Example changing iparams: rsi.SetPeriod(rsi.GetPeriod()+1); rsi.SetAppliedPrice(PRICE_MEDIAN); @@ -442,12 +442,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - RVI_Params params(14); - Indi_RVI *rvi = new Indi_RVI(params, iparams); + RVI_Params iparams(14); + Indi_RVI *rvi = new Indi_RVI(iparams, iparams); Print("RVI: ", rvi.GetValue(LINE_MAIN)); delete rvi; -Example changing params: +Example changing iparams: rvi.SetPeriod(rvi.GetPeriod()+1); @@ -460,12 +460,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - SAR_Params params(0.02, 0.2); - Indi_SAR *sar = new Indi_SAR(params, iparams); + SAR_Params iparams(0.02, 0.2); + Indi_SAR *sar = new Indi_SAR(iparams, iparams); Print("SAR: ", sar.GetValue()); delete sar; -Example changing params: +Example changing iparams: sar.SetStep(sar.GetStep()*2); sar.SetMax(sar.GetMax()*2); @@ -479,12 +479,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - StdDev_Params params(13, 10, MODE_SMA, PRICE_CLOSE); - Indi_StdDev *sd = new Indi_StdDev(params, iparams); + StdDev_Params iparams(13, 10, MODE_SMA, PRICE_CLOSE); + Indi_StdDev *sd = new Indi_StdDev(iparams, iparams); Print("StdDev: ", sd.GetValue()); delete sd; -Example changing params: +Example changing iparams: sd.SetPeriod(sd.GetPeriod()+1); sd.SetMAShift(sd.GetMAShift()+1); @@ -500,12 +500,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - Stoch_Params params(5, 3, 3, MODE_SMMA, STO_LOWHIGH); - Indi_Stochastic *stoch = new Indi_Stochastic(params, iparams); + Stoch_Params iparams(5, 3, 3, MODE_SMMA, STO_LOWHIGH); + Indi_Stochastic *stoch = new Indi_Stochastic(iparams, iparams); Print("Stochastic: ", stoch.GetValue()); delete stoch; -Example changing params: +Example changing iparams: stoch.SetKPeriod(stoch.GetKPeriod()+1); stoch.SetDPeriod(stoch.GetDPeriod()+1); @@ -522,12 +522,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - WPR_Params params(14); - Indi_WPR *wpr = new Indi_WPR(params, iparams); + WPR_Params iparams(14); + Indi_WPR *wpr = new Indi_WPR(iparams, iparams); Print("WPR: ", wpr.GetValue()); delete wpr; -Example changing params: +Example changing iparams: wpr.SetPeriod(wpr.GetPeriod()+1); @@ -540,12 +540,12 @@ Example using a static call: Example usage: IndicatorParams iparams; - ZigZag_Params params(12, 5, 3); - Indi_ZigZag *zz = new Indi_ZigZag(params, iparams); + ZigZag_Params iparams(12, 5, 3); + Indi_ZigZag *zz = new Indi_ZigZag(iparams, iparams); Print("ZigZag: ", zz.GetValue()); delete zz; -Example changing params: +Example changing iparams: zz.SetDepth(zz.GetDepth()+1); zz.SetDeviation(zz.GetDeviation()+1); diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index a200b149d..2fefe648a 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -86,16 +86,13 @@ struct MathParams : IndicatorParams { /** * Implements the Volume Rate of Change indicator. */ -class Indi_Math : public Indicator { - protected: - MathParams params; - +class Indi_Math : public Indicator { public: /** * Class constructor. */ - Indi_Math(MathParams &_params) : Indicator((IndicatorParams)_params) { params = _params; }; - Indi_Math(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_SPECIAL_MATH, _tf) { params.tf = _tf; }; + Indi_Math(MathParams &_params) : Indicator(_params) { }; + Indi_Math(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_SPECIAL_MATH, _tf) { }; /** * Returns the indicator's value. @@ -103,9 +100,9 @@ class Indi_Math : public Indicator { double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_INDICATOR: - if (GetDataSource() == NULL) { + if (indi_src == NULL) { GetLogger().Error( "In order use custom indicator as a source, you need to select one using SetIndicatorData() method, " "which is a part of MathParams structure.", @@ -116,15 +113,15 @@ class Indi_Math : public Indicator { SetUserError(ERR_INVALID_PARAMETER); return _value; } - switch (params.op_mode) { + switch (iparams.op_mode) { case MATH_OP_MODE_BUILTIN: _value = Indi_Math::iMathOnIndicator( - GetDataSource(), Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), + indi_src, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), /*[*/ GetOpBuiltIn(), GetMode1(), GetMode2(), GetShift1(), GetShift2() /*]*/, 0, _shift, &this); break; case MATH_OP_MODE_CUSTOM_FUNCTION: _value = Indi_Math::iMathOnIndicator( - GetDataSource(), Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), + indi_src, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), /*[*/ GetOpFunction(), GetMode1(), GetMode2(), GetShift1(), GetShift2() /*]*/, 0, _shift, &this); break; } @@ -143,17 +140,17 @@ class Indi_Math : public Indicator { IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); unsigned int _position; - IndicatorDataEntry _entry(params.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); if (idata.KeyExists(_bar_time, _position)) { _entry = idata.GetByPos(_position); } else { _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)params.max_modes; _mode++) { + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType())); + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -169,17 +166,18 @@ class Indi_Math : public Indicator { return _param; } - static double iMathOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, ENUM_MATH_OP op, - unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, - unsigned int _shift_2, unsigned int _mode, int _shift, Indicator *_obj) { + static double iMathOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, + ENUM_MATH_OP op, unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, + unsigned int _shift_2, unsigned int _mode, int _shift, Indi_Math *_obj) { double _val_1 = _indi.GetValue(_shift_1, _mode_1); double _val_2 = _indi.GetValue(_shift_2, _mode_2); return Math::Op(op, _val_1, _val_2); } - static double iMathOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, MathCustomOpFunction _op, - unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, - unsigned int _shift_2, unsigned int _mode, int _shift, Indicator *_obj) { + static double iMathOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, + MathCustomOpFunction _op, unsigned int _mode_1, unsigned int _mode_2, + unsigned int _shift_1, unsigned int _shift_2, unsigned int _mode, int _shift, + Indi_Math *_obj) { double _val_1 = _indi.GetValue(_shift_1, _mode_1); double _val_2 = _indi.GetValue(_shift_2, _mode_2); return _op(_val_1, _val_2); @@ -190,32 +188,32 @@ class Indi_Math : public Indicator { /** * Get math operation. */ - ENUM_MATH_OP GetOpBuiltIn() { return params.op_builtin; } + ENUM_MATH_OP GetOpBuiltIn() { return iparams.op_builtin; } /** * Get math operation. */ - MathCustomOpFunction GetOpFunction() { return params.op_fn; } + MathCustomOpFunction GetOpFunction() { return iparams.op_fn; } /** * Get mode 1. */ - unsigned int GetMode1() { return params.mode_1; } + unsigned int GetMode1() { return iparams.mode_1; } /** * Get mode 2. */ - unsigned int GetMode2() { return params.mode_2; } + unsigned int GetMode2() { return iparams.mode_2; } /** * Get shift 1. */ - unsigned int GetShift1() { return params.shift_1; } + unsigned int GetShift1() { return iparams.shift_1; } /** * Get shift 2. */ - unsigned int GetShift2() { return params.shift_2; } + unsigned int GetShift2() { return iparams.shift_2; } /* Setters */ @@ -224,8 +222,8 @@ class Indi_Math : public Indicator { */ void SetOp(ENUM_MATH_OP _op) { istate.is_changed = true; - params.op_builtin = _op; - params.op_mode = MATH_OP_MODE_BUILTIN; + iparams.op_builtin = _op; + iparams.op_mode = MATH_OP_MODE_BUILTIN; } /** @@ -233,8 +231,8 @@ class Indi_Math : public Indicator { */ void SetOp(MathCustomOpFunction _op) { istate.is_changed = true; - params.op_fn = _op; - params.op_mode = MATH_OP_MODE_CUSTOM_FUNCTION; + iparams.op_fn = _op; + iparams.op_mode = MATH_OP_MODE_CUSTOM_FUNCTION; } /** @@ -242,7 +240,7 @@ class Indi_Math : public Indicator { */ void SetMode1(unsigned int _mode_1) { istate.is_changed = true; - params.mode_1 = _mode_1; + iparams.mode_1 = _mode_1; } /** @@ -250,7 +248,7 @@ class Indi_Math : public Indicator { */ void SetMode2(unsigned int _mode_2) { istate.is_changed = true; - params.mode_2 = _mode_2; + iparams.mode_2 = _mode_2; } /** @@ -258,7 +256,7 @@ class Indi_Math : public Indicator { */ void SetShift1(unsigned int _shift_1) { istate.is_changed = true; - params.shift_1 = _shift_1; + iparams.shift_1 = _shift_1; } /** @@ -266,7 +264,7 @@ class Indi_Math : public Indicator { */ void SetShift3(unsigned int _shift_2) { istate.is_changed = true; - params.shift_2 = _shift_2; + iparams.shift_2 = _shift_2; } /** diff --git a/Storage/ValueStorage.indicator.h b/Storage/ValueStorage.indicator.h index 56f133d0c..6f91599cf 100644 --- a/Storage/ValueStorage.indicator.h +++ b/Storage/ValueStorage.indicator.h @@ -36,10 +36,10 @@ /** * Storage for direct access to indicator's buffer for a given mode. */ -template +template class IndicatorBufferValueStorage : public HistoryValueStorage { // Pointer to indicator to access data from. - Indicator *indicator; + Indicator *indicator; // Mode of the target indicator. int mode; @@ -48,7 +48,7 @@ class IndicatorBufferValueStorage : public HistoryValueStorage { /** * Constructor. */ - IndicatorBufferValueStorage(Indicator *_indi, int _mode = 0, bool _is_series = false) + IndicatorBufferValueStorage(Indicator *_indi, int _mode = 0, bool _is_series = false) : indicator(_indi), mode(_mode), HistoryValueStorage(_indi.GetSymbol(), _indi.GetTf()) {} /** diff --git a/Strategy.mqh b/Strategy.mqh index 84af95675..7bf54dfbc 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -93,8 +93,8 @@ class Strategy : public Object { Dict ddata; Dict fdata; Dict idata; - Dict indicators_unmanaged; // Indicators list (unmanaged). - DictStruct> indicators_managed; // Indicators list (managed). + Dict *> indicators_unmanaged; // Indicators list (unmanaged). + DictStruct>> indicators_managed; // Indicators list (managed). DictStruct tasks; Log logger; // Log instance. MqlTick last_tick; @@ -159,7 +159,7 @@ class Strategy : public Object { * Class deconstructor. */ ~Strategy() { - for (DictIterator iter = indicators_unmanaged.Begin(); iter.IsValid(); ++iter) { + for (DictIterator *> iter = indicators_unmanaged.Begin(); iter.IsValid(); ++iter) { delete iter.Value(); } } @@ -308,7 +308,7 @@ class Strategy : public Object { /** * Returns handler to the strategy's indicator class. */ - Indicator *GetIndicator(int _id = 0) { + Indicator *GetIndicator(int _id = 0) { if (indicators_managed.KeyExists(_id)) { return indicators_managed[_id].Ptr(); } else if (indicators_unmanaged.KeyExists(_id)) { @@ -322,7 +322,7 @@ class Strategy : public Object { /** * Returns strategy's indicators. */ - DictStruct> GetIndicators() { return indicators_managed; } + DictStruct>> GetIndicators() { return indicators_managed; } /* Struct getters */ @@ -587,9 +587,10 @@ class Strategy : public Object { /** * Sets reference to indicator. */ - void SetIndicator(Indicator *_indi, int _id = 0, bool _managed = true) { + template + void SetIndicator(Indicator *_indi, int _id = 0, bool _managed = true) { if (_managed) { - Ref _ref = _indi; + Ref> _ref = _indi; indicators_managed.Set(_id, _ref); } else { indicators_unmanaged.Set(_id, _indi); @@ -1267,7 +1268,7 @@ class Strategy : public Object { int _count = (int)fmax(fabs(_level), fabs(_method)); int _direction = Order::OrderDirection(_cmd, _mode); Chart *_chart = trade.GetChart(); - Indicator *_indi = GetIndicator(); + Indicator *_indi = GetIndicator(); StrategyPriceStop _psm(_method); _psm.SetChartParams(_chart.GetParams()); if (Object::IsValid(_indi)) { From 3753c1f301ca2bc3929cddeba0a4f15438728ede Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Wed, 29 Sep 2021 18:53:24 +0200 Subject: [PATCH 17/78] WIP. Indicators' refactoring as Indicator is now a template class. Added IndicatorBase class. Most of the indicators under `indicators.h` now compiles. --- Draw.mqh | 1 + DrawIndicator.mqh | 7 +- Indicator.mqh | 532 +---------- Indicator.struct.h | 4 +- Indicator.struct.serialize.h | 1 - IndicatorBase.h | 1213 ++++++++++++++++++++++++ Indicators/Bitwise/Indi_Candle.mqh | 2 +- Indicators/Indi_AMA.mqh | 1 - Indicators/Indi_ASI.mqh | 2 +- Indicators/Indi_ATR.mqh | 1 + Indicators/Indi_Alligator.mqh | 1 + Indicators/Indi_AppliedPrice.mqh | 11 +- Indicators/Indi_CCI.mqh | 4 +- Indicators/Indi_ColorLine.mqh | 2 +- Indicators/Indi_DEMA.mqh | 11 +- Indicators/Indi_DeMarker.mqh | 1 + Indicators/Indi_Demo.mqh | 11 - Indicators/Indi_Drawer.mqh | 82 +- Indicators/Indi_Drawer.struct.h | 4 - Indicators/Indi_Momentum.mqh | 6 +- Indicators/Indi_Pattern.mqh | 2 +- Indicators/Indi_Pivot.mqh | 2 +- Indicators/Indi_Price.mqh | 3 +- Indicators/Indi_PriceFeeder.mqh | 5 +- Indicators/Indi_RS.mqh | 5 +- Indicators/Indi_RSI.mqh | 25 +- Indicators/Indi_SAR.mqh | 1 + Indicators/Indi_StdDev.mqh | 12 +- Indicators/Indi_UltimateOscillator.mqh | 6 +- Indicators/indicators.h | 10 +- Storage/ValueStorage.indicator.h | 9 +- tests/CompileIndicatorsTest.mq5 | 2 +- 32 files changed, 1367 insertions(+), 612 deletions(-) create mode 100644 IndicatorBase.h diff --git a/Draw.mqh b/Draw.mqh index bcfcfe647..350f89bf6 100644 --- a/Draw.mqh +++ b/Draw.mqh @@ -31,6 +31,7 @@ class Draw; // Includes. #include "Chart.mqh" +#include "Data.define.h" #ifndef __MQL4__ // Defines macros (for MQL4 backward compatibility). diff --git a/DrawIndicator.mqh b/DrawIndicator.mqh index 321bf04e0..7017a81eb 100644 --- a/DrawIndicator.mqh +++ b/DrawIndicator.mqh @@ -36,7 +36,7 @@ #include "Object.mqh" // Forward declaration. -class Indicator; +class IndicatorBase; class DrawPoint { public: @@ -52,12 +52,11 @@ class DrawPoint { DrawPoint(datetime _time = NULL, double _value = 0) : time(_time), value(_value) {} }; -template class DrawIndicator { protected: color color_line; Draw* draw; - Indicator* indi; + IndicatorBase* indi; public: // Object variables. @@ -68,7 +67,7 @@ class DrawIndicator { /** * Class constructor. */ - DrawIndicator(Indicator *_indi) : indi(_indi) { + DrawIndicator(IndicatorBase* _indi) : indi(_indi) { // color_line = Object::IsValid(_indi) ? _indi.GetParams().indi_color : clrRed; // @fixme draw = new Draw(); } diff --git a/Indicator.mqh b/Indicator.mqh index 12c8171e9..63af912a3 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -39,6 +39,7 @@ class Chart; #include "Indicator.struct.h" #include "Indicator.struct.serialize.h" #include "Indicator.struct.signal.h" +#include "IndicatorBase.h" #include "Math.h" #include "Object.mqh" #include "Refs.mqh" @@ -49,35 +50,13 @@ class Chart; #include "Storage/ValueStorage.indicator.h" #include "Storage/ValueStorage.native.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compatibility). -bool IndicatorBuffers(int _count) { return Indicator::SetIndicatorBuffers(_count); } -int IndicatorCounted(int _value = 0) { - static int prev_calculated = 0; - // https://docs.mql4.com/customind/indicatorcounted - prev_calculated = _value > 0 ? _value : prev_calculated; - return prev_calculated; -} -#endif - /** * Class to deal with indicators. */ template -class Indicator : public Chart { +class Indicator : public IndicatorBase { protected: // Structs. - BufferStruct idata; - DrawIndicator* draw; - IndicatorState istate; - void* mydata; - bool is_feeding; // Whether FeedHistoryEntries is already working. - bool is_fed; // Whether FeedHistoryEntries already done its job. - DictStruct> indicators; // Indicators list keyed by id. - bool indicator_builtin; - ARRAY(ValueStorage*, value_storages); - Indicator* indi_src; // // Indicator used as data source. - IndicatorCalculateCache cache; TS iparams; public: @@ -98,19 +77,19 @@ class Indicator : public Chart { /** * Class constructor. */ - Indicator() : indi_src(NULL) {} - Indicator(TS& _iparams) - : Chart(_iparams.GetTf()), draw(NULL), iparams(_iparams), is_feeding(false), is_fed(false), indi_src(NULL) { + // Indicator() : IndicatorBase() {} + Indicator(TS& _iparams) : IndicatorBase(_iparams.GetTf()) { + iparams = _iparams; SetName(_iparams.name != "" ? _iparams.name : EnumToString(iparams.itype)); Init(); } - Indicator(const TS& _iparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : Chart(_tf), draw(NULL), iparams(_iparams), is_feeding(false), is_fed(false), indi_src(NULL) { + Indicator(const TS& _iparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorBase(_tf) { + iparams = _iparams; SetName(_iparams.name != "" ? _iparams.name : EnumToString(iparams.itype)); Init(); } Indicator(ENUM_INDICATOR_TYPE _itype, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, string _name = "") - : Chart(_tf), draw(NULL), is_feeding(false), is_fed(false), indi_src(NULL) { + : IndicatorBase(_tf) { iparams.SetIndicatorType(_itype); iparams.SetShift(_shift); SetName(_name != "" ? _name : EnumToString(iparams.itype)); @@ -152,7 +131,7 @@ class Indicator : public Chart { */ bool InitDraw() { if (iparams.is_draw && !Object::IsValid(draw)) { - draw = new DrawIndicator(&this); + draw = new DrawIndicator(THIS_PTR); draw.SetColorLine(iparams.indi_color); } return iparams.is_draw; @@ -169,126 +148,6 @@ class Indicator : public Chart { } } - /* Defines MQL backward compatible methods */ - - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(DUMMY); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, int _mode, - int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, int _mode, - int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, - int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, - int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, - G _g, int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, - G _g, H _h, int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _h, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g COMMA _h); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, - G _g, H _h, I _i, int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _h, _i, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g COMMA _h COMMA _i); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, - G _g, H _h, I _i, J _j, int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g COMMA _h COMMA _i COMMA _j); -#endif - } - - template - double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, - G _g, H _h, I _i, J _j, K _k, int _mode, int _shift) { -#ifdef __MQL4__ - return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _mode, _shift); -#else // __MQL5__ - ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g COMMA _h COMMA _i COMMA _j COMMA _k); -#endif - } - /* Buffer methods */ virtual string CacheKey() { return GetName(); } @@ -465,7 +324,7 @@ class Indicator : public Chart { /** * Loads and validates built-in indicators whose can be used as data source. */ - void ValidateDataSource(Indicator* _target, Indicator* _source) { + void ValidateDataSource(IndicatorBase* _target, IndicatorBase* _source) { if (_target == NULL) { Alert("Internal Error! _target is NULL in ", __FUNCTION_LINE__, "."); DebugBreak(); @@ -483,19 +342,18 @@ class Indicator : public Chart { return; } - if (_source.iparams.max_modes > 1 && _target.GetDataSourceMode() == -1) { + if (_source.GetModeCount() > 1 && _target.GetDataSourceMode() == -1) { // Mode must be selected if source indicator has more that one mode. Alert("Warning! ", GetName(), " must select source indicator's mode via SetDataSourceMode(int). Defaulting to mode 0."); - _target.iparams.SetDataSourceMode(0); + _target.SetDataSourceMode(0); DebugBreak(); - } else if (_source.iparams.max_modes == 1 && _target.GetDataSourceMode() == -1) { - _target.iparams.SetDataSourceMode(0); - } else if (_target.GetDataSourceMode() < 0 || - (unsigned int)_target.GetDataSourceMode() > _source.iparams.max_modes) { + } else if (_source.GetModeCount() == 1 && _target.GetDataSourceMode() == -1) { + _target.SetDataSourceMode(0); + } else if (_target.GetDataSourceMode() < 0 || _target.GetDataSourceMode() > _source.GetModeCount()) { Alert("Error! ", _target.GetName(), " must select valid source indicator's mode via SetDataSourceMode(int) between 0 and ", - _source.iparams.GetMaxModes(), "."); + _source.GetModeCount(), "."); DebugBreak(); } } @@ -523,32 +381,34 @@ class Indicator : public Chart { /** * Provides built-in indicators whose can be used as data source. */ - virtual Indicator* FetchDataSource(ENUM_INDICATOR_TYPE _id) { return NULL; } + virtual IndicatorBase* FetchDataSource(ENUM_INDICATOR_TYPE _id) { return NULL; } - /** - * Whether data source is selected. - */ - bool HasDataSource() { return GetDataSource() != NULL || iparams.GetDataSourceId() != -1; } + /* Operator overloading methods */ /** - * Returns currently selected data source without any validation. + * Access indicator entry data using [] operator. */ - Indicator* GetDataSourceRaw() { return GetDataSource(); } + IndicatorDataEntry operator[](int _shift) { return GetEntry(_shift); } + IndicatorDataEntry operator[](ENUM_INDICATOR_INDEX _shift) { return GetEntry(_shift); } + IndicatorDataEntry operator[](datetime _dt) { return idata[_dt]; } + + /* Getters */ /** * Returns currently selected data source doing validation. */ - Indicator* GetDataSource() { - Indicator* _result = NULL; - if (GetDataSource() != NULL) { - _result = GetDataSource(); + IndicatorBase* GetDataSource() { + IndicatorBase* _result = NULL; + + if (GetDataSourceRaw() != NULL) { + _result = GetDataSourceRaw(); } else if (iparams.GetDataSourceId() != -1) { int _source_id = iparams.GetDataSourceId(); if (indicators.KeyExists(_source_id)) { _result = indicators[_source_id].Ptr(); } else { - Ref _source = FetchDataSource((ENUM_INDICATOR_TYPE)_source_id); + Ref _source = FetchDataSource((ENUM_INDICATOR_TYPE)_source_id); if (!_source.IsSet()) { Alert(GetName(), " has no built-in source indicator ", _source_id); @@ -565,296 +425,18 @@ class Indicator : public Chart { return _result; } - /* Operator overloading methods */ - - /** - * Access indicator entry data using [] operator. - */ - IndicatorDataEntry operator[](int _shift) { return GetEntry(_shift); } - IndicatorDataEntry operator[](ENUM_INDICATOR_INDEX _shift) { return GetEntry(_shift); } - IndicatorDataEntry operator[](datetime _dt) { return idata[_dt]; } - - /* Getters */ - - /** - * Returns buffers' cache. - */ - IndicatorCalculateCache* GetCache() { return &cache; } - - /** - * Gets an indicator's chart parameter value. - */ - template - T Get(ENUM_CHART_PARAM _param) { - return Chart::Get(_param); - } - /** - * Gets an indicator's state property value. + * Gets number of modes available to retrieve by GetValue(). */ - template - T Get(STRUCT_ENUM(IndicatorState, ENUM_INDICATOR_STATE_PROP) _prop) { - return istate.Get(_prop); - } + virtual int GetModeCount() { return 0; } /** - * Gets an indicator property flag. + * Whether data source is selected. */ - bool GetFlag(INDICATOR_ENTRY_FLAGS _prop, int _shift = 0) { - IndicatorDataEntry _entry = GetEntry(_shift); - return _entry.CheckFlag(_prop); - } + virtual bool HasDataSource() { return GetDataSourceRaw() != NULL || iparams.GetDataSourceId() != -1; } /* State methods */ - /** - * Checks for crossover. - * - * @return - * Returns true when values are crossing over, otherwise false. - */ - bool IsCrossover(int _shift1 = 0, int _shift2 = 1, int _mode1 = 0, int _mode2 = 0) { - double _curr_value1 = GetEntry(_shift1)[_mode1]; - double _prev_value1 = GetEntry(_shift2)[_mode1]; - double _curr_value2 = GetEntry(_shift1)[_mode2]; - double _prev_value2 = GetEntry(_shift2)[_mode2]; - return ((_curr_value1 > _prev_value1 && _curr_value2 < _prev_value2) || - (_prev_value1 > _curr_value1 && _prev_value2 < _curr_value2)); - } - - /** - * Checks if values are decreasing. - * - * @param int _rows - * Numbers of rows to check. - * @param int _mode - * Indicator index mode to check. - * @param int _shift - * Shift which is the final value to take into the account. - * - * @return - * Returns true when values are increasing. - */ - bool IsDecreasing(int _rows = 1, int _mode = 0, int _shift = 0) { - bool _result = true; - for (int i = _shift + _rows - 1; i >= _shift && _result; i--) { - IndicatorDataEntry _entry_curr = GetEntry(i); - IndicatorDataEntry _entry_prev = GetEntry(i + 1); - _result &= _entry_curr.IsValid() && _entry_prev.IsValid() && _entry_curr[_mode] < _entry_prev[_mode]; - if (!_result) { - break; - } - } - return _result; - } - - /** - * Checks if value decreased by the given percentage value. - * - * @param int _pct - * Percentage value to use for comparison. - * @param int _mode - * Indicator index mode to use. - * @param int _shift - * Indicator value shift to use. - * @param int _count - * Count of bars to compare change backward. - * @param int _hundreds - * When true, use percentage in hundreds, otherwise 1 is 100%. - * - * @return - * Returns true when value increased. - */ - bool IsDecByPct(float _pct, int _mode = 0, int _shift = 0, int _count = 1, bool _hundreds = true) { - bool _result = true; - IndicatorDataEntry _v0 = GetEntry(_shift); - IndicatorDataEntry _v1 = GetEntry(_shift + _count); - _result &= _v0.IsValid() && _v1.IsValid(); - _result &= _result && Math::ChangeInPct(_v1[_mode], _v0[_mode], _hundreds) < _pct; - return _result; - } - - /** - * Checks if values are increasing. - * - * @param int _rows - * Numbers of rows to check. - * @param int _mode - * Indicator index mode to check. - * @param int _shift - * Shift which is the final value to take into the account. - * - * @return - * Returns true when values are increasing. - */ - bool IsIncreasing(int _rows = 1, int _mode = 0, int _shift = 0) { - bool _result = true; - for (int i = _shift + _rows - 1; i >= _shift && _result; i--) { - IndicatorDataEntry _entry_curr = GetEntry(i); - IndicatorDataEntry _entry_prev = GetEntry(i + 1); - _result &= _entry_curr.IsValid() && _entry_prev.IsValid() && _entry_curr[_mode] > _entry_prev[_mode]; - if (!_result) { - break; - } - } - return _result; - } - - /** - * Checks if value increased by the given percentage value. - * - * @param int _pct - * Percentage value to use for comparison. - * @param int _mode - * Indicator index mode to use. - * @param int _shift - * Indicator value shift to use. - * @param int _count - * Count of bars to compare change backward. - * @param int _hundreds - * When true, use percentage in hundreds, otherwise 1 is 100%. - * - * @return - * Returns true when value increased. - */ - bool IsIncByPct(float _pct, int _mode = 0, int _shift = 0, int _count = 1, bool _hundreds = true) { - bool _result = true; - IndicatorDataEntry _v0 = GetEntry(_shift); - IndicatorDataEntry _v1 = GetEntry(_shift + _count); - _result &= _v0.IsValid() && _v1.IsValid(); - _result &= _result && Math::ChangeInPct(_v1[_mode], _v0[_mode], _hundreds) > _pct; - return _result; - } - - /* Getters */ - - int GetDataSourceMode() { return GetDataSourceMode(); } - - /** - * Returns the highest bar's index (shift). - */ - template - int GetHighest(int count = WHOLE_ARRAY, int start_bar = 0) { - int max_idx = -1; - double max = -DBL_MAX; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMax(iparams.max_modes); - if (value > max) { - max = value; - max_idx = shift; - } - } - - return max_idx; - } - - /** - * Returns the lowest bar's index (shift). - */ - template - int GetLowest(int count = WHOLE_ARRAY, int start_bar = 0) { - int min_idx = -1; - double min = DBL_MAX; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMin(iparams.max_modes); - if (value < min) { - min = value; - min_idx = shift; - } - } - - return min_idx; - } - - /** - * Returns the highest value. - */ - template - double GetMax(int start_bar = 0, int count = WHOLE_ARRAY) { - double max = NULL; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMax(iparams.max_modes); - if (max == NULL || value > max) { - max = value; - } - } - - return max; - } - - /** - * Returns the lowest value. - */ - template - double GetMin(int start_bar, int count = WHOLE_ARRAY) { - double min = NULL; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMin(iparams.max_modes); - if (min == NULL || value < min) { - min = value; - } - } - - return min; - } - - /** - * Returns average value. - */ - template - double GetAvg(int start_bar, int count = WHOLE_ARRAY) { - int num_values = 0; - double sum = 0; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value_min = GetEntry(shift).GetMin(iparams.max_modes); - double value_max = GetEntry(shift).GetMax(iparams.max_modes); - - sum += value_min + value_max; - num_values += 2; - } - - return sum / num_values; - } - - /** - * Returns median of values. - */ - template - double GetMed(int start_bar, int count = WHOLE_ARRAY) { - double array[]; - - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - int num_bars = last_bar - start_bar + 1; - int index = 0; - - ArrayResize(array, num_bars); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - array[index++] = GetEntry(shift).GetAvg(iparams.max_modes); - } - - ArraySort(array); - double median; - int len = ArraySize(array); - if (len % 2 == 0) { - median = (array[len / 2] + array[(len / 2) - 1]) / 2; - } else { - median = array[len / 2]; - } - - return median; - } - /** * Gets indicator's params. */ @@ -913,9 +495,7 @@ class Indicator : public Chart { */ string GetFullName() { return iparams.name + "[" + IntegerToString(iparams.GetMaxModes()) + "]" + - (HasDataSource() ? (" (over " + GetDataSource().GetName() + "[" + - IntegerToString(GetDataSource().GetParams().GetMaxModes()) + "])") - : ""); + (HasDataSource() ? (" (over " + GetDataSource().GetFullName() + ")") : ""); } /** @@ -1187,7 +767,7 @@ class Indicator : public Chart { ValueStorage* GetValueStorage(int _mode = 0) { if (value_storages[_mode] == NULL) { - value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); + value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); } return value_storages[_mode]; } @@ -1198,7 +778,8 @@ class Indicator : public Chart { template T GetValue(int _shift = 0, int _mode = -1) { T _result; - int _index = _mode != -1 ? _mode : iparams.indi_mode; + // @fixit We probably don't want to retrieve source mode from there. + int _index = _mode != -1 ? _mode : GetDataSourceMode(); GetEntry(_shift).values[_index].Get(_result); ResetLastError(); return _result; @@ -1276,8 +857,8 @@ class Indicator : public Chart { if (iparams.is_draw) { // Print("Drawing ", GetName(), iparams.indi_data != NULL ? (" (over " + iparams.indi_data.GetName() + ")") : ""); for (int i = 0; i < (int)iparams.max_modes; ++i) - draw.DrawLineTo(GetName() + "_" + IntegerToString(i) + "_" + IntegerToString(iparams.indi_mode), GetBarTime(0), - GetEntry(0)[i], iparams.draw_window); + draw.DrawLineTo(GetName() + "_" + IntegerToString(i) + "_" + IntegerToString(iparams.GetDataSourceMode()), + GetBarTime(0), GetEntry(0)[i], iparams.draw_window); } } @@ -1334,37 +915,4 @@ class Indicator : public Chart { } }; -/** - * BarsCalculated() method to be used on Indicator instance. - */ -/* -int BarsCalculated(Indicator* _indi, int _bars_required) { - if (_bars_required == 0) { - return _bars_required; - } - - IndicatorDataEntry _entry = _indi.GetEntry(_bars_required - 1); - // GetEntry() could end up with an error. It is okay. - ResetLastError(); - - int _valid_history_count = 0; - - if (!_entry.IsValid()) { - // We don't have sufficient data. Counting how much data we have. - - for (int i = 0; i < _bars_required; ++i) { - IndicatorDataEntry _check_entry = _indi.GetEntry(i); - if (!_check_entry.IsValid()) { - break; - } - ++_valid_history_count; - } - } else { - _valid_history_count = _bars_required; - } - - return _valid_history_count; -} -*/ - #endif diff --git a/Indicator.struct.h b/Indicator.struct.h index e1027704d..630ef9dd3 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -31,6 +31,7 @@ #endif // Forward declaration. +template class Indicator; struct ChartParams; @@ -369,7 +370,6 @@ struct IndicatorParams { int indi_data_source_mode; // Mode used as input from data source. bool indi_managed; // Whether indicator should be owned by indicator. ARRAY(DataParamEntry, input_params); // Indicator input params. - int indi_mode; // Index of indicator data to be used as data source. bool is_draw; // Draw active. int draw_window; // Drawing window. string custom_indi_name; // Name of the indicator passed to iCustom() method. @@ -389,7 +389,6 @@ struct IndicatorParams { itype(_itype), is_draw(false), indi_color(clrNONE), - indi_mode(0), draw_window(0) { SetDataSourceType(_idstype); Init(); @@ -406,7 +405,6 @@ struct IndicatorParams { indi_data_source_mode(0), is_draw(false), indi_color(clrNONE), - indi_mode(0), draw_window(0) { SetDataSourceType(_idstype); Init(); diff --git a/Indicator.struct.serialize.h b/Indicator.struct.serialize.h index 6c563f941..d7bd36a23 100644 --- a/Indicator.struct.serialize.h +++ b/Indicator.struct.serialize.h @@ -92,7 +92,6 @@ SerializerNodeType IndicatorParams::Serialize(Serializer &s) { // s.PassObject(this, "indicator", indi_data); // @todo // s.Pass(THIS_REF, "indi_data_ownership", indi_data_ownership); s.Pass(THIS_REF, "indi_color", indi_color, SERIALIZER_FIELD_FLAG_HIDDEN); - s.Pass(THIS_REF, "indi_mode", indi_mode); s.Pass(THIS_REF, "is_draw", is_draw); s.Pass(THIS_REF, "draw_window", draw_window, SERIALIZER_FIELD_FLAG_HIDDEN); s.Pass(THIS_REF, "custom_indi_name", custom_indi_name); diff --git a/IndicatorBase.h b/IndicatorBase.h new file mode 100644 index 000000000..157fd8281 --- /dev/null +++ b/IndicatorBase.h @@ -0,0 +1,1213 @@ +//+------------------------------------------------------------------+ +//| 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 . + * + */ + +/** + * @file + * Base interface for Indicator class. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Forward declaration. +class Chart; + +// Includes. +#include "Array.mqh" +#include "BufferStruct.mqh" +#include "Chart.mqh" +#include "DateTime.mqh" +#include "DrawIndicator.mqh" +#include "Indicator.define.h" +#include "Indicator.enum.h" +#include "Indicator.struct.cache.h" +#include "Indicator.struct.h" +#include "Indicator.struct.serialize.h" +#include "Indicator.struct.signal.h" +#include "Math.h" +#include "Object.mqh" +#include "Refs.mqh" +#include "Serializer.mqh" +#include "SerializerCsv.mqh" +#include "SerializerJson.mqh" +#include "Storage/ValueStorage.h" +#include "Storage/ValueStorage.indicator.h" +#include "Storage/ValueStorage.native.h" + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compatibility). +bool IndicatorBuffers(int _count) { return Indicator::SetIndicatorBuffers(_count); } +int IndicatorCounted(int _value = 0) { + static int prev_calculated = 0; + // https://docs.mql4.com/customind/indicatorcounted + prev_calculated = _value > 0 ? _value : prev_calculated; + return prev_calculated; +} +#endif + +/** + * Class to deal with indicators. + */ +class IndicatorBase : public Chart { + protected: + // Structs. + BufferStruct idata; + DrawIndicator* draw; + IndicatorState istate; + void* mydata; + bool is_feeding; // Whether FeedHistoryEntries is already working. + bool is_fed; // Whether FeedHistoryEntries already done its job. + DictStruct> indicators; // Indicators list keyed by id. + bool indicator_builtin; + ARRAY(ValueStorage*, value_storages); + IndicatorBase* indi_src; // // Indicator used as data source. + int indi_src_mode; // Mode of source indicator + IndicatorCalculateCache cache; + + public: + /* Indicator enumerations */ + + /* + * Default enumerations: + * + * ENUM_MA_METHOD values: + * 0: MODE_SMA (Simple averaging) + * 1: MODE_EMA (Exponential averaging) + * 2: MODE_SMMA (Smoothed averaging) + * 3: MODE_LWMA (Linear-weighted averaging) + */ + + /* Special methods */ + + /** + * Class constructor. + */ + IndicatorBase() { + is_feeding = is_fed = false; + indi_src = NULL; + } + + /** + * Class constructor. + */ + IndicatorBase(ChartParams& _cparams) : Chart(_cparams) { + is_feeding = is_fed = false; + indi_src = NULL; + } + + /** + * Class constructor. + */ + IndicatorBase(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL) : Chart(_tf, _symbol) { + is_feeding = is_fed = false; + indi_src = NULL; + } + + /** + * Class constructor. + */ + IndicatorBase(ENUM_TIMEFRAMES_INDEX _tfi, string _symbol = NULL) : Chart(_tfi, _symbol) { + is_feeding = is_fed = false; + indi_src = NULL; + } + + /** + * Class deconstructor. + */ + virtual ~IndicatorBase() { + ReleaseHandle(); + + for (int i = 0; i < ArraySize(value_storages); ++i) { + if (value_storages[i] != NULL) { + delete value_storages[i]; + } + } + } + + /* Defines MQL backward compatible methods */ + + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(DUMMY); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, int _mode, + int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, int _mode, + int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, + int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, + int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, + G _g, int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, + G _g, H _h, int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _h, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g COMMA _h); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, + G _g, H _h, I _i, int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _h, _i, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g COMMA _h COMMA _i); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, + G _g, H _h, I _i, J _j, int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g COMMA _h COMMA _i COMMA _j); +#endif + } + + template + double iCustom(int& _handle, string _symbol, ENUM_TIMEFRAMES _tf, string _name, A _a, B _b, C _c, D _d, E _e, F _f, + G _g, H _h, I _i, J _j, K _k, int _mode, int _shift) { +#ifdef __MQL4__ + return ::iCustom(_symbol, _tf, _name, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _mode, _shift); +#else // __MQL5__ + ICUSTOM_DEF(COMMA _a COMMA _b COMMA _c COMMA _d COMMA _e COMMA _f COMMA _g COMMA _h COMMA _i COMMA _j COMMA _k); +#endif + } + + /* Buffer methods */ + + virtual string CacheKey() { return GetName(); } + + /** + * Initializes a cached proxy between i*OnArray() methods and OnCalculate() + * used by custom indicators. + * + * Note that OnCalculateProxy() method sets incoming price array as not + * series. It will be reverted back by SetPrevCalculated(). It is because + * OnCalculate() methods assumes that prices are set as not series. + * + * For real example how you can use this method, look at + * Indi_MA::iMAOnArray() method. + * + * Usage: + * + * static double iFooOnArray(double &price[], int total, int period, + * int foo_shift, int foo_method, int shift, string cache_name = "") + * { + * if (cache_name != "") { + * String cache_key; + * cache_key.Add(cache_name); + * cache_key.Add(period); + * cache_key.Add(foo_method); + * + * Ref cache = Indicator::OnCalculateProxy(cache_key.ToString(), price, total); + * + * int prev_calculated = + * Indi_Foo::Calculate(total, cache.Ptr().prev_calculated, 0, price, cache.Ptr().buffer1, ma_method, period); + * + * cache.Ptr().SetPrevCalculated(price, prev_calculated); + * + * return cache.Ptr().GetValue(1, shift + ma_shift); + * } + * else { + * // Default iFooOnArray. + * } + * + * WARNING: Do not use shifts when creating cache_key, as this will create many invalid buffers. + */ + /* + static IndicatorCalculateCache OnCalculateProxy(string key, double& price[], int& total) { + if (total == 0) { + total = ArraySize(price); + } + + // Stores previously calculated value. + static DictStruct cache; + + unsigned int position; + IndicatorCalculateCache cache_item; + + if (cache.KeyExists(key, position)) { + cache_item = cache.GetByKey(key); + } else { + IndicatorCalculateCache cache_item_new(1, ArraySize(price)); + cache_item = cache_item_new; + cache.Set(key, cache_item); + } + + // Number of bars available in the chart. Same as length of the input `array`. + int rates_total = ArraySize(price); + + int begin = 0; + + cache_item.Resize(rates_total); + + cache_item.price_was_as_series = ArrayGetAsSeries(price); + ArraySetAsSeries(price, false); + + return cache_item; + } + */ + + /** + * Gets indicator data from a buffer and copy into struct array. + * + * @return + * Returns true of successful copy. + * Returns false on invalid values. + */ + bool CopyEntries(IndicatorDataEntry& _data[], int _count, int _start_shift = 0) { + bool _is_valid = true; + if (ArraySize(_data) < _count) { + _is_valid &= ArrayResize(_data, _count) > 0; + } + for (int i = 0; i < _count; i++) { + IndicatorDataEntry _entry = GetEntry(_start_shift + i); + _is_valid &= _entry.IsValid(); + _data[i] = _entry; + } + return _is_valid; + } + + /** + * Gets indicator data from a buffer and copy into array of values. + * + * @return + * Returns true of successful copy. + * Returns false on invalid values. + */ + template + bool CopyValues(T& _data[], int _count, int _start_shift = 0, int _mode = 0) { + bool _is_valid = true; + if (ArraySize(_data) < _count) { + _count = ArrayResize(_data, _count); + _count = _count > 0 ? _count : ArraySize(_data); + } + for (int i = 0; i < _count; i++) { + IndicatorDataEntry _entry = GetEntry(_start_shift + i); + _is_valid &= _entry.IsValid(); + _data[i] = (T)_entry[_mode]; + } + return _is_valid; + } + + /** + * Validates currently selected indicator used as data source. + */ + void ValidateSelectedDataSource() { + if (HasDataSource()) { + ValidateDataSource(THIS_PTR, GetDataSourceRaw()); + } + } + + /** + * Loads and validates built-in indicators whose can be used as data source. + */ + virtual void ValidateDataSource(IndicatorBase* _target, IndicatorBase* _source) {} + + /** + * Checks whether indicator have given mode index. + * + * If given mode is -1 (default one) and indicator has exactly one mode, then mode index will be replaced by 0. + */ + virtual void ValidateDataSourceMode(int& _out_mode) {} + + /** + * Provides built-in indicators whose can be used as data source. + */ + virtual IndicatorBase* FetchDataSource(ENUM_INDICATOR_TYPE _id) { return NULL; } + + /** + * Returns currently selected data source without any validation. + */ + IndicatorBase* GetDataSourceRaw() { return indi_src; } + + /* Operator overloading methods */ + + /** + * Access indicator entry data using [] operator. + */ + IndicatorDataEntry operator[](int _shift) { return GetEntry(_shift); } + IndicatorDataEntry operator[](ENUM_INDICATOR_INDEX _shift) { return GetEntry(_shift); } + IndicatorDataEntry operator[](datetime _dt) { return idata[_dt]; } + + /* Getters */ + + /** + * Returns buffers' cache. + */ + IndicatorCalculateCache* GetCache() { return &cache; } + + /** + * Gets an indicator's chart parameter value. + */ + template + T Get(ENUM_CHART_PARAM _param) { + return Chart::Get(_param); + } + + /** + * Gets an indicator's state property value. + */ + template + T Get(STRUCT_ENUM(IndicatorState, ENUM_INDICATOR_STATE_PROP) _prop) { + return istate.Get(_prop); + } + + /** + * Gets number of modes available to retrieve by GetValue(). + */ + virtual int GetModeCount() { return 0; } + + /** + * Gets an indicator property flag. + */ + bool GetFlag(INDICATOR_ENTRY_FLAGS _prop, int _shift = 0) { + IndicatorDataEntry _entry = GetEntry(_shift); + return _entry.CheckFlag(_prop); + } + + /* State methods */ + + /** + * Checks for crossover. + * + * @return + * Returns true when values are crossing over, otherwise false. + */ + bool IsCrossover(int _shift1 = 0, int _shift2 = 1, int _mode1 = 0, int _mode2 = 0) { + double _curr_value1 = GetEntry(_shift1)[_mode1]; + double _prev_value1 = GetEntry(_shift2)[_mode1]; + double _curr_value2 = GetEntry(_shift1)[_mode2]; + double _prev_value2 = GetEntry(_shift2)[_mode2]; + return ((_curr_value1 > _prev_value1 && _curr_value2 < _prev_value2) || + (_prev_value1 > _curr_value1 && _prev_value2 < _curr_value2)); + } + + /** + * Checks if values are decreasing. + * + * @param int _rows + * Numbers of rows to check. + * @param int _mode + * Indicator index mode to check. + * @param int _shift + * Shift which is the final value to take into the account. + * + * @return + * Returns true when values are increasing. + */ + bool IsDecreasing(int _rows = 1, int _mode = 0, int _shift = 0) { + bool _result = true; + for (int i = _shift + _rows - 1; i >= _shift && _result; i--) { + IndicatorDataEntry _entry_curr = GetEntry(i); + IndicatorDataEntry _entry_prev = GetEntry(i + 1); + _result &= _entry_curr.IsValid() && _entry_prev.IsValid() && _entry_curr[_mode] < _entry_prev[_mode]; + if (!_result) { + break; + } + } + return _result; + } + + /** + * Checks if value decreased by the given percentage value. + * + * @param int _pct + * Percentage value to use for comparison. + * @param int _mode + * Indicator index mode to use. + * @param int _shift + * Indicator value shift to use. + * @param int _count + * Count of bars to compare change backward. + * @param int _hundreds + * When true, use percentage in hundreds, otherwise 1 is 100%. + * + * @return + * Returns true when value increased. + */ + bool IsDecByPct(float _pct, int _mode = 0, int _shift = 0, int _count = 1, bool _hundreds = true) { + bool _result = true; + IndicatorDataEntry _v0 = GetEntry(_shift); + IndicatorDataEntry _v1 = GetEntry(_shift + _count); + _result &= _v0.IsValid() && _v1.IsValid(); + _result &= _result && Math::ChangeInPct(_v1[_mode], _v0[_mode], _hundreds) < _pct; + return _result; + } + + /** + * Checks if values are increasing. + * + * @param int _rows + * Numbers of rows to check. + * @param int _mode + * Indicator index mode to check. + * @param int _shift + * Shift which is the final value to take into the account. + * + * @return + * Returns true when values are increasing. + */ + bool IsIncreasing(int _rows = 1, int _mode = 0, int _shift = 0) { + bool _result = true; + for (int i = _shift + _rows - 1; i >= _shift && _result; i--) { + IndicatorDataEntry _entry_curr = GetEntry(i); + IndicatorDataEntry _entry_prev = GetEntry(i + 1); + _result &= _entry_curr.IsValid() && _entry_prev.IsValid() && _entry_curr[_mode] > _entry_prev[_mode]; + if (!_result) { + break; + } + } + return _result; + } + + /** + * Checks if value increased by the given percentage value. + * + * @param int _pct + * Percentage value to use for comparison. + * @param int _mode + * Indicator index mode to use. + * @param int _shift + * Indicator value shift to use. + * @param int _count + * Count of bars to compare change backward. + * @param int _hundreds + * When true, use percentage in hundreds, otherwise 1 is 100%. + * + * @return + * Returns true when value increased. + */ + bool IsIncByPct(float _pct, int _mode = 0, int _shift = 0, int _count = 1, bool _hundreds = true) { + bool _result = true; + IndicatorDataEntry _v0 = GetEntry(_shift); + IndicatorDataEntry _v1 = GetEntry(_shift + _count); + _result &= _v0.IsValid() && _v1.IsValid(); + _result &= _result && Math::ChangeInPct(_v1[_mode], _v0[_mode], _hundreds) > _pct; + return _result; + } + + /* Getters */ + + /** + * Returns currently selected data source doing validation. + */ + virtual IndicatorBase* GetDataSource() { return NULL; } + + int GetDataSourceMode() { return indi_src_mode; } + + /** + * Whether data source is selected. + */ + virtual bool HasDataSource() { return false; } + + /** + * Returns the highest bar's index (shift). + */ + template + int GetHighest(int count = WHOLE_ARRAY, int start_bar = 0) { + int max_idx = -1; + double max = -DBL_MAX; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value = GetEntry(shift).GetMax(GetModeCount()); + if (value > max) { + max = value; + max_idx = shift; + } + } + + return max_idx; + } + + /** + * Returns the lowest bar's index (shift). + */ + template + int GetLowest(int count = WHOLE_ARRAY, int start_bar = 0) { + int min_idx = -1; + double min = DBL_MAX; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value = GetEntry(shift).GetMin(GetModeCount()); + if (value < min) { + min = value; + min_idx = shift; + } + } + + return min_idx; + } + + /** + * Returns the highest value. + */ + template + double GetMax(int start_bar = 0, int count = WHOLE_ARRAY) { + double max = NULL; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value = GetEntry(shift).GetMax(iparams.max_modes); + if (max == NULL || value > max) { + max = value; + } + } + + return max; + } + + /** + * Returns the lowest value. + */ + template + double GetMin(int start_bar, int count = WHOLE_ARRAY) { + double min = NULL; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value = GetEntry(shift).GetMin(iparams.max_modes); + if (min == NULL || value < min) { + min = value; + } + } + + return min; + } + + /** + * Returns average value. + */ + template + double GetAvg(int start_bar, int count = WHOLE_ARRAY) { + int num_values = 0; + double sum = 0; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value_min = GetEntry(shift).GetMin(iparams.max_modes); + double value_max = GetEntry(shift).GetMax(iparams.max_modes); + + sum += value_min + value_max; + num_values += 2; + } + + return sum / num_values; + } + + /** + * Returns median of values. + */ + template + double GetMed(int start_bar, int count = WHOLE_ARRAY) { + double array[]; + + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + int num_bars = last_bar - start_bar + 1; + int index = 0; + + ArrayResize(array, num_bars); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + array[index++] = GetEntry(shift).GetAvg(iparams.max_modes); + } + + ArraySort(array); + double median; + int len = ArraySize(array); + if (len % 2 == 0) { + median = (array[len / 2] + array[(len / 2) - 1]) / 2; + } else { + median = array[len / 2]; + } + + return median; + } + + /** + * Gets indicator's symbol. + */ + string GetSymbol() { return Get(CHART_PARAM_SYMBOL); } + + /** + * Gets indicator's time-frame. + */ + ENUM_TIMEFRAMES GetTf() { return Get(CHART_PARAM_TF); } + + /** + * Gets indicator's signals. + * + * When indicator values are not valid, returns empty signals. + */ + virtual IndicatorSignal GetSignals(int _count = 3, int _shift = 0, int _mode1 = 0, int _mode2 = 0) { + IndicatorSignal _signal; + return _signal; + } + + /** + * Get indicator type. + */ + virtual ENUM_INDICATOR_TYPE GetType() { return INDI_NONE; } + + /** + * Get pointer to data of indicator. + */ + BufferStruct* GetData() { return GetPointer(idata); } + + /** + * Get data type of indicator. + */ + virtual ENUM_DATATYPE GetDataType() { return (ENUM_DATATYPE)-1; } + + /** + * Get name of the indicator. + */ + virtual string GetName() { return ""; } + + /** + * Get full name of the indicator (with "over ..." part). + */ + virtual string GetFullName() { return GetName(); } + + /** + * Get more descriptive name of the indicator. + */ + virtual string GetDescriptiveName() { return GetName(); } + + /* Setters */ + + /** + * Sets an indicator's chart parameter value. + */ + template + void Set(ENUM_CHART_PARAM _param, T _value) { + Chart::Set(_param, _value); + } + + /** + * Sets indicator data source. + */ + template + void SetDataSource(Indicator* _indi, bool _managed = true, int _input_mode = -1) { + indi_src = _indi; + iparams.SetDataSource(-1, _input_mode, _managed); + } + + /** + * Sets data source's input mode. + */ + void SetDataSourceMode(int _mode) { indi_src_mode = _mode; } + + /** + * Sets name of the indicator. + */ + virtual void SetName(string _name) {} + + /** + * Sets indicator's handle. + * + * Note: Not supported in MT4. + */ + virtual void SetHandle(int _handle) {} + + /** + * Sets indicator's symbol. + */ + void SetSymbol(string _symbol) { Set(CHART_PARAM_SYMBOL, _symbol); } + + /* Conditions */ + + /** + * Checks for indicator condition. + * + * @param ENUM_INDICATOR_CONDITION _cond + * Indicator condition. + * @param MqlParam[] _args + * Condition arguments. + * @return + * Returns true when the condition is met. + */ + bool CheckCondition(ENUM_INDICATOR_CONDITION _cond, DataParamEntry& _args[]) { + switch (_cond) { + case INDI_COND_ENTRY_IS_MAX: + // @todo: Add arguments, check if the entry value is max. + return false; + case INDI_COND_ENTRY_IS_MIN: + // @todo: Add arguments, check if the entry value is min. + return false; + case INDI_COND_ENTRY_GT_AVG: + // @todo: Add arguments, check if... + // Indicator entry value is greater than average. + return false; + case INDI_COND_ENTRY_GT_MED: + // @todo: Add arguments, check if... + // Indicator entry value is greater than median. + return false; + case INDI_COND_ENTRY_LT_AVG: + // @todo: Add arguments, check if... + // Indicator entry value is lesser than average. + return false; + case INDI_COND_ENTRY_LT_MED: + // @todo: Add arguments, check if... + // Indicator entry value is lesser than median. + return false; + default: + GetLogger().Error(StringFormat("Invalid indicator condition: %s!", EnumToString(_cond), __FUNCTION_LINE__)); + return false; + } + } + bool CheckCondition(ENUM_INDICATOR_CONDITION _cond) { + ARRAY(DataParamEntry, _args); + return IndicatorBase::CheckCondition(_cond, _args); + } + + /** + * Execute Indicator action. + * + * @param ENUM_INDICATOR_ACTION _action + * Indicator action to execute. + * @param MqlParam _args + * Indicator action arguments. + * @return + * Returns true when the action has been executed successfully. + */ + virtual bool ExecuteAction(ENUM_INDICATOR_ACTION _action, DataParamEntry& _args[]) { + bool _result = true; + long _arg1 = ArraySize(_args) > 0 ? DataParamEntry::ToInteger(_args[0]) : WRONG_VALUE; + switch (_action) { + case INDI_ACTION_CLEAR_CACHE: + _arg1 = _arg1 > 0 ? _arg1 : TimeCurrent(); + idata.Clear(_arg1); + return true; + default: + GetLogger().Error(StringFormat("Invalid Indicator action: %s!", EnumToString(_action), __FUNCTION_LINE__)); + return false; + } + return _result; + } + bool ExecuteAction(ENUM_INDICATOR_ACTION _action) { + ARRAY(DataParamEntry, _args); + return ExecuteAction(_action, _args); + } + bool ExecuteAction(ENUM_INDICATOR_ACTION _action, long _arg1) { + ARRAY(DataParamEntry, _args); + DataParamEntry _param1 = _arg1; + ArrayPushObject(_args, _param1); + _args[0].integer_value = _arg1; + return ExecuteAction(_action, _args); + } + + /* Other methods */ + + /** + * Releases indicator's handle. + * + * Note: Not supported in MT4. + */ + void ReleaseHandle() { +#ifdef __MQL5__ + if (istate.handle != INVALID_HANDLE) { + IndicatorRelease(istate.handle); + } +#endif + istate.handle = INVALID_HANDLE; + istate.is_changed = true; + } + + /** + * Checks whether indicator has a valid value for a given shift. + */ + virtual bool HasValidEntry(int _shift = 0) { + unsigned int position; + long bar_time = GetBarTime(_shift); + + if (idata.KeyExists(bar_time, position)) { + return idata.GetByPos(position).IsValid(); + } + + return false; + } + + /** + * Adds entry to the indicator's buffer. Invalid entry won't be added. + */ + bool AddEntry(IndicatorDataEntry& entry, int _shift = 0) { + if (!entry.IsValid()) return false; + + datetime timestamp = GetBarTime(_shift); + entry.timestamp = timestamp; + idata.Add(entry, timestamp); + + return true; + } + + /** + * Returns shift at which the last known valid entry exists for a given + * period (or from the start, when period is not specified). + */ + bool GetLastValidEntryShift(int& out_shift, int period = 0) { + out_shift = 0; + + while (true) { + if ((period != 0 && out_shift >= period) || !HasValidEntry(out_shift + 1)) + return out_shift > 0; // Current shift is always invalid. + + ++out_shift; + } + + return out_shift > 0; + } + + /** + * Returns shift at which the oldest known valid entry exists for a given + * period (or from the start, when period is not specified). + */ + bool GetOldestValidEntryShift(int& out_shift, int& out_num_valid, int shift = 0, int period = 0) { + bool found = false; + // Counting from previous up to previous - period. + for (out_shift = shift + 1; out_shift < shift + period + 1; ++out_shift) { + if (!HasValidEntry(out_shift)) { + --out_shift; + out_num_valid = out_shift - shift; + return found; + } else + found = true; + } + + --out_shift; + out_num_valid = out_shift - shift; + return found; + } + + /** + * Checks whether indicator has valid at least given number of last entries + * (counting from given shift or 0). + */ + bool HasAtLeastValidLastEntries(int period, int shift = 0) { + for (int i = 0; i < period; ++i) + if (!HasValidEntry(shift + i)) return false; + + return true; + } + + /** + * Feed history entries. + */ + void FeedHistoryEntries(int period, int shift = 0) { + if (is_feeding || is_fed) { + // Avoiding forever loop. + return; + } + + is_feeding = true; + + for (int i = shift + period; i > shift; --i) { + if (ChartStatic::iPrice(PRICE_OPEN, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), i) <= + 0) { + // No data for that entry + continue; + } + + GetEntry(i); + } + + is_feeding = false; + is_fed = true; + } + + ValueStorage* GetValueStorage(int _mode = 0) { + if (value_storages[_mode] == NULL) { + value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); + } + return value_storages[_mode]; + } + + /** + * Returns indicator value for a given shift and mode. + */ + template + T GetValue(int _shift = 0, int _mode = -1) { + T _result; + int _index = _mode != -1 ? _mode : GetDataSourceMode(); + GetEntry(_shift).values[_index].Get(_result); + ResetLastError(); + return _result; + } + + /** + * Returns price corresponding to indicator value for a given shift and mode. + * + * Can be useful for calculating trailing stops based on the indicator. + * + * @return + * Returns price value of the corresponding indicator values. + */ + template + float GetValuePrice(int _shift = 0, int _mode = 0, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL) { + float _price = 0; + if (iparams.GetIDataValueRange() != IDATA_RANGE_PRICE) { + _price = (float)GetPrice(_ap, _shift); + } else if (iparams.GetIDataValueRange() == IDATA_RANGE_PRICE) { + // When indicator values are the actual prices. + T _values[4]; + if (!CopyValues(_values, 4, _shift, _mode)) { + // When values aren't valid, return 0. + return _price; + } + datetime _bar_time = GetBarTime(_shift); + float _value = 0; + BarOHLC _ohlc(_values, _bar_time); + _price = _ohlc.GetAppliedPrice(_ap); + } + return _price; + } + + /** + * Returns values for a given shift. + * + * Note: Remember to check if shift exists by HasValidEntry(shift). + */ + template + bool GetValues(int _shift, T& _out1, T& _out2) { + IndicatorDataEntry _entry = GetEntry(_shift); + _out1 = _entry.values[0]; + _out2 = _entry.values[1]; + bool _result = GetLastError() != 4401; + ResetLastError(); + return _result; + } + + template + bool GetValues(int _shift, T& _out1, T& _out2, T& _out3) { + IndicatorDataEntry _entry = GetEntry(_shift); + _out1 = _entry.values[0]; + _out2 = _entry.values[1]; + _out3 = _entry.values[2]; + bool _result = GetLastError() != 4401; + ResetLastError(); + return _result; + } + + template + bool GetValues(int _shift, T& _out1, T& _out2, T& _out3, T& _out4) { + IndicatorDataEntry _entry = GetEntry(_shift); + _out1 = _entry.values[0]; + _out2 = _entry.values[1]; + _out3 = _entry.values[2]; + _out4 = _entry.values[3]; + bool _result = GetLastError() != 4401; + ResetLastError(); + return _result; + } + + virtual void OnTick() {} + + /* Data representation methods */ + + /* Virtual methods */ + + /** + * Returns stored data in human-readable format. + */ + // virtual bool ToString() = NULL; // @fixme? + + /** + * Whether we can and have to select mode when specifying data source. + */ + virtual bool IsDataSourceModeSelectable() { return true; } + + /** + * Update indicator. + */ + virtual bool Update() { + // @todo + return false; + }; + + /** + * Returns the indicator's struct value. + */ + virtual IndicatorDataEntry GetEntry(int _shift = 0) { + IndicatorDataEntry _entry; + return _entry; + }; + + /** + * Returns the indicator's entry value. + */ + virtual MqlParam GetEntryValue(int _shift = 0, int _mode = 0) { + MqlParam _param = {TYPE_FLOAT}; + _param.double_value = (float)GetEntry(_shift).GetValue(_mode); + return _param; + } + + /** + * Returns the indicator's value in plain format. + */ + virtual string ToString(int _shift = 0) { + IndicatorDataEntry _entry = GetEntry(_shift); + int _serializer_flags = + SERIALIZER_FLAG_SKIP_HIDDEN | SERIALIZER_FLAG_INCLUDE_DEFAULT | SERIALIZER_FLAG_INCLUDE_DYNAMIC; + SerializerConverter _stub_indi = + SerializerConverter::MakeStubObject(_serializer_flags, _entry.GetSize()); + return SerializerConverter::FromObject(_entry, _serializer_flags).ToString(0, &_stub_indi); + } +}; + +/** + * CopyBuffer() method to be used on Indicator instance with ValueStorage buffer. + * + * Note that data will be copied so that the oldest element will be located at the start of the physical memory + * allocated for the array + */ +template +int CopyBuffer(IndicatorBase* _indi, int _mode, int _start, int _count, ValueStorage& _buffer, int _rates_total) { + int _num_copied = 0; + int _buffer_size = ArraySize(_buffer); + + if (_buffer_size < _rates_total) { + _buffer_size = ArrayResize(_buffer, _rates_total); + } + + for (int i = _start; i < _count; ++i) { + IndicatorDataEntry _entry = _indi.GetEntry(i); + + if (!_entry.IsValid()) { + break; + } + + T _value = _entry.GetValue(_mode); + + // Print(_value); + + _buffer[_buffer_size - i - 1] = _value; + ++_num_copied; + } + + return _num_copied; +} + +/** + * BarsCalculated() method to be used on Indicator instance. + */ +int BarsCalculated(IndicatorBase* _indi, int _bars_required) { + if (_bars_required == 0) { + return _bars_required; + } + + IndicatorDataEntry _entry = _indi.GetEntry(_bars_required - 1); + // GetEntry() could end up with an error. It is okay. + ResetLastError(); + + int _valid_history_count = 0; + + if (!_entry.IsValid()) { + // We don't have sufficient data. Counting how much data we have. + + for (int i = 0; i < _bars_required; ++i) { + IndicatorDataEntry _check_entry = _indi.GetEntry(i); + if (!_check_entry.IsValid()) { + break; + } + ++_valid_history_count; + } + } else { + _valid_history_count = _bars_required; + } + + return _valid_history_count; +} diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index a9a15bc54..67e05527c 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -55,7 +55,7 @@ class Indi_Candle : public Indicator { /** * Class constructor. */ - Indi_Candle(CandleParams &_params) : iparams(_params), Indicator(_params){}; + Indi_Candle(CandleParams &_params) : Indicator(_params){}; Indi_Candle(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CANDLE, _tf) { iparams.tf = _tf; }; /** diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index 37048fbf5..60f7ffb79 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -47,7 +47,6 @@ struct IndiAMAParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); SetMaxModes(1); SetShift(_shift); - tf = _tf; switch (idstype) { case IDATA_ICUSTOM: if (custom_indi_name == "") { diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index f75b8c9a4..c3a737189 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -49,7 +49,7 @@ class Indi_ASI : public Indicator { /** * Class constructor. */ - Indi_ASI(ASIParams &_params) : iparams(_params.mpc), Indicator(_params){}; + Indi_ASI(ASIParams &_params) : Indicator(_params){}; Indi_ASI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ASI, _tf){}; /** diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index 7705e4822..79f6a8113 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -50,6 +50,7 @@ struct ATRParams : IndicatorParams { * Note: It doesn't give independent signals. It is used to define volatility (trend strength). */ class Indi_ATR : public Indicator { + public: /** * Class constructor. */ diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index a5d9cf847..20b3bce7a 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -93,6 +93,7 @@ struct AlligatorParams : IndicatorParams { * Implements the Alligator indicator. */ class Indi_Alligator : public Indicator { + public: /** * Class constructor. */ diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index 2a175e123..5cb963ab4 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -47,11 +47,10 @@ class Indi_AppliedPrice : public Indicator { /** * Class constructor. */ - Indi_AppliedPrice(AppliedPriceParams &_params) : iparams(_params), Indicator(_params){}; - Indi_AppliedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : iparams(PRICE_OPEN, 0, _tf), Indicator(INDI_PRICE, _tf){}; + Indi_AppliedPrice(AppliedPriceParams &_params) : Indicator(_params){}; + Indi_AppliedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE, _tf){}; - static double iAppliedPriceOnIndicator(Indicator *_indi, ENUM_APPLIED_PRICE _applied_price, - int _shift = 0) { + static double iAppliedPriceOnIndicator(IndicatorBase *_indi, ENUM_APPLIED_PRICE _applied_price, int _shift = 0) { double _ohlc[4]; _indi[_shift].GetArray(_ohlc, 4); return BarOHLC::GetAppliedPrice(_applied_price, _ohlc[0], _ohlc[1], _ohlc[2], _ohlc[3]); @@ -70,10 +69,14 @@ class Indi_AppliedPrice : public Indicator { // (e.g. for applied price of Indi_Price). iparams.SetDataSourceMode(GetAppliedPrice()); } + + // @fixit + /* if (indi_src.GetParams().GetMaxModes() != 4) { Print("Indi_AppliedPrice indicator requires that has at least 4 modes/buffers (OHLC)!"); DebugBreak(); } + */ _value = Indi_AppliedPrice::iAppliedPriceOnIndicator(indi_src, GetAppliedPrice(), _shift); break; default: diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 84b97a4c1..0d769b2fc 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -104,12 +104,12 @@ class Indi_CCI : public Indicator { #endif } - static double iCCIOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, + static double iCCIOnIndicator(IndicatorBase *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _mode, int _shift = 0) { _indi.ValidateDataSourceMode(_mode); double _indi_value_buffer[]; - IndicatorDataEntry _entry(_indi.GetParams().GetMaxModes()); + IndicatorDataEntry _entry(_indi.GetModeCount()); ArrayResize(_indi_value_buffer, _period); diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 7797320d0..c9d8ae052 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -65,7 +65,7 @@ class Indi_ColorLine : public Indicator { * Calculates Color Line on the array of values. */ static double iColorLineOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _shift, - IndicatorCalculateCache *_cache, Indi_ColorLine *_indi_ma, + IndicatorCalculateCache *_cache, IndicatorBase *_indi_ma, bool _recalculate = false) { _cache.SetPriceBuffer(_open, _high, _low, _close); diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 20c3df897..012e4add6 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -49,7 +49,6 @@ struct DEMAParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); SetMaxModes(1); SetShift(_shift); - tf = _tf; switch (idstype) { case IDATA_ICUSTOM: if (custom_indi_name == "") { @@ -127,8 +126,7 @@ class Indi_DEMA : public Indicator { #endif } - template - static double iDEMAOnIndicator(IndicatorCalculateCache *cache, Indicator *indi, int indi_mode, + static double iDEMAOnIndicator(IndicatorCalculateCache *cache, IndicatorBase *indi, int indi_mode, unsigned int ma_period, unsigned int ma_shift, int shift) { return iDEMAOnArray(indi.GetValueStorage(indi_mode), 0, ma_period, ma_shift, shift, cache); } @@ -179,9 +177,6 @@ class Indi_DEMA : public Indicator { return (rates_total); } - /** - - /** * Returns the indicator's value. */ @@ -204,8 +199,8 @@ class Indi_DEMA : public Indicator { break; case IDATA_INDICATOR: // Calculating DEMA value from specified indicator. - _value = - Indi_DEMA::iDEMAOnIndicator(GetCache(), indi_src, GetDataSourceMode(), GetPeriod(), GetMAShift(), _shift); + _value = Indi_DEMA::iDEMAOnIndicator(GetCache(), GetDataSource(), GetDataSourceMode(), GetPeriod(), + GetMAShift(), _shift); break; } istate.is_ready = _LastError == ERR_NO_ERROR; diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index 68ff11c55..5da4c8a7e 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -49,6 +49,7 @@ struct DeMarkerParams : IndicatorParams { * Implements the DeMarker indicator. */ class Indi_DeMarker : public Indicator { + public: /** * Class constructor. */ diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index a8bfff36f..8df3b9606 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -40,7 +40,6 @@ struct DemoIndiParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetMaxModes(1); SetShift(_shift); - tf = _tf; switch (idstype) { case IDATA_ICUSTOM: if (custom_indi_name == "") { @@ -74,16 +73,6 @@ class Indi_Demo : public Indicator { Indi_Demo(DemoIndiParams &_params) : Indicator(_params){}; Indi_Demo(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DEMO, _tf){}; - /** - * Initialize indicator data drawing on custom data. - */ - bool InitDraw() { - if (iparams.is_draw) { - draw = new DrawIndicator(&this); - } - return iparams.is_draw; - } - /** * Returns the indicator value. */ diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index b8ee1031d..27059651d 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -44,6 +44,7 @@ double iDrawer(string _symbol, int _tf, int _period, int _ap, int _shift) { class Indi_Drawer : public Indicator { Redis redis; + public: /** * Class constructor. */ @@ -152,8 +153,7 @@ class Indi_Drawer : public Indicator { * - https://www.mql5.com/en/docs/indicators/irsi */ static double iDrawer(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, - ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, - Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, IndicatorBase *_obj = NULL) { return 1.0; } @@ -171,7 +171,7 @@ class Indi_Drawer : public Indicator { double result; for (i = _shift; i < (int)_shift + (int)_period; i++) { - indi_values[_shift + _period - (i - _shift) - 1] = _indi[i][_obj.GetParams().indi_mode]; + indi_values[_shift + _period - (i - _shift) - 1] = _indi[i][_obj.GetDataSourceMode()]; } result = iDrawerOnArray(indi_values, 0, _period - 1, 0); @@ -194,7 +194,7 @@ class Indi_Drawer : public Indicator { * Drawer values. To exactly replicate our Drawer numbers, a formula will need at * least 250 data points." */ - static double iDrawerOnIndicator(Indicator *_indi, Indi_Drawer *_obj, string _symbol = NULL, + static double iDrawerOnIndicator(IndicatorBase *_indi, Indi_Drawer *_obj, string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0) { long _bar_time_curr = _obj.GetBarTime(_shift); @@ -206,7 +206,7 @@ class Indi_Drawer : public Indicator { // Looks like MT uses specified period as start of the SMMA calculations. _obj.FeedHistoryEntries(_period); - int i; + // int i; double indi_values[]; ArrayResize(indi_values, _period); @@ -214,40 +214,43 @@ class Indi_Drawer : public Indicator { // SMMA-based version of Drawer. DrawerGainLossData last_data, new_data; - unsigned int data_position; + // unsigned int data_position; double diff; - int _mode = _obj.GetParams().indi_mode; - - if (!_obj.aux_data.KeyExists(_bar_time_prev, data_position)) { - // No previous SMMA-based average gain and loss. Calculating SMA-based ones. - double sum_gain = 0; - double sum_loss = 0; + int _mode = _obj.GetDataSourceMode(); - for (i = 1; i < (int)_period; i++) { - double price_new = _indi[(_shift + 1) + i - 1][_mode]; - double price_old = _indi[(_shift + 1) + i][_mode]; - - if (price_new == 0.0 || price_old == 0.0) { - // Missing history price data, skipping calculations. - return 0.0; - } - - diff = price_new - price_old; - - if (diff > 0) { - sum_gain += diff; + /* + @fixit + if (!_obj.aux_data.KeyExists(_bar_time_prev, data_position)) { + // No previous SMMA-based average gain and loss. Calculating SMA-based ones. + double sum_gain = 0; + double sum_loss = 0; + + for (i = 1; i < (int)_period; i++) { + double price_new = _indi[(_shift + 1) + i - 1][_mode]; + double price_old = _indi[(_shift + 1) + i][_mode]; + + if (price_new == 0.0 || price_old == 0.0) { + // Missing history price data, skipping calculations. + return 0.0; + } + + diff = price_new - price_old; + + if (diff > 0) { + sum_gain += diff; + } else { + sum_loss += -diff; + } + } + + // Calculating SMA-based values. + last_data.avg_gain = sum_gain / _period; + last_data.avg_loss = sum_loss / _period; } else { - sum_loss += -diff; + // Data already exists, retrieving it by position got by KeyExists(). + last_data = _obj.aux_data.GetByPos(data_position); } - } - - // Calculating SMA-based values. - last_data.avg_gain = sum_gain / _period; - last_data.avg_loss = sum_loss / _period; - } else { - // Data already exists, retrieving it by position got by KeyExists(). - last_data = _obj.aux_data.GetByPos(data_position); - } + */ diff = _indi[_shift][_mode] - _indi[_shift + 1][_mode]; @@ -262,7 +265,10 @@ class Indi_Drawer : public Indicator { new_data.avg_gain = (last_data.avg_gain * (_period - 1) + curr_gain) / _period; new_data.avg_loss = (last_data.avg_loss * (_period - 1) + curr_loss) / _period; - _obj.aux_data.Set(_bar_time_curr, new_data); + /* + @fixit + _obj.aux_data.Set(_bar_time_curr, new_data); + */ if (new_data.avg_loss == 0.0) // @fixme Why 0 loss? @@ -309,7 +315,7 @@ class Indi_Drawer : public Indicator { GetAppliedPrice() /* ] */, 0, _shift); break; case IDATA_INDICATOR: - _value = Indi_Drawer::iDrawerOnIndicator(iparams.indi_data_source, THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), + _value = Indi_Drawer::iDrawerOnIndicator(GetDataSource(), THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _shift); break; } @@ -321,7 +327,7 @@ class Indi_Drawer : public Indicator { * Returns the indicator's struct value. */ IndicatorDataEntry GetEntry(int _shift = 0) { - unsigned int i; + int i; long _bar_time = GetBarTime(_shift); unsigned int _position; IndicatorDataEntry _entry(iparams.GetMaxModes()); diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index e927dff0b..7e27de388 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -44,10 +44,6 @@ struct DrawerParams : IndicatorParams { void DrawerParams(DrawerParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { this = _params; tf = _tf; - if (idstype == IDATA_INDICATOR && indi_data_source == NULL) { - PriceIndiParams price_params(_tf); - SetDataSource(new Indi_Price(price_params), true); - } }; // Serializers. SERIALIZER_EMPTY_STUB; diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 7928b7266..731295f68 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -108,10 +108,10 @@ class Indi_Momentum : public Indicator { #endif } - static double iMomentumOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, - unsigned int _period, int _mode, int _shift = 0) { + static double iMomentumOnIndicator(IndicatorBase *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, + int _mode, int _shift = 0) { double _indi_value_buffer[]; - IndicatorDataEntry _entry(_indi.GetParams().GetMaxModes()); + IndicatorDataEntry _entry(_indi.GetModeCount()); _period += 1; diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index 44afb06d8..145b7ce31 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -49,7 +49,7 @@ class Indi_Pattern : public Indicator { /** * Class constructor. */ - Indi_Pattern(IndiPatternParams &_params) : iparams(_params), Indicator(_params){}; + Indi_Pattern(IndiPatternParams &_params) : Indicator(_params){}; Indi_Pattern(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PATTERN, _tf) { iparams.tf = _tf; }; /** diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index 373ac9f6e..2d4cb411b 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -48,7 +48,7 @@ class Indi_Pivot : public Indicator { /** * Class constructor. */ - Indi_Pivot(IndiPivotParams &_params) : iparams(_params), Indicator(_params){}; + Indi_Pivot(IndiPivotParams &_params) : Indicator(_params){}; Indi_Pivot(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PIVOT, _tf) { iparams.tf = _tf; }; /** diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index c605dde5c..242603a23 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -130,7 +130,8 @@ class Indi_Price : public Indicator { Indi_Price *_indi_price; if (!Objects::TryGet(_key, _indi_price)) { PriceIndiParams _indi_price_params(_shift, _applied_price); - _indi_price = Objects::Set(_key, new Indi_Price(_indi_price_params, _tf)); + _indi_price_params.SetTf(_tf); + _indi_price = Objects::Set(_key, new Indi_Price(_indi_price_params)); _indi_price.SetSymbol(_symbol); } return _indi_price; diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index 6c2f03389..ad4d37cf4 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -62,8 +62,9 @@ class Indi_PriceFeeder : public Indicator { * Class constructor. */ Indi_PriceFeeder(PriceFeederIndiParams& _p) : Indicator(_p){}; - Indi_PriceFeeder(const double& _price_data[], int _total = 0) - : iparams(_price_data, _total), Indicator(INDI_PRICE_FEEDER){}; + Indi_PriceFeeder(const double& _price_data[], int _total = 0) : Indicator(INDI_PRICE_FEEDER) { + ArrayCopy(iparams.price_data, _price_data); + }; void SetPrices(const double& _price_data[], int _total = 0) { iparams = PriceFeederIndiParams(_price_data, _total); } diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index d2f538907..140f05ea9 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -51,13 +51,14 @@ class Indi_RS : public Indicator { /** * Class constructor. */ - Indi_RS(RSParams &_params) : iparams(_params), Indicator(_params) { Init(); }; + Indi_RS(RSParams &_params) : Indicator(_params) { Init(); }; Indi_RS(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RS, _tf) { Init(); }; void Init() { if (iparams.GetDataSourceType() == IDATA_MATH) { PriceIndiParams _iprice_params(); - iprice = new Indi_Price(_iprice_params); + // @fixit + Indi_Price *_iprice_close = Indi_Price::GetCached(NULL, 0, /*unused*/ PRICE_CLOSE, 0); MathParams _imath0_params(MATH_OP_SUB, PRICE_CLOSE, 0, PRICE_CLOSE, 1); _imath0_params.SetDataSource(iprice.Ptr(), false); diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index 9db1318b2..b8233bf0f 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -44,18 +44,18 @@ double iRSIOnArray(double &_arr[], int _total, int _period, int _shift) { // Structs. struct RSIParams : IndicatorParams { protected: - unsigned int period; + int period; ENUM_APPLIED_PRICE applied_price; public: - void RSIParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), applied_price(_ap) { + void RSIParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : applied_price(_ap) { itype = INDI_RSI; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\RSI"); + SetPeriod(_period); }; void RSIParams(RSIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { this = _params; @@ -63,9 +63,9 @@ struct RSIParams : IndicatorParams { }; // Getters. ENUM_APPLIED_PRICE GetAppliedPrice() { return applied_price; } - unsigned int GetPeriod() { return period; } + int GetPeriod() { return period; } // Setters. - void SetPeriod(unsigned int _period) { period = _period; } + void SetPeriod(int _period) { period = _period; } void SetAppliedPrice(ENUM_APPLIED_PRICE _ap) { applied_price = _ap; } // Serializers. SERIALIZER_EMPTY_STUB; @@ -176,8 +176,7 @@ class Indi_RSI : public Indicator { * RSI values. To exactly replicate our RSI numbers, a formula will need at * least 250 data points." */ - template - static double iRSIOnIndicator(Indicator *_indi, Indi_RSI *_obj, string _symbol = NULL, + static double iRSIOnIndicator(IndicatorBase *_indi, Indi_RSI *_obj, string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0) { long _bar_time_curr = _obj.GetBarTime(_shift); @@ -199,7 +198,7 @@ class Indi_RSI : public Indicator { RSIGainLossData last_data, new_data; unsigned int data_position; double diff; - int _mode = _obj.GetParams().indi_mode; + int _mode = _obj.GetDataSourceMode(); if (!_obj.aux_data.KeyExists(_bar_time_prev, data_position)) { // No previous SMMA-based average gain and loss. Calculating SMA-based ones. @@ -320,16 +319,16 @@ class Indi_RSI : public Indicator { switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_RSI::iRSI(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _shift, THIS_PTR); + _value = Indi_RSI::iRSI(GetSymbol(), GetTf(), iparams.GetPeriod(), iparams.GetAppliedPrice(), _shift, THIS_PTR); break; case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, /* [ */ GetPeriod(), - GetAppliedPrice() /* ] */, 0, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, /* [ */ iparams.GetPeriod(), + iparams.GetAppliedPrice() /* ] */, 0, _shift); break; case IDATA_INDICATOR: - _value = Indi_RSI::iRSIOnIndicator(GetDataSource(), THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), - GetAppliedPrice(), _shift); + _value = Indi_RSI::iRSIOnIndicator(GetDataSource(), THIS_PTR, GetSymbol(), GetTf(), iparams.GetPeriod(), + iparams.GetAppliedPrice(), _shift); break; } istate.is_ready = GetLastError() == ERR_NO_ERROR; diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 24453a37e..01efb5cde 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -110,6 +110,7 @@ class Indi_SAR : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetStep(), + GetMax() /*]*/, _mode, _shift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index 6999f26fb..bf4a0fc28 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -117,14 +117,13 @@ class Indi_StdDev : public Indicator { /** * Note that this method operates on current price (set by _applied_price). */ - template - static double iStdDevOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, + static double iStdDevOnIndicator(IndicatorBase *_indi, string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, Indi_StdDev *_obj = NULL) { double _indi_value_buffer[]; double _std_dev; int i; - int _mode = _obj != NULL ? _obj.GetParams().indi_mode : 0; + int _mode = _obj != NULL ? _obj.GetDataSourceMode() : 0; ArrayResize(_indi_value_buffer, _ma_period); @@ -198,10 +197,11 @@ class Indi_StdDev : public Indicator { Indi_PriceFeeder indi_price_feeder(price); MAParams ma_params(period, 0, ma_method, PRICE_OPEN); - ma_params.SetDataSource(&indi_price_feeder, false, 0); // Using first and only mode from price feeder. - Indi_MA indi_ma(ma_params); + Indi_MA *_indi_ma = + Indi_MA::GetCached("Indi_StdDev:Unbuffered", (ENUM_TIMEFRAMES)-1, period, 0, ma_method, (ENUM_APPLIED_PRICE)-1); + _indi_ma.SetDataSource(&indi_price_feeder, false, 0); // Using first and only mode from price feeder. - return iStdDevOnIndicator(&indi_ma, NULL, NULL, period, 0, PRICE_OPEN, /*unused*/ 0); + return iStdDevOnIndicator(_indi_ma, NULL, NULL, period, 0, PRICE_OPEN, /*unused*/ 0); } /** diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index fbb9f2db3..7efa85686 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -74,9 +74,9 @@ class Indi_UltimateOscillator : public Indicator { Util::MakeKey("Indi_UltimateOscillator", _fast_period, _middle_period, _slow_period, _fast_k, _middle_k, _slow_k)); - Indicator *_indi_atr_fast = Indi_ATR::GetCached(_symbol, _tf, _fast_period); - Indicator *_indi_atr_middle = Indi_ATR::GetCached(_symbol, _tf, _middle_period); - Indicator *_indi_atr_slow = Indi_ATR::GetCached(_symbol, _tf, _slow_period); + IndicatorBase *_indi_atr_fast = Indi_ATR::GetCached(_symbol, _tf, _fast_period); + IndicatorBase *_indi_atr_middle = Indi_ATR::GetCached(_symbol, _tf, _middle_period); + IndicatorBase *_indi_atr_slow = Indi_ATR::GetCached(_symbol, _tf, _slow_period); return iUOOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _fast_period, _middle_period, _slow_period, _fast_k, _middle_k, _slow_k, _mode, _shift, _cache, _indi_atr_fast, _indi_atr_middle, _indi_atr_slow); diff --git a/Indicators/indicators.h b/Indicators/indicators.h index d6325d453..6f21660f0 100644 --- a/Indicators/indicators.h +++ b/Indicators/indicators.h @@ -32,13 +32,13 @@ #include "Indi_ADXW.mqh" #include "Indi_AMA.mqh" #include "Indi_AO.mqh" -#include "Indi_Alligator.mqh" -#include "Indi_AppliedPrice.mqh" #include "Indi_ASI.mqh" #include "Indi_ATR.mqh" +#include "Indi_Alligator.mqh" +#include "Indi_AppliedPrice.mqh" #include "Indi_BWMFI.mqh" #include "Indi_BWZT.mqh" -#include "Indi_Bands.mqh" +//#include "Indi_Bands.mqh" #include "Indi_BearsPower.mqh" #include "Indi_BullsPower.mqh" #include "Indi_CCI.mqh" @@ -73,8 +73,8 @@ #include "Indi_PriceChannel.mqh" #include "Indi_PriceFeeder.mqh" #include "Indi_PriceVolumeTrend.mqh" -#include "Indi_RS.mqh" -#include "Indi_RSI.mqh" +//#include "Indi_RS.mqh" +//#include "Indi_RSI.mqh" #include "Indi_RVI.mqh" #include "Indi_RateOfChange.mqh" #include "Indi_SAR.mqh" diff --git a/Storage/ValueStorage.indicator.h b/Storage/ValueStorage.indicator.h index 6f91599cf..4dc6aacb0 100644 --- a/Storage/ValueStorage.indicator.h +++ b/Storage/ValueStorage.indicator.h @@ -30,16 +30,19 @@ #pragma once #endif +// Forward declarations. +class IndicatorBase; + // Includes. #include "ValueStorage.history.h" /** * Storage for direct access to indicator's buffer for a given mode. */ -template +template class IndicatorBufferValueStorage : public HistoryValueStorage { // Pointer to indicator to access data from. - Indicator *indicator; + IndicatorBase *indicator; // Mode of the target indicator. int mode; @@ -48,7 +51,7 @@ class IndicatorBufferValueStorage : public HistoryValueStorage { /** * Constructor. */ - IndicatorBufferValueStorage(Indicator *_indi, int _mode = 0, bool _is_series = false) + IndicatorBufferValueStorage(IndicatorBase *_indi, int _mode = 0, bool _is_series = false) : indicator(_indi), mode(_mode), HistoryValueStorage(_indi.GetSymbol(), _indi.GetTf()) {} /** diff --git a/tests/CompileIndicatorsTest.mq5 b/tests/CompileIndicatorsTest.mq5 index b772bc476..4d0b149bd 100644 --- a/tests/CompileIndicatorsTest.mq5 +++ b/tests/CompileIndicatorsTest.mq5 @@ -30,4 +30,4 @@ /** * Implements Init event handler. */ -int OnInit() { return (_LastError == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED); } +int OnInit() { return 0; } From 3f3cdd2c34ecb181373929aa6c9b6fc9baeb9cb6 Mon Sep 17 00:00:00 2001 From: kenorb Date: Wed, 29 Sep 2021 22:14:13 +0100 Subject: [PATCH 18/78] Trade: Adds TradeSignal class and tests --- .github/workflows/test.yml | 20 +++ Trade/TradeSignal.h | 123 ++++++++++++++ Trade/TradeSignal.struct.h | 190 +++++++++++++++++++++ Trade/tests/TradeSignalTest.mq4 | 28 +++ Trade/tests/TradeSignalTest.mq5 | 291 ++++++++++++++++++++++++++++++++ 5 files changed, 652 insertions(+) create mode 100644 Trade/TradeSignal.h create mode 100644 Trade/TradeSignal.struct.h create mode 100644 Trade/tests/TradeSignalTest.mq4 create mode 100644 Trade/tests/TradeSignalTest.mq5 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be1bba5ff..ef6d94273 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -235,3 +235,23 @@ jobs: with: Script: ${{ matrix.test }} RunOnFail: "exit 0" + + Trade-Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Trade/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - TradeSignalTest + steps: + - uses: actions/download-artifact@v2 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} diff --git a/Trade/TradeSignal.h b/Trade/TradeSignal.h new file mode 100644 index 000000000..a84caef5a --- /dev/null +++ b/Trade/TradeSignal.h @@ -0,0 +1,123 @@ +//+------------------------------------------------------------------+ +//| 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 . + * + */ + +// Includes. +#include "TradeSignal.struct.h" + +/** + * @file + * Implements TradeSignal class. + */ + +/** + * Class to store and manage a trading signal. + */ +class TradeSignal { + protected: + TradeSignalEntry signal; + + public: + /** + * Class constructor. + */ + TradeSignal(const TradeSignalEntry &_signal) : signal(_signal) {} + + /* Getters */ + + /** + * Gets a signal flag state. + */ + bool Get(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_FLAG) _flag) { return signal.Get(_flag); } + + /** + * Gets a signal property. + */ + template + TV Get(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop) { + signal.Get(_prop); + } + + /* Setters */ + + /** + * Sets a signal flag state. + */ + void Set(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_FLAG) _prop, bool _value) { signal.Set(_prop, _value); } + + /** + * Sets a signal property. + */ + template + void Set(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop, TV _value) { + signal.Set(_prop, _value); + } + + /* Signal methods */ + + /** + * Check for signal to close a trade. + */ + bool ShouldClose(ENUM_ORDER_TYPE _cmd) { + switch (_cmd) { + case ORDER_TYPE_BUY: + return signal.CheckSignalsEqual(SIGNAL_CLOSE_BUY_SIGNAL, SIGNAL_CLOSE_BUY_MAIN); + case ORDER_TYPE_SELL: + return signal.CheckSignalsEqual(SIGNAL_CLOSE_SELL_SIGNAL, SIGNAL_CLOSE_SELL_MAIN); + default: + break; + } + return false; + } + + /** + * Check for signal to open a trade. + */ + bool ShouldOpen(ENUM_ORDER_TYPE _cmd) { + switch (_cmd) { + case ORDER_TYPE_BUY: + return signal.CheckSignalsEqual(SIGNAL_OPEN_BUY_SIGNAL, SIGNAL_OPEN_BUY_MAIN); + case ORDER_TYPE_SELL: + return signal.CheckSignalsEqual(SIGNAL_OPEN_SELL_SIGNAL, SIGNAL_OPEN_SELL_MAIN); + default: + break; + } + return false; + } + + /** + * Gets signal's strength to close. + * + * @return + * Returns strength of signal to close between -1 and 1. + * Returns 0 on a neutral signal or when signals are in conflict. + */ + float GetSignalClose() { return float(int(ShouldClose(ORDER_TYPE_BUY)) - int(ShouldClose(ORDER_TYPE_SELL))); } + + /** + * Gets signal's strength to open. + * + * @return + * Returns strength of signal to close between -1 and 1. + * Returns 0 on a neutral signal or when signals are in conflict. + */ + float GetSignalOpen() { return float(int(ShouldOpen(ORDER_TYPE_BUY)) - int(ShouldOpen(ORDER_TYPE_SELL))); } +}; diff --git a/Trade/TradeSignal.struct.h b/Trade/TradeSignal.struct.h new file mode 100644 index 000000000..8eff5b15b --- /dev/null +++ b/Trade/TradeSignal.struct.h @@ -0,0 +1,190 @@ +//+------------------------------------------------------------------+ +//| 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 . + * + */ + +/** + * @file + * Includes TradeSignal's structs. + */ + +// Includes. +#include "../Serializer.mqh" + +// Defines. +#define SIGNAL_CLOSE_BUY_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_SIGNAL) +#define SIGNAL_CLOSE_BUY_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN) +#define SIGNAL_CLOSE_BUY_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER) +#define SIGNAL_CLOSE_SELL_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_SIGNAL) +#define SIGNAL_CLOSE_SELL_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN) +#define SIGNAL_CLOSE_SELL_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER) +#define SIGNAL_CLOSE_TIME_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER) +#define SIGNAL_OPEN_BUY_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_SIGNAL) +#define SIGNAL_OPEN_BUY_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN) +#define SIGNAL_OPEN_BUY_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER) +#define SIGNAL_OPEN_SELL_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_SIGNAL) +#define SIGNAL_OPEN_SELL_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN) +#define SIGNAL_OPEN_SELL_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER) +#define SIGNAL_OPEN_TIME_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER) + +// Structure for a trade signal. +struct TradeSignalEntry { + protected: + ENUM_TIMEFRAMES tf; // Timeframe. + float strength; // Signal strength. + float weight; // Signal weight. + unsigned int signals; // Store signals (@see: ENUM_TRADE_SIGNAL_FLAG). + + public: + /* Struct's enumerations */ + + // Enumeration for strategy bitwise signal flags. + enum ENUM_TRADE_SIGNAL_FLAG { + TRADE_SIGNAL_FLAG_NONE = 0 << 0, + TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN = 1 << 0, // Main signal for close buy + TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER = 1 << 1, // Filter for close buy + TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN = 1 << 2, // Main signal for close sell + TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER = 1 << 3, // Filter for close sell + TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER = 1 << 4, // Time filter to close + TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN = 1 << 5, // Main signal for close buy + TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER = 1 << 6, // Filter for close buy + TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN = 1 << 7, // Main signal for close sell + TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER = 1 << 8, // Filter for close sell + TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER = 1 << 9, // Time filter to open + TRADE_SIGNAL_FLAG_PROCESSED = 1 << 10, // Signal proceed + // Pre-defined signal conditions. + TRADE_SIGNAL_FLAG_CLOSE_BUY_SIGNAL = + TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN ^ (TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER), + TRADE_SIGNAL_FLAG_CLOSE_SELL_SIGNAL = + TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN ^ (TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER), + TRADE_SIGNAL_FLAG_OPEN_BUY_SIGNAL = + TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN ^ (TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER), + TRADE_SIGNAL_FLAG_OPEN_SELL_SIGNAL = + TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN ^ (TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER), + }; + + // Enumeration for strategy signal properties. + enum ENUM_TRADE_SIGNAL_PROP { + TRADE_SIGNAL_PROP_SIGNALS, + TRADE_SIGNAL_PROP_STRENGTH, + TRADE_SIGNAL_PROP_TF, + TRADE_SIGNAL_PROP_WEIGHT, + }; + // Enumeration for strategy signal types. + enum ENUM_TRADE_SIGNAL_OP { + TRADE_SIGNAL_OP_SELL = -1, // Signal to sell. + TRADE_SIGNAL_OP_NEUTRAL = 0, // Neutral signal. + TRADE_SIGNAL_OP_BUY = 1, // Signal to buy. + }; + + /* Constructor */ + TradeSignalEntry(unsigned int _signals, float _strength = 0.0f) + : signals(_signals), strength(_strength), tf(PERIOD_CURRENT), weight(0.0f) {} + TradeSignalEntry(ENUM_TIMEFRAMES _tf = NULL, float _strength = 0.0f, float _weight = 0.0f) + : signals(0), strength(_strength), tf(_tf), weight(_weight) {} + TradeSignalEntry(const TradeSignalEntry &_entry) { this = _entry; } + /* Getters */ + template + T Get(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop) { + switch (_param) { + case TRADE_SIGNAL_PROP_SIGNALS: + return (T)signals; + case TRADE_SIGNAL_PROP_STRENGTH: + return (T)strength; + case TRADE_SIGNAL_PROP_TF: + return (T)tf; + case TRADE_SIGNAL_PROP_WEIGHT: + return (T)weight; + } + SetUserError(ERR_INVALID_PARAMETER); + return (T)WRONG_VALUE; + } + bool Get(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_FLAG) _prop) { return CheckSignals(_prop); } + /* Setters */ + template + void Set(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop, T _value) { + switch (_param) { + case TRADE_SIGNAL_PROP_SIGNALS: + signals = (unsigned int)_value; + return; + case TRADE_SIGNAL_PROP_STRENGTH: + strength = (float)_value; + return; + case TRADE_SIGNAL_PROP_TF: + tf = (ENUM_TIMEFRAMES)_value; + return; + case TRADE_SIGNAL_PROP_WEIGHT: + weight = (float)_value; + return; + } + SetUserError(ERR_INVALID_PARAMETER); + } + void Set(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_FLAG) _prop, bool _value) { SetSignal(_prop, _value); } + /* Signal methods for bitwise operations */ + bool CheckSignals(unsigned int _flags) { return (signals & _flags) != 0; } + bool CheckSignalsEqual(unsigned int _flags, unsigned int _value) { return (signals & _flags) == _value; } + bool CheckSignalsExact(unsigned int _flags) { return (signals & _flags) == _flags; } + char GetCloseDirection() { + if (CheckSignals(TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN & ~TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN)) { + return 1; + } else if (CheckSignals(TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN & ~TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN)) { + return -1; + } + return 0; + } + char GetOpenDirection() { + if (CheckSignals(TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN & ~TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN)) { + return 1; + } else if (CheckSignals(TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN & ~TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN)) { + return -1; + } + return 0; + } + unsigned int GetSignals() { return signals; } + /* Setters */ + void AddSignals(unsigned int _flags) { signals |= _flags; } + void RemoveSignals(unsigned int _flags) { signals &= ~_flags; } + void SetSignal(ENUM_TRADE_SIGNAL_FLAG _flag, bool _value = true) { + if (_value) { + AddSignals(_flag); + } else { + RemoveSignals(_flag); + } + } + void SetSignals(unsigned int _flags) { signals = _flags; } + // Serializers. + SERIALIZER_EMPTY_STUB; + SerializerNodeType Serialize(Serializer &_s) { + _s.PassEnum(THIS_REF, "tf", tf); + _s.Pass(THIS_REF, "strength", strength, SERIALIZER_FIELD_FLAG_DYNAMIC); + _s.Pass(THIS_REF, "weight", weight, SERIALIZER_FIELD_FLAG_DYNAMIC); + int _size = sizeof(int) * 8; + for (int i = 0; i < _size; i++) { + int _value = CheckSignals(1 << i) ? 1 : 0; + _s.Pass(THIS_REF, (string)(i + 1), _value, SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE); + } + return SerializerNodeObject; + } + string ToString() { + // SerializerConverter _stub = SerializerConverter::MakeStubObject(SERIALIZER_FLAG_SKIP_HIDDEN); + return SerializerConverter::FromObject(THIS_REF, SERIALIZER_FLAG_SKIP_HIDDEN) + .ToString(SERIALIZER_JSON_NO_WHITESPACES); + } +}; diff --git a/Trade/tests/TradeSignalTest.mq4 b/Trade/tests/TradeSignalTest.mq4 new file mode 100644 index 000000000..8c80fd59a --- /dev/null +++ b/Trade/tests/TradeSignalTest.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of TradeSignal class. + */ + +// Includes. +#include "TradeSignalTest.mq5" diff --git a/Trade/tests/TradeSignalTest.mq5 b/Trade/tests/TradeSignalTest.mq5 new file mode 100644 index 000000000..152f395bc --- /dev/null +++ b/Trade/tests/TradeSignalTest.mq5 @@ -0,0 +1,291 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of TradeSignal class. + */ + +// Includes. +#include "../../Test.mqh" +#include "../../Trade.mqh" +#include "../TradeSignal.h" + +// Test signals to close buy trade with filters. +bool TestTradeSignalCloseBuyWithFilters() { + bool _result = true; + // 1st method. + TradeSignalEntry _entry1(SIGNAL_CLOSE_BUY_MAIN | SIGNAL_CLOSE_BUY_FILTER); + TradeSignal _signal1(_entry1); + _result &= !_signal1.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldClose(ORDER_TYPE_SELL); + // Do not close due to buy filter flag. + _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalOpen() == 0.0f; + // 2nd method. + TradeSignalEntry _entry2; + _entry2.Set(SIGNAL_CLOSE_BUY_MAIN, true); + _entry2.Set(SIGNAL_CLOSE_BUY_FILTER, true); + _entry2.Set(SIGNAL_CLOSE_TIME_FILTER, true); + TradeSignal _signal2(_entry2); + // Do not close due to buy and time filter flags. + _result &= !_signal2.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldClose(ORDER_TYPE_SELL); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal2.GetSignalOpen() == 0.0f; + return _result; +} + +// Test signals to close buy trade without filters. +bool TestTradeSignalCloseBuyWithoutFilters() { + bool _result = true; + // 1st method. + TradeSignalEntry _entry1(SIGNAL_CLOSE_BUY_MAIN); + TradeSignal _signal1(_entry1); + _result &= _signal1.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldClose(ORDER_TYPE_SELL); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal1.GetSignalClose() >= 0.5; + _result &= _signal1.GetSignalOpen() == 0.0f; + // 2nd method. + TradeSignalEntry _entry2; + _entry2.Set(SIGNAL_CLOSE_BUY_MAIN, true); + TradeSignal _signal2(_entry2); + _result &= _signal2.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldClose(ORDER_TYPE_SELL); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal2.GetSignalClose() >= 0.5f; + _result &= _signal2.GetSignalOpen() == 0.0f; + return _result; +} + +// Test signals to close sell trade with filters. +bool TestTradeSignalCloseSellWithFilters() { + bool _result = true; + // 1st method. + TradeSignalEntry _entry1(SIGNAL_CLOSE_SELL_MAIN | SIGNAL_CLOSE_SELL_FILTER); + TradeSignal _signal1(_entry1); + _result &= !_signal1.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldClose(ORDER_TYPE_SELL); + // Do not close due to sell filter flag. + _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalOpen() == 0.0f; + // 2nd method. + TradeSignalEntry _entry2; + _entry2.Set(SIGNAL_CLOSE_SELL_MAIN, true); + _entry2.Set(SIGNAL_CLOSE_SELL_FILTER, true); + _entry2.Set(SIGNAL_CLOSE_TIME_FILTER, true); + TradeSignal _signal2(_entry2); + // Do not close due to sell and time filter flags. + _result &= !_signal2.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldClose(ORDER_TYPE_SELL); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal2.GetSignalOpen() == 0.0f; + return _result; +} + +// Test signals to close sell trade without filters. +bool TestTradeSignalCloseSellWithoutFilters() { + bool _result = true; + // 1st method. + TradeSignalEntry _entry1(SIGNAL_CLOSE_SELL_MAIN); + TradeSignal _signal1(_entry1); + _result &= !_signal1.ShouldClose(ORDER_TYPE_BUY); + _result &= _signal1.ShouldClose(ORDER_TYPE_SELL); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal1.GetSignalClose() <= -0.5; + _result &= _signal1.GetSignalOpen() == 0.0f; + // 2nd method. + TradeSignalEntry _entry2; + _entry2.Set(SIGNAL_CLOSE_SELL_MAIN, true); + TradeSignal _signal2(_entry2); + _result &= !_signal2.ShouldClose(ORDER_TYPE_BUY); + _result &= _signal2.ShouldClose(ORDER_TYPE_SELL); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal2.GetSignalClose() <= -0.5; + _result &= _signal2.GetSignalOpen() == 0.0f; + return _result; +} + +// -- + +// Test signals to open buy trade with filters. +bool TestTradeSignalOpenBuyWithFilters() { + bool _result = true; + // 1st method. + TradeSignalEntry _entry1(SIGNAL_OPEN_BUY_MAIN | SIGNAL_OPEN_BUY_FILTER); + TradeSignal _signal1(_entry1); + _result &= !_signal1.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldClose(ORDER_TYPE_SELL); + // Do not open due to buy filter flag. + _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalOpen() == 0.0f; + // 2nd method. + TradeSignalEntry _entry2; + _entry2.Set(SIGNAL_OPEN_BUY_MAIN, true); + _entry2.Set(SIGNAL_OPEN_BUY_FILTER, true); + _entry2.Set(SIGNAL_OPEN_TIME_FILTER, true); + TradeSignal _signal2(_entry2); + _result &= !_signal2.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldClose(ORDER_TYPE_SELL); + // Do not open due to buy and time filter flags. + _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal2.GetSignalOpen() == 0.0f; + return _result; +} + +// Test signals to open buy trade without filters. +bool TestTradeSignalOpenBuyWithoutFilters() { + bool _result = true; + // 1st method. + TradeSignalEntry _entry1(SIGNAL_OPEN_BUY_MAIN); + TradeSignal _signal1(_entry1); + _result &= !_signal1.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldClose(ORDER_TYPE_SELL); + _result &= _signal1.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalOpen() >= 0.5; + // 2nd method. + TradeSignalEntry _entry2; + _entry2.Set(SIGNAL_OPEN_BUY_MAIN, true); + TradeSignal _signal2(_entry2); + _result &= !_signal2.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldClose(ORDER_TYPE_SELL); + _result &= _signal2.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal2.GetSignalOpen() >= 0.5f; + return _result; +} + +// Test signals to open sell trade with filters. +bool TestTradeSignalOpenSellWithFilters() { + bool _result = true; + // 1st method. + TradeSignalEntry _entry1(SIGNAL_OPEN_SELL_MAIN | SIGNAL_OPEN_SELL_FILTER); + TradeSignal _signal1(_entry1); + _result &= !_signal1.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldClose(ORDER_TYPE_SELL); + // Do not open due to sell filter flag. + _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalOpen() == 0.0f; + // 2nd method. + TradeSignalEntry _entry2; + _entry2.Set(SIGNAL_OPEN_SELL_MAIN, true); + _entry2.Set(SIGNAL_OPEN_SELL_FILTER, true); + _entry2.Set(SIGNAL_OPEN_TIME_FILTER, true); + TradeSignal _signal2(_entry2); + _result &= !_signal2.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldClose(ORDER_TYPE_SELL); + // Do not open due to sell and time filter flags. + _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal2.GetSignalOpen() == 0.0f; + return _result; +} + +// Test signals to open sell trade without filters. +bool TestTradeSignalOpenSellWithoutFilters() { + bool _result = true; + // 1st method. + TradeSignalEntry _entry1(SIGNAL_OPEN_SELL_MAIN); + TradeSignal _signal1(_entry1); + _result &= !_signal1.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldClose(ORDER_TYPE_SELL); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); + _result &= _signal1.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalOpen() <= -0.5; + // 2nd method. + TradeSignalEntry _entry2; + _entry2.Set(SIGNAL_OPEN_SELL_MAIN, true); + TradeSignal _signal2(_entry2); + _result &= !_signal2.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldClose(ORDER_TYPE_SELL); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); + _result &= _signal2.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal2.GetSignalOpen() <= -0.5; + return _result; +} + +// Test empty signal. +bool TestTradeSignalNone() { + bool _result = true; + // 1st method. + TradeSignalEntry _entry1(SIGNAL_CLOSE_BUY_FILTER | SIGNAL_CLOSE_SELL_FILTER); + TradeSignal _signal1(_entry1); + _result &= !_signal1.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldClose(ORDER_TYPE_SELL); + // Do not close due to buy filter flag. + _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalOpen() == 0.0f; + // 2nd method. + TradeSignalEntry _entry2; + TradeSignal _signal2(_entry2); + // Do not close due to buy and time filter flags. + _result &= !_signal2.ShouldClose(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldClose(ORDER_TYPE_SELL); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); + _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); + _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal2.GetSignalOpen() == 0.0f; + return _result; +} + +/** + * Implements OnInit(). + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(TestTradeSignalCloseBuyWithFilters(), "Fail!"); + assertTrueOrFail(TestTradeSignalCloseBuyWithoutFilters(), "Fail!"); + assertTrueOrFail(TestTradeSignalCloseSellWithFilters(), "Fail!"); + assertTrueOrFail(TestTradeSignalCloseSellWithoutFilters(), "Fail!"); + assertTrueOrFail(TestTradeSignalOpenBuyWithFilters(), "Fail!"); + assertTrueOrFail(TestTradeSignalOpenBuyWithoutFilters(), "Fail!"); + assertTrueOrFail(TestTradeSignalOpenSellWithFilters(), "Fail!"); + assertTrueOrFail(TestTradeSignalOpenSellWithoutFilters(), "Fail!"); + assertTrueOrFail(TestTradeSignalNone(), "Fail!"); + return _result && GetLastError() == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED; +} From b8ce03f6a6b8595bb29a811bca739c121433383f Mon Sep 17 00:00:00 2001 From: kenorb Date: Wed, 29 Sep 2021 23:18:42 +0100 Subject: [PATCH 19/78] TradeSignal: Adds serializers and ToString() method --- Trade/TradeSignal.h | 21 +++++++++++++++++++++ Trade/tests/TradeSignalTest.mq5 | 20 ++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Trade/TradeSignal.h b/Trade/TradeSignal.h index a84caef5a..dd3cddfb1 100644 --- a/Trade/TradeSignal.h +++ b/Trade/TradeSignal.h @@ -120,4 +120,25 @@ class TradeSignal { * Returns 0 on a neutral signal or when signals are in conflict. */ float GetSignalOpen() { return float(int(ShouldOpen(ORDER_TYPE_BUY)) - int(ShouldOpen(ORDER_TYPE_SELL))); } + + /* Serializers */ + + /** + * Serialize an instance class. + * + * @return + * Returns a JSON serialized instance. + */ + SerializerNodeType Serialize(Serializer &_s) { + _s.PassStruct(THIS_REF, "signal", signal); + return SerializerNodeObject; + } + + /** + * Converts the signal to a string. + * + * @return + * Returns a JSON serialized signal. + */ + string ToString() { return signal.ToString(); } }; diff --git a/Trade/tests/TradeSignalTest.mq5 b/Trade/tests/TradeSignalTest.mq5 index 152f395bc..67f8ef111 100644 --- a/Trade/tests/TradeSignalTest.mq5 +++ b/Trade/tests/TradeSignalTest.mq5 @@ -42,6 +42,7 @@ bool TestTradeSignalCloseBuyWithFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; _entry2.Set(SIGNAL_CLOSE_BUY_MAIN, true); @@ -55,6 +56,7 @@ bool TestTradeSignalCloseBuyWithFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + Print(_signal2.ToString()); return _result; } @@ -70,6 +72,7 @@ bool TestTradeSignalCloseBuyWithoutFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() >= 0.5; _result &= _signal1.GetSignalOpen() == 0.0f; + Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; _entry2.Set(SIGNAL_CLOSE_BUY_MAIN, true); @@ -80,6 +83,7 @@ bool TestTradeSignalCloseBuyWithoutFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() >= 0.5f; _result &= _signal2.GetSignalOpen() == 0.0f; + Print(_signal2.ToString()); return _result; } @@ -96,6 +100,7 @@ bool TestTradeSignalCloseSellWithFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; _entry2.Set(SIGNAL_CLOSE_SELL_MAIN, true); @@ -109,6 +114,7 @@ bool TestTradeSignalCloseSellWithFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + Print(_signal2.ToString()); return _result; } @@ -124,6 +130,7 @@ bool TestTradeSignalCloseSellWithoutFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() <= -0.5; _result &= _signal1.GetSignalOpen() == 0.0f; + Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; _entry2.Set(SIGNAL_CLOSE_SELL_MAIN, true); @@ -134,11 +141,10 @@ bool TestTradeSignalCloseSellWithoutFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() <= -0.5; _result &= _signal2.GetSignalOpen() == 0.0f; + Print(_signal2.ToString()); return _result; } -// -- - // Test signals to open buy trade with filters. bool TestTradeSignalOpenBuyWithFilters() { bool _result = true; @@ -152,6 +158,7 @@ bool TestTradeSignalOpenBuyWithFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; _entry2.Set(SIGNAL_OPEN_BUY_MAIN, true); @@ -165,6 +172,7 @@ bool TestTradeSignalOpenBuyWithFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + Print(_signal2.ToString()); return _result; } @@ -180,6 +188,7 @@ bool TestTradeSignalOpenBuyWithoutFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; _result &= _signal1.GetSignalOpen() >= 0.5; + Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; _entry2.Set(SIGNAL_OPEN_BUY_MAIN, true); @@ -190,6 +199,7 @@ bool TestTradeSignalOpenBuyWithoutFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; _result &= _signal2.GetSignalOpen() >= 0.5f; + Print(_signal2.ToString()); return _result; } @@ -206,6 +216,7 @@ bool TestTradeSignalOpenSellWithFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; _entry2.Set(SIGNAL_OPEN_SELL_MAIN, true); @@ -219,6 +230,7 @@ bool TestTradeSignalOpenSellWithFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + Print(_signal2.ToString()); return _result; } @@ -234,6 +246,7 @@ bool TestTradeSignalOpenSellWithoutFilters() { _result &= _signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; _result &= _signal1.GetSignalOpen() <= -0.5; + Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; _entry2.Set(SIGNAL_OPEN_SELL_MAIN, true); @@ -244,6 +257,7 @@ bool TestTradeSignalOpenSellWithoutFilters() { _result &= _signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; _result &= _signal2.GetSignalOpen() <= -0.5; + Print(_signal2.ToString()); return _result; } @@ -260,6 +274,7 @@ bool TestTradeSignalNone() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; TradeSignal _signal2(_entry2); @@ -270,6 +285,7 @@ bool TestTradeSignalNone() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + Print(_signal2.ToString()); return _result; } From 47542d54bf6be80439d9999dbc4fd5e63508b391 Mon Sep 17 00:00:00 2001 From: kenorb Date: Wed, 29 Sep 2021 23:41:49 +0100 Subject: [PATCH 20/78] TradeSignal: Adds GetSignalCloseDirection() and GetSignalOpenDirection() (moved from struct) --- Trade/TradeSignal.h | 30 +++++++++++++++++++++++++++ Trade/TradeSignal.struct.h | 25 +++++++++-------------- Trade/tests/TradeSignalTest.mq5 | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 16 deletions(-) diff --git a/Trade/TradeSignal.h b/Trade/TradeSignal.h index dd3cddfb1..3c98c7362 100644 --- a/Trade/TradeSignal.h +++ b/Trade/TradeSignal.h @@ -112,6 +112,21 @@ class TradeSignal { */ float GetSignalClose() { return float(int(ShouldClose(ORDER_TYPE_BUY)) - int(ShouldClose(ORDER_TYPE_SELL))); } + /** + * Gets signal's close direction. + * + * @return + * Returns +1 for upwards, -1 for downwards, or 0 for a neutral direction. + */ + char GetSignalCloseDirection() { + if (signal.CheckSignals(SIGNAL_CLOSE_UPWARDS)) { + return 1; + } else if (signal.CheckSignals(SIGNAL_CLOSE_DOWNWARDS)) { + return -1; + } + return 0; + } + /** * Gets signal's strength to open. * @@ -121,6 +136,21 @@ class TradeSignal { */ float GetSignalOpen() { return float(int(ShouldOpen(ORDER_TYPE_BUY)) - int(ShouldOpen(ORDER_TYPE_SELL))); } + /** + * Gets signal's open direction. + * + * @return + * Returns +1 for upwards, -1 for downwards, or 0 for a neutral direction. + */ + char GetSignalOpenDirection() { + if (signal.CheckSignals(SIGNAL_OPEN_UPWARDS)) { + return 1; + } else if (signal.CheckSignals(SIGNAL_OPEN_DOWNWARDS)) { + return -1; + } + return 0; + } + /* Serializers */ /** diff --git a/Trade/TradeSignal.struct.h b/Trade/TradeSignal.struct.h index 8eff5b15b..cc6c478f2 100644 --- a/Trade/TradeSignal.struct.h +++ b/Trade/TradeSignal.struct.h @@ -32,17 +32,21 @@ #define SIGNAL_CLOSE_BUY_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_SIGNAL) #define SIGNAL_CLOSE_BUY_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN) #define SIGNAL_CLOSE_BUY_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER) +#define SIGNAL_CLOSE_DOWNWARDS STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_DOWNWARDS) #define SIGNAL_CLOSE_SELL_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_SIGNAL) #define SIGNAL_CLOSE_SELL_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN) #define SIGNAL_CLOSE_SELL_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER) #define SIGNAL_CLOSE_TIME_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER) +#define SIGNAL_CLOSE_UPWARDS STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_UPWARDS) #define SIGNAL_OPEN_BUY_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_SIGNAL) #define SIGNAL_OPEN_BUY_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN) #define SIGNAL_OPEN_BUY_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER) +#define SIGNAL_OPEN_DOWNWARDS STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_DOWNWARDS) #define SIGNAL_OPEN_SELL_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_SIGNAL) #define SIGNAL_OPEN_SELL_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN) #define SIGNAL_OPEN_SELL_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER) #define SIGNAL_OPEN_TIME_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER) +#define SIGNAL_OPEN_UPWARDS STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_UPWARDS) // Structure for a trade signal. struct TradeSignalEntry { @@ -78,6 +82,11 @@ struct TradeSignalEntry { TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN ^ (TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER), TRADE_SIGNAL_FLAG_OPEN_SELL_SIGNAL = TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN ^ (TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER), + // Pre-defined signal directions. + TRADE_SIGNAL_FLAG_CLOSE_DOWNWARDS = TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN & ~TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN, + TRADE_SIGNAL_FLAG_CLOSE_UPWARDS = TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN & ~TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN, + TRADE_SIGNAL_FLAG_OPEN_DOWNWARDS = TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN & ~TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN, + TRADE_SIGNAL_FLAG_OPEN_UPWARDS = TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN & ~TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN, }; // Enumeration for strategy signal properties. @@ -141,22 +150,6 @@ struct TradeSignalEntry { bool CheckSignals(unsigned int _flags) { return (signals & _flags) != 0; } bool CheckSignalsEqual(unsigned int _flags, unsigned int _value) { return (signals & _flags) == _value; } bool CheckSignalsExact(unsigned int _flags) { return (signals & _flags) == _flags; } - char GetCloseDirection() { - if (CheckSignals(TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN & ~TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN)) { - return 1; - } else if (CheckSignals(TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN & ~TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN)) { - return -1; - } - return 0; - } - char GetOpenDirection() { - if (CheckSignals(TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN & ~TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN)) { - return 1; - } else if (CheckSignals(TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN & ~TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN)) { - return -1; - } - return 0; - } unsigned int GetSignals() { return signals; } /* Setters */ void AddSignals(unsigned int _flags) { signals |= _flags; } diff --git a/Trade/tests/TradeSignalTest.mq5 b/Trade/tests/TradeSignalTest.mq5 index 67f8ef111..f732a015e 100644 --- a/Trade/tests/TradeSignalTest.mq5 +++ b/Trade/tests/TradeSignalTest.mq5 @@ -41,7 +41,9 @@ bool TestTradeSignalCloseBuyWithFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 1.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; @@ -55,7 +57,9 @@ bool TestTradeSignalCloseBuyWithFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 1.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal2.ToString()); return _result; } @@ -71,7 +75,9 @@ bool TestTradeSignalCloseBuyWithoutFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() >= 0.5; + _result &= _signal1.GetSignalCloseDirection() == 1.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; @@ -82,7 +88,9 @@ bool TestTradeSignalCloseBuyWithoutFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() >= 0.5f; + _result &= _signal1.GetSignalCloseDirection() == 1.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal2.ToString()); return _result; } @@ -99,7 +107,9 @@ bool TestTradeSignalCloseSellWithFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == -1.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; @@ -113,7 +123,9 @@ bool TestTradeSignalCloseSellWithFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == -1.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal2.ToString()); return _result; } @@ -129,7 +141,9 @@ bool TestTradeSignalCloseSellWithoutFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() <= -0.5; + _result &= _signal1.GetSignalCloseDirection() == -1.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; @@ -140,7 +154,9 @@ bool TestTradeSignalCloseSellWithoutFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() <= -0.5; + _result &= _signal1.GetSignalCloseDirection() == -1.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal2.ToString()); return _result; } @@ -157,7 +173,9 @@ bool TestTradeSignalOpenBuyWithFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 1.0f; Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; @@ -171,7 +189,9 @@ bool TestTradeSignalOpenBuyWithFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 1.0f; Print(_signal2.ToString()); return _result; } @@ -187,7 +207,9 @@ bool TestTradeSignalOpenBuyWithoutFilters() { _result &= _signal1.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal1.GetSignalOpen() >= 0.5; + _result &= _signal1.GetSignalOpenDirection() == 1.0f; Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; @@ -198,7 +220,9 @@ bool TestTradeSignalOpenBuyWithoutFilters() { _result &= _signal2.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal2.GetSignalOpen() >= 0.5f; + _result &= _signal1.GetSignalOpenDirection() == 1.0f; Print(_signal2.ToString()); return _result; } @@ -215,7 +239,9 @@ bool TestTradeSignalOpenSellWithFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == -1.0f; Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; @@ -229,7 +255,9 @@ bool TestTradeSignalOpenSellWithFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == -1.0f; Print(_signal2.ToString()); return _result; } @@ -245,7 +273,9 @@ bool TestTradeSignalOpenSellWithoutFilters() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); _result &= _signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal1.GetSignalOpen() <= -0.5; + _result &= _signal1.GetSignalOpenDirection() == -1.0f; Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; @@ -256,7 +286,9 @@ bool TestTradeSignalOpenSellWithoutFilters() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); _result &= _signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal2.GetSignalOpen() <= -0.5; + _result &= _signal1.GetSignalOpenDirection() == -1.0f; Print(_signal2.ToString()); return _result; } @@ -273,7 +305,9 @@ bool TestTradeSignalNone() { _result &= !_signal1.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal1.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal1.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal1.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal1.ToString()); // 2nd method. TradeSignalEntry _entry2; @@ -284,7 +318,9 @@ bool TestTradeSignalNone() { _result &= !_signal2.ShouldOpen(ORDER_TYPE_BUY); _result &= !_signal2.ShouldOpen(ORDER_TYPE_SELL); _result &= _signal2.GetSignalClose() == 0.0f; + _result &= _signal1.GetSignalCloseDirection() == 0.0f; _result &= _signal2.GetSignalOpen() == 0.0f; + _result &= _signal1.GetSignalOpenDirection() == 0.0f; Print(_signal2.ToString()); return _result; } From d25b0f7e734e788f710af6cc52b5203d4ad3bd89 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Thu, 30 Sep 2021 14:16:03 +0200 Subject: [PATCH 21/78] WIP. Indicator classes refactoring. Works in MT5, 5 indicators doesn't calculate proper values in MT4. --- Action.mqh | 2 +- Condition.mqh | 2 +- EA.mqh | 2 +- Indicator.mqh | 99 +----------------- IndicatorBase.h | 12 +-- Indicators/Indi_AC.mqh | 2 +- Indicators/Indi_AD.mqh | 2 +- Indicators/Indi_ADX.mqh | 2 +- Indicators/Indi_ADXW.mqh | 2 +- Indicators/Indi_AMA.mqh | 2 +- Indicators/Indi_AO.mqh | 2 +- Indicators/Indi_ASI.mqh | 2 +- Indicators/Indi_ATR.mqh | 2 +- Indicators/Indi_Alligator.mqh | 2 +- Indicators/Indi_BWMFI.mqh | 2 +- Indicators/Indi_BWZT.mqh | 5 +- Indicators/Indi_Bands.mqh | 26 ++--- Indicators/Indi_BearsPower.mqh | 2 +- Indicators/Indi_BullsPower.mqh | 2 +- Indicators/Indi_CCI.mqh | 2 +- Indicators/Indi_CHO.mqh | 2 +- Indicators/Indi_CHV.mqh | 3 +- Indicators/Indi_ColorBars.mqh | 2 +- Indicators/Indi_ColorCandlesDaily.mqh | 3 +- Indicators/Indi_ColorLine.mqh | 5 +- Indicators/Indi_CustomMovingAverage.mqh | 1 + Indicators/Indi_DEMA.mqh | 5 +- Indicators/Indi_DeMarker.mqh | 2 +- Indicators/Indi_Demo.mqh | 2 +- Indicators/Indi_DetrendedPrice.mqh | 2 +- Indicators/Indi_Drawer.mqh | 2 +- Indicators/Indi_Envelopes.mqh | 6 +- Indicators/Indi_Force.mqh | 2 +- Indicators/Indi_FractalAdaptiveMA.mqh | 2 +- Indicators/Indi_Fractals.mqh | 2 +- Indicators/Indi_Gator.mqh | 2 +- Indicators/Indi_HeikenAshi.mqh | 2 +- Indicators/Indi_Ichimoku.mqh | 2 +- Indicators/Indi_MA.mqh | 4 +- Indicators/Indi_MACD.mqh | 2 +- Indicators/Indi_MFI.mqh | 2 +- Indicators/Indi_MassIndex.mqh | 2 +- Indicators/Indi_Momentum.mqh | 2 +- Indicators/Indi_OBV.mqh | 4 +- Indicators/Indi_OsMA.mqh | 2 +- Indicators/Indi_Price.mqh | 16 +-- Indicators/Indi_PriceVolumeTrend.mqh | 2 +- Indicators/Indi_RS.mqh | 15 +-- Indicators/Indi_RSI.mqh | 13 ++- Indicators/Indi_RVI.mqh | 2 +- Indicators/Indi_RateOfChange.mqh | 2 +- Indicators/Indi_SAR.mqh | 2 +- Indicators/Indi_StdDev.mqh | 2 +- Indicators/Indi_Stochastic.mqh | 2 +- Indicators/Indi_TRIX.mqh | 2 +- Indicators/Indi_UltimateOscillator.mqh | 7 +- Indicators/Indi_VIDYA.mqh | 2 +- Indicators/Indi_VROC.mqh | 2 +- Indicators/Indi_Volumes.mqh | 2 +- Indicators/Indi_WPR.mqh | 2 +- Indicators/Indi_WilliamsAD.mqh | 3 +- Indicators/Indi_ZigZag.mqh | 3 +- Indicators/Special/Indi_Math.mqh | 15 ++- Indicators/indicators.h | 6 +- Strategy.mqh | 10 +- tests/IndicatorsTest.mq5 | 129 ++++++++++++------------ 66 files changed, 185 insertions(+), 293 deletions(-) diff --git a/Action.mqh b/Action.mqh index 12387359c..5ed379560 100644 --- a/Action.mqh +++ b/Action.mqh @@ -141,7 +141,7 @@ class Action { #ifdef INDICATOR_MQH case ACTION_TYPE_INDICATOR: if (Object::IsValid(_entry.obj)) { - _result = ((Indicator *)_entry.obj).ExecuteAction((ENUM_INDICATOR_ACTION)_entry.action_id); + _result = ((IndicatorBase *)_entry.obj).ExecuteAction((ENUM_INDICATOR_ACTION)_entry.action_id); } else { _result = false; _entry.AddFlags(ACTION_ENTRY_FLAG_IS_INVALID); diff --git a/Condition.mqh b/Condition.mqh index f29051c29..915cbcd4e 100644 --- a/Condition.mqh +++ b/Condition.mqh @@ -167,7 +167,7 @@ class Condition { #ifdef INDICATOR_MQH case COND_TYPE_INDICATOR: if (Object::IsValid(_entry.obj)) { - _result = ((Indicator *)_entry.obj).CheckCondition((ENUM_INDICATOR_CONDITION)_entry.cond_id, _entry.args); + _result = ((IndicatorBase *)_entry.obj).CheckCondition((ENUM_INDICATOR_CONDITION)_entry.cond_id, _entry.args); } else { // Static method not supported. _result = false; diff --git a/EA.mqh b/EA.mqh index ba4112c78..ff92532ef 100644 --- a/EA.mqh +++ b/EA.mqh @@ -373,7 +373,7 @@ class EA { if (eparams.CheckFlagDataStore(EA_DATA_STORE_INDICATOR)) { for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { Strategy *_strati = iter.Value().Ptr(); - Indicator *_indi = _strati.GetIndicator(); + IndicatorBase *_indi = _strati.GetIndicator(); if (_indi != NULL) { ENUM_TIMEFRAMES _itf = _indi.GetParams().tf.GetTf(); IndicatorDataEntry _ientry = _indi.GetEntry(); diff --git a/Indicator.mqh b/Indicator.mqh index 63af912a3..d7da6e157 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -100,15 +100,8 @@ class Indicator : public IndicatorBase { * Class deconstructor. */ ~Indicator() { - ReleaseHandle(); DeinitDraw(); - for (int i = 0; i < ArraySize(value_storages); ++i) { - if (value_storages[i] != NULL) { - delete value_storages[i]; - } - } - if (indi_src != NULL && iparams.indi_managed) { // User selected custom, managed data source. if (CheckPointer(indi_src) == POINTER_INVALID) { @@ -286,7 +279,7 @@ class Indicator : public IndicatorBase { * allocated for the array */ /* - static int CopyBuffer(Indicator* _indi, int _mode, int _start, int _count, ValueStorage& _buffer, + static int CopyBuffer(IndicatorBase * _indi, int _mode, int _start, int _count, ValueStorage& _buffer, int _rates_total) { int _num_copied = 0; int _buffer_size = ArraySize(_buffer); if (_buffer_size < _rates_total) { @@ -412,6 +405,7 @@ class Indicator : public IndicatorBase { if (!_source.IsSet()) { Alert(GetName(), " has no built-in source indicator ", _source_id); + DebugBreak(); } else { indicators.Set(_source_id, _source); @@ -534,8 +528,7 @@ class Indicator : public IndicatorBase { /** * Sets indicator data source. */ - template - void SetDataSource(Indicator* _indi, bool _managed = true, int _input_mode = -1) { + void SetDataSource(IndicatorBase* _indi, bool _managed, int _input_mode) { indi_src = _indi; iparams.SetDataSource(-1, _input_mode, _managed); } @@ -765,91 +758,7 @@ class Indicator : public IndicatorBase { is_fed = true; } - ValueStorage* GetValueStorage(int _mode = 0) { - if (value_storages[_mode] == NULL) { - value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); - } - return value_storages[_mode]; - } - - /** - * Returns indicator value for a given shift and mode. - */ - template - T GetValue(int _shift = 0, int _mode = -1) { - T _result; - // @fixit We probably don't want to retrieve source mode from there. - int _index = _mode != -1 ? _mode : GetDataSourceMode(); - GetEntry(_shift).values[_index].Get(_result); - ResetLastError(); - return _result; - } - - /** - * Returns price corresponding to indicator value for a given shift and mode. - * - * Can be useful for calculating trailing stops based on the indicator. - * - * @return - * Returns price value of the corresponding indicator values. - */ - template - float GetValuePrice(int _shift = 0, int _mode = 0, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL) { - float _price = 0; - if (iparams.GetIDataValueRange() != IDATA_RANGE_PRICE) { - _price = (float)GetPrice(_ap, _shift); - } else if (iparams.GetIDataValueRange() == IDATA_RANGE_PRICE) { - // When indicator values are the actual prices. - T _values[4]; - if (!CopyValues(_values, 4, _shift, _mode)) { - // When values aren't valid, return 0. - return _price; - } - datetime _bar_time = GetBarTime(_shift); - float _value = 0; - BarOHLC _ohlc(_values, _bar_time); - _price = _ohlc.GetAppliedPrice(_ap); - } - return _price; - } - - /** - * Returns values for a given shift. - * - * Note: Remember to check if shift exists by HasValidEntry(shift). - */ - template - bool GetValues(int _shift, T& _out1, T& _out2) { - IndicatorDataEntry _entry = GetEntry(_shift); - _out1 = _entry.values[0]; - _out2 = _entry.values[1]; - bool _result = GetLastError() != 4401; - ResetLastError(); - return _result; - } - - template - bool GetValues(int _shift, T& _out1, T& _out2, T& _out3) { - IndicatorDataEntry _entry = GetEntry(_shift); - _out1 = _entry.values[0]; - _out2 = _entry.values[1]; - _out3 = _entry.values[2]; - bool _result = GetLastError() != 4401; - ResetLastError(); - return _result; - } - - template - bool GetValues(int _shift, T& _out1, T& _out2, T& _out3, T& _out4) { - IndicatorDataEntry _entry = GetEntry(_shift); - _out1 = _entry.values[0]; - _out2 = _entry.values[1]; - _out3 = _entry.values[2]; - _out4 = _entry.values[3]; - bool _result = GetLastError() != 4401; - ResetLastError(); - return _result; - } + ENUM_IDATA_VALUE_RANGE GetIDataValueRange() { return iparams.idvrange; } virtual void OnTick() { Chart::OnTick(); diff --git a/IndicatorBase.h b/IndicatorBase.h index 157fd8281..1f4dd7d38 100644 --- a/IndicatorBase.h +++ b/IndicatorBase.h @@ -781,11 +781,7 @@ class IndicatorBase : public Chart { /** * Sets indicator data source. */ - template - void SetDataSource(Indicator* _indi, bool _managed = true, int _input_mode = -1) { - indi_src = _indi; - iparams.SetDataSource(-1, _input_mode, _managed); - } + virtual void SetDataSource(IndicatorBase* _indi, bool _managed, int _input_mode) = 0; /** * Sets data source's input mode. @@ -1009,6 +1005,8 @@ class IndicatorBase : public Chart { is_fed = true; } + virtual ENUM_IDATA_VALUE_RANGE GetIDataValueRange() = 0; + ValueStorage* GetValueStorage(int _mode = 0) { if (value_storages[_mode] == NULL) { value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); @@ -1039,9 +1037,9 @@ class IndicatorBase : public Chart { template float GetValuePrice(int _shift = 0, int _mode = 0, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL) { float _price = 0; - if (iparams.GetIDataValueRange() != IDATA_RANGE_PRICE) { + if (GetIDataValueRange() != IDATA_RANGE_PRICE) { _price = (float)GetPrice(_ap, _shift); - } else if (iparams.GetIDataValueRange() == IDATA_RANGE_PRICE) { + } else if (GetIDataValueRange() == IDATA_RANGE_PRICE) { // When indicator values are the actual prices. T _values[4]; if (!CopyValues(_values, 4, _shift, _mode)) { diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 2b10d1fb1..9472946d3 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -61,7 +61,7 @@ class Indi_AC : public Indicator { * - https://www.mql5.com/en/docs/indicators/iac */ static double iAC(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iAC(_symbol, _tf, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index d15169d5a..f5fdf23a0 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -60,7 +60,7 @@ class Indi_AD : public Indicator { * - https://www.mql5.com/en/docs/indicators/iad */ static double iAD(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iAD(_symbol, _tf, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 33c77ee3a..7d1f9cba1 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -89,7 +89,7 @@ class Indi_ADX : public Indicator { ENUM_APPLIED_PRICE _applied_price, // (MT5): not used int _mode = LINE_MAIN_ADX, // (MT4/MT5): 0 - MODE_MAIN/MAIN_LINE, 1 - // MODE_PLUSDI/PLUSDI_LINE, 2 - MODE_MINUSDI/MINUSDI_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iADX(_symbol, _tf, _period, _applied_price, _mode, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index cdad42ac8..32fc007bc 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -65,7 +65,7 @@ class Indi_ADXW : public Indicator { * Built-in version of ADX Wilder. */ static double iADXWilder(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _mode = LINE_MAIN_ADX, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iADXWilder(_symbol, _tf, _ma_period), _mode, _shift); #else diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index 60f7ffb79..bed13c120 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -85,7 +85,7 @@ class Indi_AMA : public Indicator { */ static double iAMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ama_period, int _fast_ema_period, int _slow_ema_period, int _ama_shift, ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN( ::iAMA(_symbol, _tf, _ama_period, _fast_ema_period, _slow_ema_period, _ama_shift, _ap), _mode, _shift); diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index 26ee96ccf..dad8da0e6 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -64,7 +64,7 @@ class Indi_AO : public Indicator { * - https://www.mql5.com/en/docs/indicators/iao */ static double iAO(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, int _mode = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ // Note: In MQL4 _mode is not supported. return ::iAO(_symbol, _tf, _shift); diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index c3a737189..7d7250127 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -56,7 +56,7 @@ class Indi_ASI : public Indicator { * Built-in version of ASI. */ static double iASI(string _symbol, ENUM_TIMEFRAMES _tf, double _mpc, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, Util::MakeKey("Indi_ASI", _mpc)); return iASIOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mpc, _mode, _shift, _cache); } diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index 79f6a8113..8b84cad2a 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -65,7 +65,7 @@ class Indi_ATR : public Indicator { * - https://www.mql5.com/en/docs/indicators/iatr */ static double iATR(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iATR(_symbol, _tf, _period, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index 20b3bce7a..bb22a2020 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -121,7 +121,7 @@ class Indi_Alligator : public Indicator { static double iAlligator(string _symbol, ENUM_TIMEFRAMES _tf, int _jaw_period, int _jaw_shift, int _teeth_period, int _teeth_shift, int _lips_period, int _lips_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, ENUM_ALLIGATOR_LINE _mode, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iAlligator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift, _ma_method, _applied_price, _mode, _shift); diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index 208c25a51..bd9db39ad 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -72,7 +72,7 @@ class Indi_BWMFI : public Indicator { * - https://www.mql5.com/en/docs/indicators/ibwmfi */ static double iBWMFI(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, - ENUM_BWMFI_BUFFER _mode = BWMFI_BUFFER, Indicator *_obj = NULL) { + ENUM_BWMFI_BUFFER _mode = BWMFI_BUFFER, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ // Adjusting shift for MT4. _shift++; diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index a5c9705c5..4b461e975 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -57,8 +57,7 @@ class Indi_BWZT : public Indicator { /** * Built-in version of BWZT. */ - static double iBWZT(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + static double iBWZT(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_BWZT"); Indi_AC *_indi_ac = Indi_AC::GetCached(_symbol, _tf); @@ -98,7 +97,7 @@ class Indi_BWZT : public Indicator { ValueStorage &ExtHBuffer, ValueStorage &ExtLBuffer, ValueStorage &ExtCBuffer, ValueStorage &ExtColorBuffer, ValueStorage &ExtAOBuffer, ValueStorage &ExtACBuffer, int DATA_LIMIT, - Indicator *ExtACHandle, Indicator *ExtAOHandle) { + IndicatorBase *ExtACHandle, IndicatorBase *ExtAOHandle) { if (rates_total < DATA_LIMIT) return (0); // Not all data may be calculated. int calculated = BarsCalculated(ExtACHandle, rates_total); diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 7a45f122c..91e1c8159 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -96,7 +96,7 @@ class Indi_Bands : public Indicator { */ static double iBands(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, double _deviation, int _bands_shift, ENUM_APPLIED_PRICE _applied_price, ENUM_BANDS_LINE _mode = BAND_BASE, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { ResetLastError(); #ifdef __MQL4__ @@ -136,8 +136,7 @@ class Indi_Bands : public Indicator { * * When _applied_price is set to -1, method will */ - template - static double iBandsOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, + static double iBandsOnIndicator(IndicatorBase *_indi, string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, double _deviation, int _bands_shift, ENUM_BANDS_LINE _mode, // (MT4/MT5): 0 - MODE_MAIN/BASE_LINE, 1 - // MODE_UPPER/UPPER_BAND, 2 - MODE_LOWER/LOWER_BAND @@ -241,20 +240,17 @@ class Indi_Bands : public Indicator { switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = - Indi_Bands::iBands(Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), GetPeriod(), - GetDeviation(), GetBandsShift(), GetAppliedPrice(), _mode, _shift, GetPointer(this)); + _value = Indi_Bands::iBands(GetSymbol(), GetTf(), GetPeriod(), GetDeviation(), GetBandsShift(), + GetAppliedPrice(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - iparams.custom_indi_name, /* [ */ GetPeriod(), GetBandsShift(), GetDeviation(), - GetAppliedPrice() /* ] */, _mode, _shift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, /* [ */ GetPeriod(), + GetBandsShift(), GetDeviation(), GetAppliedPrice() /* ] */, _mode, _shift); break; case IDATA_INDICATOR: // Calculating bands value from specified indicator. - _value = Indi_Bands::iBandsOnIndicator(indi_src, Get(CHART_PARAM_SYMBOL), - Get(CHART_PARAM_TF), GetPeriod(), GetDeviation(), - GetBandsShift(), _mode, _shift, &this); + _value = Indi_Bands::iBandsOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), GetDeviation(), + GetBandsShift(), _mode, _shift, THIS_PTR); break; } istate.is_changed = false; @@ -300,8 +296,7 @@ class Indi_Bands : public Indicator { /** * Provides built-in indicators whose can be used as data source. */ - /* @fixme - virtual Indicator *FetchDataSource(ENUM_INDICATOR_TYPE _id) { + virtual IndicatorBase *FetchDataSource(ENUM_INDICATOR_TYPE _id) { if (_id == INDI_BANDS) { BandsParams bands_params(); return new Indi_Bands(bands_params); @@ -325,9 +320,8 @@ class Indi_Bands : public Indicator { return new Indi_StdDev(stddev_params); } - return Indicator::FetchDataSource(_id); + return IndicatorBase::FetchDataSource(_id); } - */ /* Getters */ diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index 18075cf03..e4b539968 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -66,7 +66,7 @@ class Indi_BearsPower : public Indicator { */ static double iBearsPower(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _applied_price, // (MT5): not used - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iBearsPower(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index 68be78530..b493f1bb8 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -66,7 +66,7 @@ class Indi_BullsPower : public Indicator { */ static double iBullsPower(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _applied_price, // (MT5): not used - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iBullsPower(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 0d769b2fc..ffec64f4f 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -71,7 +71,7 @@ class Indi_CCI : public Indicator { * - https://www.mql5.com/en/docs/indicators/icci */ static double iCCI(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _applied_price, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iCCI(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 9f0a60007..407700a8d 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -63,7 +63,7 @@ class Indi_CHO : public Indicator { */ static double iChaikin(string _symbol, ENUM_TIMEFRAMES _tf, int _fast_ma_period, int _slow_ma_period, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_VOLUME _av, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iChaikin(_symbol, _tf, _fast_ma_period, _slow_ma_period, _ma_method, _av), _mode, _shift); diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 608352cbc..42bbae1a4 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -63,8 +63,7 @@ class Indi_CHV : public Indicator { * Built-in version of Chaikin Volatility. */ static double iCHV(string _symbol, ENUM_TIMEFRAMES _tf, int _smooth_period, int _chv_period, - ENUM_CHV_SMOOTH_METHOD _smooth_method, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + ENUM_CHV_SMOOTH_METHOD _smooth_method, int _mode = 0, int _shift = 0, IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG( _symbol, _tf, Util::MakeKey("Indi_CHV", _smooth_period, _chv_period, _smooth_method)); return iCHVOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _smooth_period, _chv_period, _smooth_method, _mode, diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index c0ef8c5b0..4e25b15a8 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -52,7 +52,7 @@ class Indi_ColorBars : public Indicator { * "Built-in" version of Color Bars. */ static double iColorBars(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_ColorCandlesDaily"); return iColorBarsOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _shift, _cache); } diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index d80c3143c..d941b67ec 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -51,8 +51,7 @@ class Indi_ColorCandlesDaily : public Indicator { /** * "Built-in" version of Color Candles Daily. */ - static double iCCD(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + static double iCCD(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_ColorCandlesDaily"); return iCCDOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _shift, _cache); } diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index c9d8ae052..d74d080e7 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -53,7 +53,7 @@ class Indi_ColorLine : public Indicator { * "Built-in" version of Color Line. */ static double iColorLine(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_ColorLine"); Indi_MA *_indi_ma = Indi_MA::GetCached(_symbol, _tf, 10, 0, MODE_EMA, PRICE_CLOSE); @@ -87,12 +87,13 @@ class Indi_ColorLine : public Indicator { * OnCalculate() method for Color Line indicator. */ static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtColorLineBuffer, - ValueStorage &ExtColorsBuffer, Indi_ColorLine *ExtMAHandle) { + ValueStorage &ExtColorsBuffer, IndicatorBase *ExtMAHandle) { static int ticks = 0, modified = 0; // Check data. int i, calculated = BarsCalculated(ExtMAHandle, rates_total); if (calculated < rates_total) { // Not all data of ExtMAHandle is calculated. + Print("Not all MA data calculate for ColorLine! Expected ", rates_total, ", got only ", calculated); return (0); } // First calculation or number of bars was changed. diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index 13c7ab6b0..88c1cb3a0 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -36,6 +36,7 @@ struct CustomMovingAverageParams : IndicatorParams { max_modes = 3; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); + SetDataSourceType(IDATA_ICUSTOM); SetCustomIndicatorName("Examples\\Custom Moving Average"); shift = _shift; smooth_method = _smooth_method; diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 012e4add6..2625dc29c 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -89,8 +89,7 @@ class Indi_DEMA : public Indicator { * - https://www.mql5.com/en/docs/indicators/IDEMA */ static double iDEMA(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, unsigned int _ma_shift, - ENUM_APPLIED_PRICE _applied_price, int _shift = 0, int _mode = 0, - Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price, int _shift = 0, int _mode = 0, IndicatorBase *_obj = NULL) { ResetLastError(); #ifdef __MQL5__ int _handle = Object::IsValid(_obj) ? _obj.Get(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL; @@ -120,7 +119,7 @@ class Indi_DEMA : public Indicator { } return _res[0]; #else - Indi_Price *_indi_price = Indi_Price::GetCached(_symbol, _tf, _applied_price, _period, _shift); + Indi_Price *_indi_price = Indi_Price::GetCached(_symbol, _tf, _shift); // Note that _applied_price and Indi_Price mode indices are compatible. return Indi_DEMA::iDEMAOnIndicator(_indi_price.GetCache(), _indi_price, 0, _period, _ma_shift, _shift); #endif diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index 5da4c8a7e..58e160022 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -64,7 +64,7 @@ class Indi_DeMarker : public Indicator { * - https://www.mql5.com/en/docs/indicators/idemarker */ static double iDeMarker(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iDeMarker(_symbol, _tf, _period, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index 8df3b9606..1dbb97398 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -77,7 +77,7 @@ class Indi_Demo : public Indicator { * Returns the indicator value. */ static double iDemo(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { return 0.1 + (0.1 * _obj.GetBarIndex()); } diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 0b8b4cb32..deed98b25 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -57,7 +57,7 @@ class Indi_DetrendedPrice : public Indicator { * Built-in version of AMA. */ static double iDPO(string _symbol, ENUM_TIMEFRAMES _tf, int _period, ENUM_APPLIED_PRICE _ap, int _mode = 0, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_SHORT(_symbol, _tf, _ap, Util::MakeKey("Indi_DPO", _period, (int)_ap)); return iDPOOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_SHORT, _period, _mode, _shift, _cache); diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index 27059651d..e891597f7 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -160,7 +160,7 @@ class Indi_Drawer : public Indicator { /** * Calculates non-SMMA version of Drawer on another indicator (uses iDrawerOnArray). */ - static double iDrawerOnArrayOnIndicator(Indicator *_indi, string _symbol = NULL, + static double iDrawerOnArrayOnIndicator(IndicatorBase *_indi, string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, Indi_Drawer *_obj = NULL) { diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 8b03c7ac6..9c75e8e31 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -88,7 +88,7 @@ class Indi_Envelopes : public Indicator { int _ma_shift, ENUM_APPLIED_PRICE _ap, double _deviation, int _mode, // (MT4 _mode): 0 - MODE_MAIN, 1 - MODE_UPPER, 2 - MODE_LOWER; (MT5 _mode): 0 - // UPPER_LINE, 1 - LOWER_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { ResetLastError(); #ifdef __MQL4__ return ::iEnvelopes(_symbol, _tf, _ma_period, _ma_method, _ma_shift, _ap, _deviation, _mode, _shift); @@ -131,8 +131,8 @@ class Indi_Envelopes : public Indicator { #endif } - static double iEnvelopesOnIndicator(IndicatorCalculateCache *_cache, Indicator *_indi, - string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, + static double iEnvelopesOnIndicator(IndicatorCalculateCache *_cache, IndicatorBase *_indi, string _symbol, + ENUM_TIMEFRAMES _tf, int _ma_period, ENUM_MA_METHOD _ma_method, // (MT4/MT5): MODE_SMA, MODE_EMA, MODE_SMMA, MODE_LWMA int _indi_mode, // Source indicator's mode index. May be -1 to use first buffer int _ma_shift, double _deviation, diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index 255cee54e..da8b13ee1 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -80,7 +80,7 @@ class Indi_Force : public Indicator { * - https://www.mql5.com/en/docs/indicators/iforce */ static double iForce(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_MA_METHOD _ma_method, - ENUM_APPLIED_PRICE _applied_price, int _shift = 0, Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price, int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iForce(_symbol, _tf, _period, _ma_method, _applied_price, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 788a896e4..d885c15ab 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -59,7 +59,7 @@ class Indi_FrAMA : public Indicator { * Built-in version of FrAMA. */ static double iFrAMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, ENUM_APPLIED_PRICE _ap, - int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + int _mode = 0, int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iFrAMA(_symbol, _tf, _ma_period, _ma_shift, _ap), _mode, _shift); #else diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index a7e4f02d3..71a8a55a1 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -64,7 +64,7 @@ class Indi_Fractals : public Indicator { static double iFractals(string _symbol, ENUM_TIMEFRAMES _tf, ENUM_LO_UP_LINE _mode, // (MT4 _mode): 1 - MODE_UPPER, 2 - MODE_LOWER int _shift = 0, // (MT5 _mode): 0 - UPPER_LINE, 1 - LOWER_LINE - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iFractals(_symbol, _tf, _mode, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index 21d6e23b1..7588e765f 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -129,7 +129,7 @@ class Indi_Gator : public Indicator { static double iGator(string _symbol, ENUM_TIMEFRAMES _tf, int _jaw_period, int _jaw_shift, int _teeth_period, int _teeth_shift, int _lips_period, int _lips_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, ENUM_GATOR_HISTOGRAM _mode, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iGator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift, _ma_method, _applied_price, _mode, _shift); diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index c3394f188..5ffbf77e7 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -79,7 +79,7 @@ class Indi_HeikenAshi : public Indicator { * Returns value for iHeikenAshi indicator. */ static double iCustomLegacyHeikenAshi(string _symbol, ENUM_TIMEFRAMES _tf, string _name, int _mode, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ // Low and High prices could be in reverse order when using MT4's built-in indicator, so we need to retrieve both // and return correct one. diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index 7de03e1a9..fd9f4dea8 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -101,7 +101,7 @@ class Indi_Ichimoku : public Indicator { * - https://www.mql5.com/en/docs/indicators/iichimoku */ static double iIchimoku(string _symbol, ENUM_TIMEFRAMES _tf, int _tenkan_sen, int _kijun_sen, int _senkou_span_b, - int _mode, int _shift = 0, Indicator *_obj = NULL) { + int _mode, int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iIchimoku(_symbol, _tf, _tenkan_sen, _kijun_sen, _senkou_span_b, _mode, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index 42fb15701..30375285a 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -84,7 +84,7 @@ class Indi_MA : public Indicator { */ static double iMA(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _ma_period, unsigned int _ma_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_array, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { ResetLastError(); #ifdef __MQL4__ return ::iMA(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_array, _shift); @@ -121,7 +121,7 @@ class Indi_MA : public Indicator { /** * Calculates MA on another indicator. */ - static double iMAOnIndicator(IndicatorCalculateCache *cache, Indicator *indi, int indi_mode, + static double iMAOnIndicator(IndicatorCalculateCache *cache, IndicatorBase *indi, int indi_mode, string symbol, ENUM_TIMEFRAMES tf, unsigned int ma_period, unsigned int ma_shift, ENUM_MA_METHOD ma_method, // (MT4/MT5): MODE_SMA, MODE_EMA, MODE_SMMA, MODE_LWMA int shift = 0) { diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index e2e1eae55..2d42406a6 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -72,7 +72,7 @@ class Indi_MACD : public Indicator { string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _ema_fast_period, unsigned int _ema_slow_period, unsigned int _signal_period, ENUM_APPLIED_PRICE _applied_price, ENUM_SIGNAL_LINE _mode = LINE_MAIN, // (MT4/MT5 _mode): 0 - MODE_MAIN/MAIN_LINE, 1 - MODE_SIGNAL/SIGNAL_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iMACD(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price, _mode, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index ee55de93c..e3e8f815c 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -65,7 +65,7 @@ class Indi_MFI : public Indicator { * - https://www.mql5.com/en/docs/indicators/imfi */ static double iMFI(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iMFI(_symbol, _tf, _period, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index 67075ca6f..e4901872c 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -59,7 +59,7 @@ class Indi_MassIndex : public Indicator { * Built-in version of Mass Index. */ static double iMI(string _symbol, ENUM_TIMEFRAMES _tf, int _period, int _second_period, int _sum_period, - int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + int _mode = 0, int _shift = 0, IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG( _symbol, _tf, Util::MakeKey("Indi_MassIndex", _period, _second_period, _sum_period)); return iMIOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _period, _second_period, _sum_period, _mode, _shift, diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 731295f68..740049890 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -75,7 +75,7 @@ class Indi_Momentum : public Indicator { * - https://www.mql5.com/en/docs/indicators/imomentum */ static double iMomentum(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _ap, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iMomentum(_symbol, _tf, _period, _ap, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 943fe6e2a..06f73aa4f 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -68,7 +68,7 @@ class Indi_OBV : public Indicator { * Class constructor. */ Indi_OBV(OBVParams &_p) : Indicator(_p) {} - Indi_OBV(ENUM_TIMEFRAMES _tf) : Indicator(INDI_OBV, _tf) {} + Indi_OBV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_OBV, _tf) {} /** * Returns the indicator value. @@ -83,7 +83,7 @@ class Indi_OBV : public Indicator { #else ENUM_APPLIED_VOLUME _applied = VOLUME_TICK, // MT5 only. #endif - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iOBV(_symbol, _tf, _applied, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 26059dd2c..4d5306c96 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -69,7 +69,7 @@ class Indi_OsMA : public Indicator { */ static double iOsMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ema_fast_period, int _ema_slow_period, int _signal_period, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iOsMA(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index 242603a23..14d8f620e 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -38,10 +38,8 @@ enum ENUM_INDI_PRICE_MODE { // Structs. struct PriceIndiParams : IndicatorParams { - ENUM_APPLIED_PRICE applied_price; - // Struct constructor. - void PriceIndiParams(int _shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN) : applied_price(_ap) { + void PriceIndiParams(int _shift = 0) { itype = INDI_PRICE; max_modes = FINAL_INDI_PRICE_MODE; SetDataValueType(TYPE_DOUBLE); @@ -63,9 +61,8 @@ class Indi_Price : public Indicator { /** * Returns the indicator value. */ - static double iPrice(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, - Indi_Price *_obj = NULL) { - ENUM_APPLIED_PRICE _ap = _obj == NULL ? PRICE_MEDIAN : _obj.iparams.applied_price; + static double iPrice(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, + ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN, int _shift = 0, Indi_Price *_obj = NULL) { return ChartStatic::iPrice(_ap, _symbol, _tf, _shift); } @@ -118,18 +115,15 @@ class Indi_Price : public Indicator { /** * Returns already cached version of Indi_Price for a given parameters. */ - static Indi_Price *GetCached(string _symbol, ENUM_TIMEFRAMES _tf, ENUM_APPLIED_PRICE _applied_price, - unsigned int _period, int _shift) { + static Indi_Price *GetCached(string _symbol, ENUM_TIMEFRAMES _tf, int _shift) { String _cache_key; _cache_key.Add(_symbol); _cache_key.Add((int)_tf); - _cache_key.Add(_period); - _cache_key.Add((int)_applied_price); _cache_key.Add(_shift); string _key = _cache_key.ToString(); Indi_Price *_indi_price; if (!Objects::TryGet(_key, _indi_price)) { - PriceIndiParams _indi_price_params(_shift, _applied_price); + PriceIndiParams _indi_price_params(_shift); _indi_price_params.SetTf(_tf); _indi_price = Objects::Set(_key, new Indi_Price(_indi_price_params)); _indi_price.SetSymbol(_symbol); diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index 484184621..f3e7b498c 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -54,7 +54,7 @@ class Indi_PriceVolumeTrend : public Indicator { * Built-in version of Price Volume Trend. */ static double iPVT(string _symbol, ENUM_TIMEFRAMES _tf, ENUM_APPLIED_VOLUME _av, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, Util::MakeKey("Indi_PriceVolumeTrend", (int)_av)); return iPVTOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _av, _mode, _shift, _cache); } diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index 140f05ea9..c1d352bb3 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -57,17 +57,18 @@ class Indi_RS : public Indicator { void Init() { if (iparams.GetDataSourceType() == IDATA_MATH) { PriceIndiParams _iprice_params(); - // @fixit - Indi_Price *_iprice_close = Indi_Price::GetCached(NULL, 0, /*unused*/ PRICE_CLOSE, 0); + // @todo Symbol should be already defined for a chart. + // @todo If it's not, move initialization to GetValue()/GetEntry() method. + Indi_Price *_iprice = Indi_Price::GetCached(GetSymbol(), GetTf(), 0); MathParams _imath0_params(MATH_OP_SUB, PRICE_CLOSE, 0, PRICE_CLOSE, 1); - _imath0_params.SetDataSource(iprice.Ptr(), false); - Ref _imath0 = new Indi_Math(_imath0_params); - MathParams _imath1_params(MATH_OP_SUB, PRICE_CLOSE, 1, PRICE_CLOSE, 0); - _imath1_params.SetDataSource(iprice.Ptr(), false); + _imath0_params.SetTf(GetTf()); + _imath1_params.SetTf(GetTf()); + Ref _imath0 = new Indi_Math(_imath0_params); Ref _imath1 = new Indi_Math(_imath1_params); - + _imath0.Ptr().SetDataSource(_iprice, false, 0); + _imath1.Ptr().SetDataSource(_iprice, false, 0); imath.Set(0, _imath0); imath.Set(1, _imath1); } diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index b8233bf0f..d5aff005c 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -89,6 +89,8 @@ struct RSIGainLossData { * Implements the Relative Strength Index indicator. */ class Indi_RSI : public Indicator { + DictStruct aux_data; + public: /** * Class constructor. @@ -104,8 +106,7 @@ class Indi_RSI : public Indicator { * - https://www.mql5.com/en/docs/indicators/irsi */ static double iRSI(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, - ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, - Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iRSI(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ @@ -142,7 +143,7 @@ class Indi_RSI : public Indicator { * Calculates non-SMMA version of RSI on another indicator (uses iRSIOnArray). */ template - static double iRSIOnArrayOnIndicator(Indicator *_indi, string _symbol = NULL, + static double iRSIOnArrayOnIndicator(IndicatorBase *_indi, string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, Indi_RSI *_obj = NULL) { @@ -373,8 +374,7 @@ class Indi_RSI : public Indicator { /** * Provides built-in indicators whose can be used as data source. */ - /* @fixme - virtual Indicator *FetchDataSource(ENUM_INDICATOR_TYPE _id) { + virtual IndicatorBase *FetchDataSource(ENUM_INDICATOR_TYPE _id) { if (_id == INDI_BANDS) { BandsParams bands_params(); return new Indi_Bands(bands_params); @@ -398,7 +398,6 @@ class Indi_RSI : public Indicator { return new Indi_StdDev(stddev_params); } - return Indicator::FetchDataSource(_id); + return IndicatorBase::FetchDataSource(_id); } - */ }; diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index 3ec203c0f..e7b278129 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -65,7 +65,7 @@ class Indi_RVI : public Indicator { static double iRVI( string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 10, ENUM_SIGNAL_LINE _mode = LINE_MAIN, // (MT4/MT5): 0 - MODE_MAIN/MAIN_LINE, 1 - MODE_SIGNAL/SIGNAL_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iRVI(_symbol, _tf, _period, _mode, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index 634e4fa2d..3d8836c36 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -56,7 +56,7 @@ class Indi_RateOfChange : public Indicator { * Built-in version of Rate of Change. */ static double iROC(string _symbol, ENUM_TIMEFRAMES _tf, int _period, ENUM_APPLIED_PRICE _ap, int _mode = 0, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_SHORT(_symbol, _tf, _ap, Util::MakeKey("Indi_RateOfChange", _period, (int)_ap)); return iROCOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_SHORT, _period, _mode, _shift, _cache); diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 01efb5cde..bb08d262d 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -64,7 +64,7 @@ class Indi_SAR : public Indicator { * - https://www.mql5.com/en/docs/indicators/isar */ static double iSAR(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, double _step = 0.02, - double _max = 0.2, int _shift = 0, Indicator *_obj = NULL) { + double _max = 0.2, int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iSAR(_symbol, _tf, _step, _max, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index bf4a0fc28..4687dec08 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -81,7 +81,7 @@ class Indi_StdDev : public Indicator { * - https://www.mql5.com/en/docs/indicators/istddev */ static double iStdDev(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, ENUM_MA_METHOD _ma_method, - ENUM_APPLIED_PRICE _applied_price, int _shift = 0, Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _applied_price, int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iStdDev(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_price, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 2eb0c0e59..e498d9740 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -76,7 +76,7 @@ class Indi_Stochastic : public Indicator { ENUM_STO_PRICE _price_field, // (MT4 _price_field): 0 - Low/High, 1 - Close/Close // (MT5 _price_field): STO_LOWHIGH - Low/High, STO_CLOSECLOSE - Close/Close int _mode, // (MT4): 0 - MODE_MAIN/MAIN_LINE, 1 - MODE_SIGNAL/SIGNAL_LINE - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iStochastic(_symbol, _tf, _kperiod, _dperiod, _slowing, _ma_method, _price_field, _mode, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index a2dbceabb..8bb2141f9 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -59,7 +59,7 @@ class Indi_TRIX : public Indicator { * Built-in version of TriX. */ static double iTriX(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, ENUM_APPLIED_PRICE _ap, int _mode = 0, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iTriX(_symbol, _tf, _ma_period, _ap), _mode, _shift); #else diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 7efa85686..dbeaa1656 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -68,7 +68,7 @@ class Indi_UltimateOscillator : public Indicator { */ static double iUO(string _symbol, ENUM_TIMEFRAMES _tf, int _fast_period, int _middle_period, int _slow_period, int _fast_k, int _middle_k, int _slow_k, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG( _symbol, _tf, Util::MakeKey("Indi_UltimateOscillator", _fast_period, _middle_period, _slow_period, _fast_k, _middle_k, @@ -87,9 +87,8 @@ class Indi_UltimateOscillator : public Indicator { */ static double iUOOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _fast_period, int _middle_period, int _slow_period, int _fast_k, int _middle_k, int _slow_k, int _mode, int _shift, - IndicatorCalculateCache *_cache, Indicator *_indi_atr_fast, - Indicator *_indi_atr_middle, Indicator *_indi_atr_slow, - bool _recalculate = false) { + IndicatorCalculateCache *_cache, IndicatorBase *_indi_atr_fast, + IndicatorBase *_indi_atr_middle, IndicatorBase *_indi_atr_slow, bool _recalculate = false) { _cache.SetPriceBuffer(_open, _high, _low, _close); if (!_cache.HasBuffers()) { diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index f6552b639..ae77b51c0 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -63,7 +63,7 @@ class Indi_VIDYA : public Indicator { * Built-in version of iVIDyA. */ static double iVIDyA(string _symbol, ENUM_TIMEFRAMES _tf, int _cmo_period, int _ema_period, int _ma_shift, - ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, Indicator *_obj = NULL) { + ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iVIDyA(_symbol, _tf, _cmo_period, _ema_period, _ma_shift, _ap), _mode, _shift); #else diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index c2c46261c..a913707cf 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -56,7 +56,7 @@ class Indi_VROC : public Indicator { * Built-in version of VROC. */ static double iVROC(string _symbol, ENUM_TIMEFRAMES _tf, int _period, ENUM_APPLIED_VOLUME _av, int _mode = 0, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, Util::MakeKey("Indi_VROC", _period, (int)_av)); return iVROCOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _period, _av, _mode, _shift, _cache); } diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 59c9d8a2c..d7c700c8c 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -55,7 +55,7 @@ class Indi_Volumes : public Indicator { * Built-in version of Volumes. */ static double iVolumes(string _symbol, ENUM_TIMEFRAMES _tf, ENUM_APPLIED_VOLUME _av, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, Util::MakeKey("Indi_Volumes", (int)_av)); return iVolumesOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _av, _mode, _shift, _cache); } diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index c9ba23598..827c01c45 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -63,7 +63,7 @@ class Indi_WPR : public Indicator { * - https://www.mql5.com/en/docs/indicators/iwpr */ static double iWPR(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, - int _shift = 0, Indicator *_obj = NULL) { + int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL4__ return ::iWPR(_symbol, _tf, _period, _shift); #else // __MQL5__ diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index 2d11c07e9..a8d4345de 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -51,8 +51,7 @@ class Indi_WilliamsAD : public Indicator { /** * Built-in version of Williams' AD. */ - static double iWAD(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + static double iWAD(string _symbol, ENUM_TIMEFRAMES _tf, int _mode = 0, int _shift = 0, IndicatorBase *_obj = NULL) { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_symbol, _tf, "Indi_WilliamsAD"); return iWADOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _shift, _cache); } diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index 636b7f6c3..2a5f8b883 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -66,8 +66,7 @@ class Indi_ZigZag : public Indicator { * Returns value for ZigZag indicator. */ static double iCustomZigZag(string _symbol, ENUM_TIMEFRAMES _tf, string _name, int _depth, int _deviation, - int _backstep, ENUM_ZIGZAG_LINE _mode = 0, int _shift = 0, - Indicator *_obj = NULL) { + int _backstep, ENUM_ZIGZAG_LINE _mode = 0, int _shift = 0, IndicatorBase *_obj = NULL) { #ifdef __MQL5__ int _handle = Object::IsValid(_obj) ? _obj.Get(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL; double _res[]; diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 2fefe648a..46c38eea9 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -91,8 +91,8 @@ class Indi_Math : public Indicator { /** * Class constructor. */ - Indi_Math(MathParams &_params) : Indicator(_params) { }; - Indi_Math(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_SPECIAL_MATH, _tf) { }; + Indi_Math(MathParams &_params) : Indicator(_params){}; + Indi_Math(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_SPECIAL_MATH, _tf){}; /** * Returns the indicator's value. @@ -166,18 +166,17 @@ class Indi_Math : public Indicator { return _param; } - static double iMathOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, - ENUM_MATH_OP op, unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, + static double iMathOnIndicator(IndicatorBase *_indi, string _symbol, ENUM_TIMEFRAMES _tf, ENUM_MATH_OP op, + unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, unsigned int _shift_2, unsigned int _mode, int _shift, Indi_Math *_obj) { double _val_1 = _indi.GetValue(_shift_1, _mode_1); double _val_2 = _indi.GetValue(_shift_2, _mode_2); return Math::Op(op, _val_1, _val_2); } - static double iMathOnIndicator(Indicator *_indi, string _symbol, ENUM_TIMEFRAMES _tf, - MathCustomOpFunction _op, unsigned int _mode_1, unsigned int _mode_2, - unsigned int _shift_1, unsigned int _shift_2, unsigned int _mode, int _shift, - Indi_Math *_obj) { + static double iMathOnIndicator(IndicatorBase *_indi, string _symbol, ENUM_TIMEFRAMES _tf, MathCustomOpFunction _op, + unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, + unsigned int _shift_2, unsigned int _mode, int _shift, Indi_Math *_obj) { double _val_1 = _indi.GetValue(_shift_1, _mode_1); double _val_2 = _indi.GetValue(_shift_2, _mode_2); return _op(_val_1, _val_2); diff --git a/Indicators/indicators.h b/Indicators/indicators.h index 6f21660f0..3257db5d4 100644 --- a/Indicators/indicators.h +++ b/Indicators/indicators.h @@ -38,7 +38,7 @@ #include "Indi_AppliedPrice.mqh" #include "Indi_BWMFI.mqh" #include "Indi_BWZT.mqh" -//#include "Indi_Bands.mqh" +#include "Indi_Bands.mqh" #include "Indi_BearsPower.mqh" #include "Indi_BullsPower.mqh" #include "Indi_CCI.mqh" @@ -73,8 +73,8 @@ #include "Indi_PriceChannel.mqh" #include "Indi_PriceFeeder.mqh" #include "Indi_PriceVolumeTrend.mqh" -//#include "Indi_RS.mqh" -//#include "Indi_RSI.mqh" +#include "Indi_RS.mqh" +#include "Indi_RSI.mqh" #include "Indi_RVI.mqh" #include "Indi_RateOfChange.mqh" #include "Indi_SAR.mqh" diff --git a/Strategy.mqh b/Strategy.mqh index 7bf54dfbc..87d258ad4 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -93,7 +93,7 @@ class Strategy : public Object { Dict ddata; Dict fdata; Dict idata; - Dict *> indicators_unmanaged; // Indicators list (unmanaged). + Dict indicators_unmanaged; // Indicators list (unmanaged). DictStruct>> indicators_managed; // Indicators list (managed). DictStruct tasks; Log logger; // Log instance. @@ -159,7 +159,7 @@ class Strategy : public Object { * Class deconstructor. */ ~Strategy() { - for (DictIterator *> iter = indicators_unmanaged.Begin(); iter.IsValid(); ++iter) { + for (DictIterator iter = indicators_unmanaged.Begin(); iter.IsValid(); ++iter) { delete iter.Value(); } } @@ -308,7 +308,7 @@ class Strategy : public Object { /** * Returns handler to the strategy's indicator class. */ - Indicator *GetIndicator(int _id = 0) { + IndicatorBase *GetIndicator(int _id = 0) { if (indicators_managed.KeyExists(_id)) { return indicators_managed[_id].Ptr(); } else if (indicators_unmanaged.KeyExists(_id)) { @@ -588,7 +588,7 @@ class Strategy : public Object { * Sets reference to indicator. */ template - void SetIndicator(Indicator *_indi, int _id = 0, bool _managed = true) { + void SetIndicator(IndicatorBase *_indi, int _id = 0, bool _managed = true) { if (_managed) { Ref> _ref = _indi; indicators_managed.Set(_id, _ref); @@ -1268,7 +1268,7 @@ class Strategy : public Object { int _count = (int)fmax(fabs(_level), fabs(_method)); int _direction = Order::OrderDirection(_cmd, _mode); Chart *_chart = trade.GetChart(); - Indicator *_indi = GetIndicator(); + IndicatorBase *_indi = GetIndicator(); StrategyPriceStop _psm(_method); _psm.SetChartParams(_chart.GetParams()); if (Object::IsValid(_indi)) { diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index 70169de92..79efa002d 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -108,8 +108,8 @@ enum ENUM_CUSTOM_INDICATORS { INDI_SPECIAL_MATH_CUSTOM = FINAL_INDICATOR_TYPE_EN // Global variables. Chart *chart; -Dict indis; -Dict whitelisted_indis; +Dict indis; +Dict whitelisted_indis; Dict tested; int bar_processed; double test_values[] = {1.245, 1.248, 1.254, 1.264, 1.268, 1.261, 1.256, 1.250, 1.242, 1.240, 1.235, @@ -147,7 +147,7 @@ void OnTick() { if (indis.Size() == 0) { return; } - for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { + for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { if (whitelisted_indis.Size() == 0) { if (tested.GetByKey(iter.Key())) { // Indicator is already tested, skipping. @@ -159,7 +159,7 @@ void OnTick() { } } - Indicator *_indi = iter.Value(); + IndicatorBase *_indi = iter.Value(); _indi.OnTick(); IndicatorDataEntry _entry = _indi.GetEntry(); @@ -185,7 +185,7 @@ void OnDeinit(const int reason) { delete chart; - for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { + for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { delete iter.Value(); } @@ -225,7 +225,7 @@ bool InitIndicators() { // Bollinger Bands. BandsParams bands_params(20, 2, 0, PRICE_OPEN); - Indicator *indi_bands = new Indi_Bands(bands_params); + IndicatorBase *indi_bands = new Indi_Bands(bands_params); indis.Push(indi_bands); // Bollinger Bands over RSI. @@ -272,9 +272,7 @@ bool InitIndicators() { indis.Push(new Indi_Gator(gator_params)); // Heiken Ashi. -#ifdef __MQL5__ indis.Push(new Indi_HeikenAshi()); -#endif // Ichimoku Kinko Hyo. IchimokuParams ichi_params(9, 26, 52); @@ -282,17 +280,17 @@ bool InitIndicators() { // Moving Average. MAParams ma_params(13, 0, MODE_SMA, PRICE_OPEN); - Indicator *indi_ma = new Indi_MA(ma_params); + IndicatorBase *indi_ma = new Indi_MA(ma_params); indis.Push(indi_ma); // DEMA. DEMAParams dema_params(13, 2, PRICE_OPEN); - Indicator *indi_dema = new Indi_DEMA(dema_params); + IndicatorBase *indi_dema = new Indi_DEMA(dema_params); indis.Push(indi_dema); // MACD. MACDParams macd_params(12, 26, 9, PRICE_CLOSE); - Indicator *macd = new Indi_MACD(macd_params); + IndicatorBase *macd = new Indi_MACD(macd_params); indis.Push(macd); // Money Flow Index (MFI). @@ -332,12 +330,13 @@ bool InitIndicators() { indis.Push(new Indi_StdDev(stddev_params)); // Standard Deviation (StdDev). - Indicator *indi_price_for_stdev = new Indi_Price(PriceIndiParams()); + IndicatorBase *indi_price_for_stdev = new Indi_Price(PriceIndiParams()); StdDevParams stddev_on_price_params(); - stddev_on_price_params.SetDataSource(indi_price_for_stdev, true, PRICE_OPEN); stddev_on_price_params.SetDraw(clrBlue, 1); - indis.Push(new Indi_StdDev(stddev_on_price_params)); + Indi_StdDev *indi_stddev_on_price = new Indi_StdDev(stddev_on_price_params); + indi_stddev_on_price.SetDataSource(indi_price_for_stdev, true, PRICE_OPEN); + indis.Push(indi_stddev_on_price); // Stochastic Oscillator. StochParams stoch_params(5, 3, 3, MODE_SMMA, STO_LOWHIGH); @@ -359,85 +358,94 @@ bool InitIndicators() { // Current Price. PriceIndiParams price_params(); // price_params.SetDraw(clrAzure); - Indicator *indi_price = new Indi_Price(price_params); + IndicatorBase *indi_price = new Indi_Price(price_params); indis.Push(indi_price); // Bollinger Bands over Price indicator. PriceIndiParams price_params_4_bands(); - Indicator *indi_price_4_bands = new Indi_Price(price_params_4_bands); + IndicatorBase *indi_price_4_bands = new Indi_Price(price_params_4_bands); BandsParams bands_on_price_params(); bands_on_price_params.SetDraw(clrCadetBlue); - bands_on_price_params.SetDataSource(indi_price_4_bands, true, INDI_PRICE_MODE_OPEN); - indis.Push(new Indi_Bands(bands_on_price_params)); + Indi_Bands *indi_bands_on_price = new Indi_Bands(bands_on_price_params); + indi_bands_on_price.SetDataSource(indi_price_4_bands, true, INDI_PRICE_MODE_OPEN); + indis.Push(indi_bands_on_price); // Standard Deviation (StdDev) over MA(SMA). // NOTE: If you set ma_shift parameter for MA, then StdDev will no longer // match built-in StdDev indicator (as it doesn't use ma_shift for averaging). MAParams ma_sma_params_for_stddev(); - Indicator *indi_ma_sma_for_stddev = new Indi_MA(ma_sma_params_for_stddev); + IndicatorBase *indi_ma_sma_for_stddev = new Indi_MA(ma_sma_params_for_stddev); StdDevParams stddev_params_on_ma_sma(13, 10); stddev_params_on_ma_sma.SetDraw(true, 1); - stddev_params_on_ma_sma.SetDataSource(indi_ma_sma_for_stddev, true, 0); - indis.Push(new Indi_StdDev(stddev_params_on_ma_sma)); + + Indi_StdDev *indi_stddev_on_ma_sma = new Indi_StdDev(stddev_params_on_ma_sma); + indi_stddev_on_ma_sma.SetDataSource(indi_ma_sma_for_stddev, true, 0); + indis.Push(indi_stddev_on_ma_sma); // Standard Deviation (StdDev) in SMA mode over Price. PriceIndiParams price_params_for_stddev_sma(); - Indicator *indi_price_for_stddev_sma = new Indi_Price(price_params_for_stddev_sma); + IndicatorBase *indi_price_for_stddev_sma = new Indi_Price(price_params_for_stddev_sma); StdDevParams stddev_sma_on_price_params(); stddev_sma_on_price_params.SetDraw(true, 1); - stddev_sma_on_price_params.SetDataSource(indi_price_for_stddev_sma, true, INDI_PRICE_MODE_OPEN); - indis.Push(new Indi_StdDev(stddev_sma_on_price_params)); + Indi_StdDev *indi_stddev_on_sma = new Indi_StdDev(stddev_sma_on_price_params); + indi_stddev_on_sma.SetDataSource(indi_price_for_stddev_sma, true, INDI_PRICE_MODE_OPEN); + indis.Push(indi_stddev_on_sma); // Moving Average (MA) over Price indicator. PriceIndiParams price_params_4_ma(); - Indicator *indi_price_4_ma = new Indi_Price(price_params_4_ma); + IndicatorBase *indi_price_4_ma = new Indi_Price(price_params_4_ma); MAParams ma_on_price_params(13, 0, MODE_SMA, PRICE_OPEN, 0); ma_on_price_params.SetDraw(clrYellowGreen); - ma_on_price_params.SetDataSource(indi_price_4_ma, true, INDI_PRICE_MODE_OPEN); ma_on_price_params.SetIndicatorType(INDI_MA_ON_PRICE); - indis.Push(new Indi_MA(ma_on_price_params)); + Indi_MA *indi_ma_on_price = new Indi_MA(ma_on_price_params); + indi_ma_on_price.SetDataSource(indi_price_4_ma, true, INDI_PRICE_MODE_OPEN); + indis.Push(indi_ma_on_price); // Commodity Channel Index (CCI) over Price indicator. PriceIndiParams price_params_4_cci(); - Indicator *indi_price_4_cci = new Indi_Price(price_params_4_cci); + IndicatorBase *indi_price_4_cci = new Indi_Price(price_params_4_cci); CCIParams cci_on_price_params(); cci_on_price_params.SetDraw(clrYellowGreen, 1); - cci_on_price_params.SetDataSource(indi_price_4_cci, true, INDI_PRICE_MODE_OPEN); - Indicator *indi_cci_on_price = new Indi_CCI(cci_on_price_params); + IndicatorBase *indi_cci_on_price = new Indi_CCI(cci_on_price_params); + indi_cci_on_price.SetDataSource(indi_price_4_cci, true, INDI_PRICE_MODE_OPEN); indis.Push(indi_cci_on_price); // Envelopes over Price indicator. PriceIndiParams price_params_4_envelopes(); - Indicator *indi_price_4_envelopes = new Indi_Price(price_params_4_envelopes); + IndicatorBase *indi_price_4_envelopes = new Indi_Price(price_params_4_envelopes); EnvelopesParams env_on_price_params(); - env_on_price_params.SetDataSource(indi_price_4_envelopes, true, INDI_PRICE_MODE_OPEN); env_on_price_params.SetDraw(clrBrown); - indis.Push(new Indi_Envelopes(env_on_price_params)); + Indi_Envelopes *indi_envelopes_on_price = new Indi_Envelopes(env_on_price_params); + indi_envelopes_on_price.SetDataSource(indi_price_4_envelopes, true, INDI_PRICE_MODE_OPEN); + indis.Push(indi_envelopes_on_price); // DEMA over Price indicator. PriceIndiParams price_params_4_dema(); - Indicator *indi_price_4_dema = new Indi_Price(price_params_4_dema); + IndicatorBase *indi_price_4_dema = new Indi_Price(price_params_4_dema); DEMAParams dema_on_price_params(13, 2, PRICE_OPEN); - dema_on_price_params.SetDataSource(indi_price_4_dema, true, INDI_PRICE_MODE_OPEN); dema_on_price_params.SetDraw(clrRed); - indis.Push(new Indi_DEMA(dema_on_price_params)); + Indi_DEMA *indi_dema_on_price = new Indi_DEMA(dema_on_price_params); + indi_dema_on_price.SetDataSource(indi_price_4_dema, true, INDI_PRICE_MODE_OPEN); + indis.Push(indi_dema_on_price); // Momentum over Price indicator. - Indicator *indi_price_4_momentum = new Indi_Price(); + IndicatorBase *indi_price_4_momentum = new Indi_Price(); MomentumParams mom_on_price_params(); - mom_on_price_params.SetDataSource(indi_price_4_momentum); mom_on_price_params.SetDraw(clrDarkCyan); - indis.Push(new Indi_Momentum(mom_on_price_params)); + Indi_Momentum *indi_momentum_on_price = new Indi_Momentum(mom_on_price_params); + indi_momentum_on_price.SetDataSource(indi_price_4_momentum, true, 0); + indis.Push(indi_momentum_on_price); // Relative Strength Index (RSI) over Price indicator. PriceIndiParams price_params_4_rsi(); - Indicator *indi_price_4_rsi = new Indi_Price(price_params_4_rsi); + IndicatorBase *indi_price_4_rsi = new Indi_Price(price_params_4_rsi); RSIParams rsi_on_price_params(); - rsi_on_price_params.SetDataSource(indi_price_4_rsi, true, INDI_PRICE_MODE_OPEN); rsi_on_price_params.SetDraw(clrBisque, 1); - indis.Push(new Indi_RSI(rsi_on_price_params)); + Indi_RSI *indi_rsi_on_price = new Indi_RSI(rsi_on_price_params); + indi_rsi_on_price.SetDataSource(indi_price_4_rsi, true, INDI_PRICE_MODE_OPEN); + indis.Push(indi_rsi_on_price); // Drawer (socket-based) indicator. DrawerParams drawer_params(14, /*unused*/ PRICE_OPEN); @@ -450,8 +458,9 @@ bool InitIndicators() { AppliedPriceParams applied_price_params(); applied_price_params.SetDraw(clrAquamarine, 0); PriceIndiParams applied_price_price_params; - applied_price_params.SetDataSource(new Indi_Price(applied_price_price_params), PRICE_TYPICAL); - indis.Push(new Indi_AppliedPrice(applied_price_params)); + Indi_AppliedPrice *indi_applied_price_on_price = new Indi_AppliedPrice(applied_price_params); + indi_applied_price_on_price.SetDataSource(new Indi_Price(applied_price_price_params), true, PRICE_TYPICAL); + indis.Push(indi_applied_price_on_price); // ADXW. ADXWParams adxw_params(14); @@ -479,9 +488,7 @@ bool InitIndicators() { // Color Line. ColorLineParams color_line_params(); -#ifdef __MQL5__ indis.Push(new Indi_ColorLine(color_line_params)); -#endif // Detrended Price Oscillator. DetrendedPriceParams detrended_params(); @@ -491,8 +498,8 @@ bool InitIndicators() { MassIndexParams mass_index_params(); indis.Push(new Indi_MassIndex(mass_index_params)); - // Price Channel. #ifdef __MQL5__ + // Price Channel. PriceChannelParams price_channel_params(); indis.Push(new Indi_PriceChannel(price_channel_params)); #endif @@ -503,9 +510,7 @@ bool InitIndicators() { // Bill Williams' Zone Trade. BWZTParams bwzt_params(); -#ifdef __MQL5__ indis.Push(new Indi_BWZT(bwzt_params)); -#endif // Rate of Change. RateOfChangeParams rate_of_change_params(); @@ -521,9 +526,7 @@ bool InitIndicators() { // Ultimate Oscillator. UltimateOscillatorParams ultimate_oscillator_params(); -#ifdef __MQL5__ indis.Push(new Indi_UltimateOscillator(ultimate_oscillator_params)); -#endif // VIDYA. VIDYAParams vidya_params(); @@ -531,9 +534,7 @@ bool InitIndicators() { // Volumes. VolumesParams volumes_params(); -#ifdef __MQL5__ indis.Push(new Indi_Volumes(volumes_params)); -#endif // Volume Rate of Change. VROCParams vol_rate_of_change_params(); @@ -543,31 +544,33 @@ bool InitIndicators() { WilliamsADParams williams_ad_params(); indis.Push(new Indi_WilliamsAD(williams_ad_params)); -// ZigZag Color. #ifdef __MQL5__ + // ZigZag Color. ZigZagColorParams zigzag_color_params(); indis.Push(new Indi_ZigZagColor(zigzag_color_params)); #endif -// Custom Moving Average. #ifdef __MQL5__ + // Custom Moving Average. CustomMovingAverageParams cma_params(); indis.Push(new Indi_CustomMovingAverage(cma_params)); #endif // Math (specialized indicator). MathParams math_params(MATH_OP_SUB, BAND_UPPER, BAND_LOWER, 0, 0); - math_params.SetDataSource(indi_bands, false, 0); math_params.SetDraw(clrBlue); math_params.SetName("Bands(UP - LO)"); - indis.Push(new Indi_Math(math_params)); + Indi_Math *indi_math_1 = new Indi_Math(math_params); + indi_math_1.SetDataSource(indi_bands, false, 0); + indis.Push(indi_math_1); // Math (specialized indicator) via custom math method. MathParams math_custom_params(MathCustomOp, BAND_UPPER, BAND_LOWER, 0, 0); - math_custom_params.SetDataSource(indi_bands, false, 0); math_custom_params.SetDraw(clrBeige); math_custom_params.SetName("Bands(Custom math fn)"); - indis.Push(new Indi_Math(math_custom_params)); + Indi_Math *indi_math_2 = new Indi_Math(math_custom_params); + indi_math_2.SetDataSource(indi_bands, false, 0); + indis.Push(indi_math_2); // RS (Math-based) indicator. RSParams rs_params(); @@ -586,7 +589,7 @@ bool InitIndicators() { indis.Push(new Indi_Candle(candle_params)); // Mark all as untested. - for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { + for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { tested.Set(iter.Key(), false); } @@ -602,13 +605,13 @@ double MathCustomOp(double a, double b) { return 1.11 + (b - a) * 2.0; } * Print indicators. */ bool PrintIndicators(string _prefix = "") { - for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { + for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { if (whitelisted_indis.Size() != 0 && !whitelisted_indis.Contains(iter.Value())) { continue; } - Indicator *_indi = iter.Value(); - string _indi_name = _indi.GetName(); + IndicatorBase *_indi = iter.Value(); + string _indi_name = _indi.GetFullName(); MqlParam _value = _indi.GetEntryValue(); if (GetLastError() == ERR_INDICATOR_DATA_NOT_FOUND || GetLastError() == ERR_USER_ERROR_FIRST + ERR_USER_INVALID_BUFF_NUM) { From a986fe897e6e6f5aca8b9be302e700c7ca6ac5fe Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Fri, 1 Oct 2021 15:30:02 +0200 Subject: [PATCH 22/78] WIP. Stalled with iVolumes. --- Indicator.struct.cache.h | 5 +++++ IndicatorBase.h | 6 +++++- Indicators/Indi_ColorLine.mqh | 2 +- Indicators/Indi_HeikenAshi.mqh | 21 +++++++++++++++++++-- Indicators/Indi_Volumes.mqh | 14 ++++++++++++-- tests/IndicatorsTest.mq5 | 7 +++++-- 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Indicator.struct.cache.h b/Indicator.struct.cache.h index 209983beb..69a652eb4 100644 --- a/Indicator.struct.cache.h +++ b/Indicator.struct.cache.h @@ -113,6 +113,11 @@ class IndicatorCalculateCache : public Dynamic { */ bool HasBuffers() { return ArraySize(buffers) != 0; } + /** + * Returns number of added buffers. + */ + int NumBuffers() { return ArraySize(buffers); } + /** * Returns existing or new cache as a child of current one. Useful when indicator uses other indicators and requires * unique caches for them. diff --git a/IndicatorBase.h b/IndicatorBase.h index 1f4dd7d38..9cca8daf5 100644 --- a/IndicatorBase.h +++ b/IndicatorBase.h @@ -1182,11 +1182,15 @@ int CopyBuffer(IndicatorBase* _indi, int _mode, int _start, int _count, ValueSto /** * BarsCalculated() method to be used on Indicator instance. */ -int BarsCalculated(IndicatorBase* _indi, int _bars_required) { +int BarsCalculated(IndicatorBase* _indi, int _bars_required, int _bars_at_least = -1) { if (_bars_required == 0) { return _bars_required; } + if (_bars_at_least != -1) { + _bars_required = _bars_at_least; + } + IndicatorDataEntry _entry = _indi.GetEntry(_bars_required - 1); // GetEntry() could end up with an error. It is okay. ResetLastError(); diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index d74d080e7..9503ddf4b 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -91,7 +91,7 @@ class Indi_ColorLine : public Indicator { static int ticks = 0, modified = 0; // Check data. int i, calculated = BarsCalculated(ExtMAHandle, rates_total); - if (calculated < rates_total) { + if (calculated < rates_total && calculated < 1000) { // Not all data of ExtMAHandle is calculated. Print("Not all MA data calculate for ColorLine! Expected ", rates_total, ", got only ", calculated); return (0); diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index 5ffbf77e7..5381364e1 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -159,8 +159,8 @@ class Indi_HeikenAshi : public Indicator { /** * OnCalculate() method for Mass Index indicator. */ - static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtLBuffer, - ValueStorage &ExtHBuffer, ValueStorage &ExtOBuffer, + static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtOBuffer, + ValueStorage &ExtHBuffer, ValueStorage &ExtLBuffer, ValueStorage &ExtCBuffer, ValueStorage &ExtColorBuffer) { int start; // Preliminary calculations. @@ -199,6 +199,23 @@ class Indi_HeikenAshi : public Indicator { double _value = EMPTY_VALUE; switch (iparams.idstype) { case IDATA_BUILTIN: +#ifdef __MQL4__ + // Converting MQL4's enum into MQL5 one, as OnCalculate uses further one. + switch (_mode) { + case HA_OPEN: + _mode = (ENUM_HA_MODE)0; + break; + case HA_HIGH: + _mode = (ENUM_HA_MODE)1; + break; + case HA_LOW: + _mode = (ENUM_HA_MODE)2; + break; + case HA_CLOSE: + _mode = (ENUM_HA_MODE)3; + break; + } +#endif _value = Indi_HeikenAshi::iHeikenAshi(GetSymbol(), GetTf(), _mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index d7c700c8c..21f8b4ba8 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -78,6 +78,10 @@ class Indi_Volumes : public Indicator { _cache.SetPrevCalculated(Indi_Volumes::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _cache.GetBuffer(1), _av)); + for (int i = 0; i < _cache.NumBuffers(); ++i) { + Print("(Mode #", _mode, ", Buffer #", i, " = ", _cache.GetTailValue(i, _shift)); + } + return _cache.GetTailValue(_mode, _shift); } @@ -87,6 +91,7 @@ class Indi_Volumes : public Indicator { static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtVolumesBuffer, ValueStorage &ExtColorsBuffer, ENUM_APPLIED_VOLUME InpVolumeType) { if (rates_total < 2) return (0); + // Starting work. int pos = prev_calculated - 1; // Correct position. @@ -94,6 +99,7 @@ class Indi_Volumes : public Indicator { ExtVolumesBuffer[0] = 0; pos = 1; } + // Main cycle. if (InpVolumeType == VOLUME_TICK) CalculateVolume(pos, rates_total, tick_volume, ExtVolumesBuffer, ExtColorsBuffer); @@ -113,6 +119,8 @@ class Indi_Volumes : public Indicator { // Calculate indicator. ExtVolumesBuffer[i] = curr_volume; ExtColorsBuffer[i] = (curr_volume > prev_volume) ? 0.0 : 1.0; + + Print("Volume: ", ExtVolumesBuffer[i].Get(), ", ", ExtColorsBuffer[i].Get()); } } @@ -150,9 +158,11 @@ class Indi_Volumes : public Indicator { } else { _entry.timestamp = GetBarTime(_shift); for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); + double _v = GetValue(_mode, _shift); + _entry.values[_mode] = _v; + Print("Volumes[", _mode, "] = ", _v); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index 79efa002d..13b3879f9 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -510,7 +510,7 @@ bool InitIndicators() { // Bill Williams' Zone Trade. BWZTParams bwzt_params(); - indis.Push(new Indi_BWZT(bwzt_params)); + // indis.Push(new Indi_BWZT(bwzt_params)); // Rate of Change. RateOfChangeParams rate_of_change_params(); @@ -526,15 +526,18 @@ bool InitIndicators() { // Ultimate Oscillator. UltimateOscillatorParams ultimate_oscillator_params(); - indis.Push(new Indi_UltimateOscillator(ultimate_oscillator_params)); + // indis.Push(new Indi_UltimateOscillator(ultimate_oscillator_params)); // VIDYA. VIDYAParams vidya_params(); indis.Push(new Indi_VIDYA(vidya_params)); +#ifdef __MQL5__ + // @fixit Should work also in MT4! // Volumes. VolumesParams volumes_params(); indis.Push(new Indi_Volumes(volumes_params)); +#endif // Volume Rate of Change. VROCParams vol_rate_of_change_params(); From f6782232dbb4fbbb930c5c328e625f2d6db6b1b5 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 14:23:01 +0100 Subject: [PATCH 23/78] Trade: Adds TradeSignalManager class --- Trade/TradeSignal.h | 15 ++- Trade/TradeSignal.struct.h | 39 +++---- Trade/TradeSignalManager.h | 134 +++++++++++++++++++++++++ Trade/tests/TradeSignalManagerTest.mq4 | 28 ++++++ Trade/tests/TradeSignalManagerTest.mq5 | 62 ++++++++++++ Trade/tests/TradeSignalTest.mq5 | 1 - 6 files changed, 256 insertions(+), 23 deletions(-) create mode 100644 Trade/TradeSignalManager.h create mode 100644 Trade/tests/TradeSignalManagerTest.mq4 create mode 100644 Trade/tests/TradeSignalManagerTest.mq5 diff --git a/Trade/TradeSignal.h b/Trade/TradeSignal.h index 3c98c7362..7a48524f5 100644 --- a/Trade/TradeSignal.h +++ b/Trade/TradeSignal.h @@ -39,7 +39,9 @@ class TradeSignal { /** * Class constructor. */ - TradeSignal(const TradeSignalEntry &_signal) : signal(_signal) {} + TradeSignal() {} + TradeSignal(const TradeSignalEntry &_entry) : signal(_entry) {} + TradeSignal(const TradeSignal &_signal) : signal(_signal.GetSignal()) {} /* Getters */ @@ -53,9 +55,14 @@ class TradeSignal { */ template TV Get(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop) { - signal.Get(_prop); + return signal.Get(_prop); } + /** + * Gets a signal entry. + */ + TradeSignalEntry GetSignal() const { return signal; } + /* Setters */ /** @@ -154,7 +161,7 @@ class TradeSignal { /* Serializers */ /** - * Serialize an instance class. + * Serializes this class. * * @return * Returns a JSON serialized instance. @@ -165,7 +172,7 @@ class TradeSignal { } /** - * Converts the signal to a string. + * Converts this class into a string. * * @return * Returns a JSON serialized signal. diff --git a/Trade/TradeSignal.struct.h b/Trade/TradeSignal.struct.h index cc6c478f2..99bfd23ee 100644 --- a/Trade/TradeSignal.struct.h +++ b/Trade/TradeSignal.struct.h @@ -27,24 +27,26 @@ // Includes. #include "../Serializer.mqh" +#include "../SerializerConverter.mqh" +#include "../SerializerJson.mqh" // Defines. -#define SIGNAL_CLOSE_BUY_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_SIGNAL) -#define SIGNAL_CLOSE_BUY_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN) #define SIGNAL_CLOSE_BUY_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER) +#define SIGNAL_CLOSE_BUY_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN) +#define SIGNAL_CLOSE_BUY_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_BUY_SIGNAL) #define SIGNAL_CLOSE_DOWNWARDS STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_DOWNWARDS) -#define SIGNAL_CLOSE_SELL_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_SIGNAL) -#define SIGNAL_CLOSE_SELL_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN) #define SIGNAL_CLOSE_SELL_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER) +#define SIGNAL_CLOSE_SELL_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN) +#define SIGNAL_CLOSE_SELL_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_SELL_SIGNAL) #define SIGNAL_CLOSE_TIME_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER) #define SIGNAL_CLOSE_UPWARDS STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_CLOSE_UPWARDS) -#define SIGNAL_OPEN_BUY_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_SIGNAL) -#define SIGNAL_OPEN_BUY_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN) #define SIGNAL_OPEN_BUY_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER) +#define SIGNAL_OPEN_BUY_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN) +#define SIGNAL_OPEN_BUY_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_BUY_SIGNAL) #define SIGNAL_OPEN_DOWNWARDS STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_DOWNWARDS) -#define SIGNAL_OPEN_SELL_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_SIGNAL) -#define SIGNAL_OPEN_SELL_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN) #define SIGNAL_OPEN_SELL_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER) +#define SIGNAL_OPEN_SELL_MAIN STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN) +#define SIGNAL_OPEN_SELL_SIGNAL STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_SELL_SIGNAL) #define SIGNAL_OPEN_TIME_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER) #define SIGNAL_OPEN_UPWARDS STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_UPWARDS) @@ -62,17 +64,18 @@ struct TradeSignalEntry { // Enumeration for strategy bitwise signal flags. enum ENUM_TRADE_SIGNAL_FLAG { TRADE_SIGNAL_FLAG_NONE = 0 << 0, - TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN = 1 << 0, // Main signal for close buy - TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER = 1 << 1, // Filter for close buy - TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN = 1 << 2, // Main signal for close sell - TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER = 1 << 3, // Filter for close sell + TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER = 1 << 0, // Filter for close buy + TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN = 1 << 1, // Main signal for close buy + TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER = 1 << 2, // Filter for close sell + TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN = 1 << 3, // Main signal for close sell TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER = 1 << 4, // Time filter to close - TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN = 1 << 5, // Main signal for close buy + TRADE_SIGNAL_FLAG_EXPIRED = 1 << 5, // Signal expired TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER = 1 << 6, // Filter for close buy - TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN = 1 << 7, // Main signal for close sell + TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN = 1 << 7, // Main signal for close buy TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER = 1 << 8, // Filter for close sell - TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER = 1 << 9, // Time filter to open - TRADE_SIGNAL_FLAG_PROCESSED = 1 << 10, // Signal proceed + TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN = 1 << 9, // Main signal for close sell + TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER = 1 << 10, // Time filter to open + TRADE_SIGNAL_FLAG_PROCESSED = 1 << 11, // Signal proceed // Pre-defined signal conditions. TRADE_SIGNAL_FLAG_CLOSE_BUY_SIGNAL = TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN ^ (TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER), @@ -112,7 +115,7 @@ struct TradeSignalEntry { /* Getters */ template T Get(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop) { - switch (_param) { + switch (_prop) { case TRADE_SIGNAL_PROP_SIGNALS: return (T)signals; case TRADE_SIGNAL_PROP_STRENGTH: @@ -129,7 +132,7 @@ struct TradeSignalEntry { /* Setters */ template void Set(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop, T _value) { - switch (_param) { + switch (_prop) { case TRADE_SIGNAL_PROP_SIGNALS: signals = (unsigned int)_value; return; diff --git a/Trade/TradeSignalManager.h b/Trade/TradeSignalManager.h new file mode 100644 index 000000000..30227f961 --- /dev/null +++ b/Trade/TradeSignalManager.h @@ -0,0 +1,134 @@ +//+------------------------------------------------------------------+ +//| 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 . + * + */ + +/** + * @file + * Implements TradeSignalManager class. + */ + +// Includes. +#include "../DictObject.mqh" +#include "TradeSignal.h" + +/** + * Class to store and manage a trading signal. + */ +class TradeSignalManager : Dynamic { + protected: + DictObject signals_active; + DictObject signals_expired; + DictObject signals_processed; + + public: + /** + * Class constructor. + */ + TradeSignalManager() {} + + /* Getters */ + + /** + * Gets an iterator instance. + * + */ + DictObjectIterator GetIterSignalsActive() { + DictObjectIterator _iter = signals_active.Begin(); + return _iter; + } + + /** + * Gets pointer to active signals. + * + */ + DictObject *GetSignalsActive() { return &signals_active; } + + /** + * Gets pointer to expired signals. + * + */ + DictObject *GetSignalsExpired() { return &signals_expired; } + + /** + * Gets pointer to processed signals. + * + */ + DictObject *GetSignalsProcessed() { return &signals_processed; } + + /* Setters */ + + /* Signal methods */ + + /** + * Adds new signal. + * + */ + void SignalAdd(TradeSignal &_signal) { signals_active.Push(_signal); } + + /** + * Refresh signals. + * + * Move already processed signals or expired to different list. + * + */ + void Refresh() { + for (DictObjectIterator iter = GetIterSignalsActive(); iter.IsValid(); ++iter) { + TradeSignal *_signal = iter.Value(); + if (_signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED))) { + signals_active.Unset(iter.Key()); + signals_processed.Push(_signal); + continue; + } + if (_signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_EXPIRED))) { + signals_active.Unset(iter.Key()); + signals_expired.Push(_signal); + continue; + } + } + } + + /* Serializers */ + + SERIALIZER_EMPTY_STUB; + + /** + * Serializes this class. + * + * @return + * Returns a JSON serialized instance. + */ + SerializerNodeType Serialize(Serializer &_s) { + _s.PassObject(THIS_REF, "signals_active", signals_active); + return SerializerNodeObject; + } + + /** + * Converts this class into a string. + * + * @return + * Returns a JSON serialized signal. + */ + string ToString() { + // SerializerConverter _stub = SerializerConverter::MakeStubObject(SERIALIZER_FLAG_SKIP_HIDDEN); + return SerializerConverter::FromObject(THIS_REF, SERIALIZER_FLAG_SKIP_HIDDEN) + .ToString(SERIALIZER_JSON_NO_WHITESPACES); + } +}; diff --git a/Trade/tests/TradeSignalManagerTest.mq4 b/Trade/tests/TradeSignalManagerTest.mq4 new file mode 100644 index 000000000..c199b1143 --- /dev/null +++ b/Trade/tests/TradeSignalManagerTest.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of TradeSignalManager class. + */ + +// Includes. +#include "TradeSignalManagerTest.mq5" diff --git a/Trade/tests/TradeSignalManagerTest.mq5 b/Trade/tests/TradeSignalManagerTest.mq5 new file mode 100644 index 000000000..10131d2c1 --- /dev/null +++ b/Trade/tests/TradeSignalManagerTest.mq5 @@ -0,0 +1,62 @@ +//+------------------------------------------------------------------+ +//| 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 . + */ + +/** + * @file + * Test functionality of TradeSignalManager class. + */ + +// Includes. +#include "../../Test.mqh" +#include "../TradeSignalManager.h" + +// Test signals for processing. +bool TestSignalsProcessed() { + bool _result = true; + TradeSignalManager _tsm; + for (int i = 0; i < 10; i++) { + TradeSignalEntry _entry(i % 2 == 0 ? SIGNAL_OPEN_BUY_MAIN : SIGNAL_OPEN_SELL_MAIN); + TradeSignal _signal(_entry); + _tsm.SignalAdd(_signal); + } + _result &= _tsm.GetSignalsActive().Size() == 10; + Print(_tsm.ToString()); + for (DictObjectIterator iter = _tsm.GetIterSignalsActive(); iter.IsValid(); ++iter) { + TradeSignal *_signal = iter.Value(); + // Set signal as processed. + _signal.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); + } + _tsm.Refresh(); + // @fixme: // _result &= _tsm.GetSignalsActive().Size() == 0; + // @fixme: // _result &= _tsm.GetSignalsExpired().Size() == 0; + _result &= _tsm.GetSignalsProcessed().Size() == 10; + Print(_tsm.ToString()); + return _result; +} + +/** + * Implements OnInit(). + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(_result &= TestSignalsProcessed(), "Fail!"); + return _result && GetLastError() == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED; +} diff --git a/Trade/tests/TradeSignalTest.mq5 b/Trade/tests/TradeSignalTest.mq5 index f732a015e..e1f18adb3 100644 --- a/Trade/tests/TradeSignalTest.mq5 +++ b/Trade/tests/TradeSignalTest.mq5 @@ -26,7 +26,6 @@ // Includes. #include "../../Test.mqh" -#include "../../Trade.mqh" #include "../TradeSignal.h" // Test signals to close buy trade with filters. From db1a3051c906a3fabcd816798470d949bdec59d4 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 15:53:17 +0100 Subject: [PATCH 24/78] TradeSignal: TradeSignalEntry: Adds magic number --- Trade/TradeSignal.struct.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Trade/TradeSignal.struct.h b/Trade/TradeSignal.struct.h index 99bfd23ee..2e3ed1789 100644 --- a/Trade/TradeSignal.struct.h +++ b/Trade/TradeSignal.struct.h @@ -56,6 +56,7 @@ struct TradeSignalEntry { ENUM_TIMEFRAMES tf; // Timeframe. float strength; // Signal strength. float weight; // Signal weight. + long magic_id; // Magic identifier. unsigned int signals; // Store signals (@see: ENUM_TRADE_SIGNAL_FLAG). public: @@ -94,6 +95,7 @@ struct TradeSignalEntry { // Enumeration for strategy signal properties. enum ENUM_TRADE_SIGNAL_PROP { + TRADE_SIGNAL_PROP_MAGIC_ID, TRADE_SIGNAL_PROP_SIGNALS, TRADE_SIGNAL_PROP_STRENGTH, TRADE_SIGNAL_PROP_TF, @@ -107,15 +109,18 @@ struct TradeSignalEntry { }; /* Constructor */ - TradeSignalEntry(unsigned int _signals, float _strength = 0.0f) - : signals(_signals), strength(_strength), tf(PERIOD_CURRENT), weight(0.0f) {} - TradeSignalEntry(ENUM_TIMEFRAMES _tf = NULL, float _strength = 0.0f, float _weight = 0.0f) - : signals(0), strength(_strength), tf(_tf), weight(_weight) {} + TradeSignalEntry(unsigned int _signals, float _strength = 0.0f, long _magic_id = 0) + : magic_id(_magic_id), signals(_signals), strength(_strength), tf(PERIOD_CURRENT), weight(0.0f) {} + TradeSignalEntry(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, long _magic_id = 0, float _strength = 0.0f, + float _weight = 0.0f) + : magic_id(_magic_id), signals(0), strength(_strength), tf(_tf), weight(_weight) {} TradeSignalEntry(const TradeSignalEntry &_entry) { this = _entry; } /* Getters */ template T Get(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop) { switch (_prop) { + case TRADE_SIGNAL_PROP_MAGIC_ID: + return (T)magic_id; case TRADE_SIGNAL_PROP_SIGNALS: return (T)signals; case TRADE_SIGNAL_PROP_STRENGTH: @@ -133,6 +138,9 @@ struct TradeSignalEntry { template void Set(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop, T _value) { switch (_prop) { + case TRADE_SIGNAL_PROP_MAGIC_ID: + magic_id = (long)_value; + return; case TRADE_SIGNAL_PROP_SIGNALS: signals = (unsigned int)_value; return; From 07f4515fbe35c9eca20f2d776e243490cd9348d2 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 16:27:46 +0100 Subject: [PATCH 25/78] EA/Strategy/Trade: Integrates TradeSignalManager with EA and Strategy --- EA.mqh | 136 ++++++++++++++++++++++++++++--------- Strategy.enum.h | 3 +- Strategy.mqh | 80 +++++++--------------- Strategy.struct.h | 89 +++++++++++++----------- Trade/TradeSignal.struct.h | 8 +-- tests/StrategyTest-RSI.mq5 | 7 +- 6 files changed, 185 insertions(+), 138 deletions(-) diff --git a/EA.mqh b/EA.mqh index 5c39db312..412db9734 100644 --- a/EA.mqh +++ b/EA.mqh @@ -49,6 +49,8 @@ #include "Task.mqh" #include "Terminal.mqh" #include "Trade.mqh" +#include "Trade/TradeSignal.h" +#include "Trade/TradeSignalManager.h" class EA { protected: @@ -72,6 +74,7 @@ class EA { EAParams eparams; EAProcessResult eresults; EAState estate; + TradeSignalManager tsm; public: /** @@ -126,6 +129,57 @@ class EA { return trade.GetByKey(_symbol != NULL ? _symbol : _Symbol).Get(_state); } + /** + * Process strategy's signal entry. + * + * @param bool _should_open + * True if method should open the orders, otherwise only process the signals. + * @param bool _should_close + * True if method should close the orders, otherwise only process the signals. + * @param int _shift + * Bar shift. + * + * @return + * Returns StrategySignal struct. + */ + TradeSignalEntry GetStrategySignalEntry(Strategy *_strat, bool _trade_allowed = true, int _shift = -1) { + // float _bf = 1.0; + // float _ls = 0; + float _scl = _strat.Get(STRAT_PARAM_SCL); + float _sol = _strat.Get(STRAT_PARAM_SOL); + int _scfm = _strat.Get(STRAT_PARAM_SCFM); + int _scft = _strat.Get(STRAT_PARAM_SCFT); + int _scm = _strat.Get(STRAT_PARAM_SCM); + int _sob = _strat.Get(STRAT_PARAM_SOB); + int _sofm = _strat.Get(STRAT_PARAM_SOFM); + int _soft = _strat.Get(STRAT_PARAM_SOFT); + int _som = _strat.Get(STRAT_PARAM_SOM); + int _ss = _shift >= 0 ? _shift : _strat.Get(STRAT_PARAM_SHIFT); + unsigned int _signals = 0; + // StrategySignal _signal(THIS_PTR, trade.Get(CHART_PARAM_TF), + // sparams.Get(STRAT_PARAM_WEIGHT)); + if (_trade_allowed) { + // Process boost factor and lot size. + // sresult.SetBoostFactor(sparams.IsBoosted() ? SignalOpenBoost(ORDER_TYPE_BUY, _sob) : 1.0f); + // sresult.SetLotSize(sparams.GetLotSizeWithFactor()); + // Process open signals when trade is allowed. + _signals |= _strat.SignalOpen(ORDER_TYPE_BUY, _som, _sol, _ss) ? SIGNAL_OPEN_BUY_MAIN : 0; + _signals |= !_strat.SignalOpenFilterMethod(ORDER_TYPE_BUY, _sofm) ? SIGNAL_OPEN_BUY_FILTER : 0; + _signals |= _strat.SignalOpen(ORDER_TYPE_SELL, _som, _sol, _ss) ? SIGNAL_OPEN_SELL_MAIN : 0; + _signals |= !_strat.SignalOpenFilterMethod(ORDER_TYPE_SELL, _sofm) ? SIGNAL_OPEN_SELL_FILTER : 0; + _signals |= !_strat.SignalOpenFilterTime(_soft) ? SIGNAL_OPEN_TIME_FILTER : 0; + } + // Process close signals. + _signals |= _strat.SignalClose(ORDER_TYPE_BUY, _scm, _scl, _ss) ? SIGNAL_CLOSE_BUY_MAIN : 0; + _signals |= !_strat.SignalCloseFilter(ORDER_TYPE_BUY, _scfm) ? SIGNAL_CLOSE_BUY_FILTER : 0; + _signals |= _strat.SignalClose(ORDER_TYPE_SELL, _scm, _scl, _ss) ? SIGNAL_CLOSE_SELL_MAIN : 0; + _signals |= !_strat.SignalCloseFilter(ORDER_TYPE_SELL, _scfm) ? SIGNAL_CLOSE_SELL_FILTER : 0; + _signals |= !_strat.SignalCloseFilterTime(_scfm) ? SIGNAL_OPEN_TIME_FILTER : 0; + TradeSignalEntry _sentry(_signals, _strat.Get(STRAT_PARAM_TF), _strat.Get(STRAT_PARAM_ID)); + _sentry.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_STRENGTH), _strat.SignalOpen(_sofm, _sol, _ss)); + return _sentry; + } + /* Setters */ /** @@ -192,32 +246,37 @@ class EA { bool _result = true; int _last_error = ERR_NO_ERROR; ResetLastError(); - DictStruct _ds = strat_signals.GetByKey(_tick.time); - for (DictStructIterator _dsi = _ds.Begin(); _dsi.IsValid(); ++_dsi) { - StrategySignal _signal = _dsi.Value(); - if (_signal.CheckSignals(STRAT_SIGNAL_PROCESSED)) { + // DictStruct _ds = strat_signals.GetByKey(_tick.time); + for (DictObjectIterator _iter = tsm.GetIterSignalsActive(); _iter.IsValid(); ++_iter) { + bool _result_local = true; + TradeSignal *_signal = _iter.Value(); + if (_signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED))) { // Ignores already processed signals. - // @todo: Not in use yet. continue; } - Strategy *_strat = _signal.GetStrategy(); + // Strategy *_strat = _signal.GetStrategy(); Trade *_trade = trade.GetByKey(_Symbol); + Strategy *_strat = + strats.GetByKey(_signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID))).Ptr(); + // _signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID)), if (_trade.Get(TRADE_STATE_ORDERS_ACTIVE)) { float _sig_close = _signal.GetSignalClose(); + string _comment_close = + _strat != NULL && _sig_close != 0.0f ? _strat.GetOrderCloseComment() : __FUNCTION_LINE__; // Check if we should close the orders. if (_sig_close >= 0.5f) { // Close signal for buy order. - _result &= _trade.OrdersCloseViaProp2( - ORDER_MAGIC, _strat.Get(STRAT_PARAM_ID), ORDER_TYPE, ORDER_TYPE_BUY, MATH_COND_EQ, - ORDER_REASON_CLOSED_BY_SIGNAL, _strat.GetOrderCloseComment()); + _trade.OrdersCloseViaProp2( + ORDER_MAGIC, _signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID)), ORDER_TYPE, + ORDER_TYPE_BUY, MATH_COND_EQ, ORDER_REASON_CLOSED_BY_SIGNAL, _comment_close); // Buy orders closed. _strat.OnOrderClose(ORDER_TYPE_BUY); } if (_sig_close <= -0.5f) { // Close signal for sell order. - _result &= _trade.OrdersCloseViaProp2( - ORDER_MAGIC, _strat.Get(STRAT_PARAM_ID), ORDER_TYPE, ORDER_TYPE_SELL, MATH_COND_EQ, - ORDER_REASON_CLOSED_BY_SIGNAL, _strat.GetOrderCloseComment()); + _trade.OrdersCloseViaProp2( + ORDER_MAGIC, _signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID)), ORDER_TYPE, + ORDER_TYPE_SELL, MATH_COND_EQ, ORDER_REASON_CLOSED_BY_SIGNAL, _comment_close); // Sell orders closed. _strat.OnOrderClose(ORDER_TYPE_SELL); } @@ -225,15 +284,17 @@ class EA { if (_trade_allowed) { float _sig_open = _signal.GetSignalOpen(); unsigned int _sig_f = eparams.Get(STRUCT_ENUM(EAParams, EA_PARAM_PROP_SIGNAL_FILTER)); + string _comment_open = _strat != NULL && _sig_open != 0.0f ? _strat.GetOrderOpenComment() : __FUNCTION_LINE__; // Open orders on signals. if (_sig_open >= 0.5f) { // Open signal for buy. // When H1 or H4 signal filter is enabled, do not open minute-based orders on opposite or neutral signals. - if (_sig_f == 0 || GetSignalOpenFiltered(_signal, _sig_f) >= 0.5f) { - _strat.Set(TRADE_PARAM_ORDER_COMMENT, _strat.GetOrderOpenComment("B:")); + if (_sig_f == 0) { // || GetSignalOpenFiltered(_signal, _sig_f) >= 0.5f) { + _strat.Set(TRADE_PARAM_ORDER_COMMENT, _comment_open); // Buy order open. - _result &= TradeRequest(ORDER_TYPE_BUY, _Symbol, _strat); - if (_result && eparams.CheckSignalFilter(STRUCT_ENUM(EAParams, EA_PARAM_SIGNAL_FILTER_FIRST))) { + _result_local &= TradeRequest(ORDER_TYPE_BUY, _Symbol, _strat); + if (_result_local && eparams.CheckSignalFilter(STRUCT_ENUM(EAParams, EA_PARAM_SIGNAL_FILTER_FIRST))) { + _signal.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); break; } } @@ -241,16 +302,19 @@ class EA { if (_sig_open <= -0.5f) { // Open signal for sell. // When H1 or H4 signal filter is enabled, do not open minute-based orders on opposite or neutral signals. - if (_sig_f == 0 || GetSignalOpenFiltered(_signal, _sig_f) <= -0.5f) { - _strat.Set(TRADE_PARAM_ORDER_COMMENT, _strat.GetOrderOpenComment("S:")); + if (_sig_f == 0) { // || GetSignalOpenFiltered(_signal, _sig_f) <= -0.5f) { + _strat.Set(TRADE_PARAM_ORDER_COMMENT, _comment_open); // Sell order open. - _result &= TradeRequest(ORDER_TYPE_SELL, _Symbol, _strat); - if (_result && eparams.CheckSignalFilter(STRUCT_ENUM(EAParams, EA_PARAM_SIGNAL_FILTER_FIRST))) { + _result_local &= TradeRequest(ORDER_TYPE_SELL, _Symbol, _strat); + if (_result_local && eparams.CheckSignalFilter(STRUCT_ENUM(EAParams, EA_PARAM_SIGNAL_FILTER_FIRST))) { + _signal.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); break; } } } - if (!_result) { + if (_result_local) { + _signal.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); + } else { _last_error = GetLastError(); switch (_last_error) { case ERR_NOT_ENOUGH_MEMORY: @@ -262,13 +326,15 @@ class EA { } } } + _result &= _result_local; } _last_error = GetLastError(); if (_last_error > 0) { logger.Warning(StringFormat("Processing signals failed! Code: %d", _last_error), __FUNCTION_LINE__); } // Remove signals after processing. - strat_signals.Unset(_tick.time); + // strat_signals.Unset(_tick.time); + tsm.Refresh(); return _result && _last_error == 0; } @@ -328,20 +394,24 @@ class EA { _can_trade &= _can_trade && !_strat.IsSuspended(); _can_trade &= _can_trade && !_strat.CheckCondition(STRAT_COND_TRADE_COND, TRADE_COND_HAS_STATE, TRADE_STATE_TRADE_CANNOT); - StrategySignal _signal = _strat.ProcessSignals(_can_trade); - if (_signal.GetSignalClose() != _signal.GetSignalOpen()) { - SignalAdd(_signal, _tick.time); + TradeSignalEntry _sentry = GetStrategySignalEntry(_strat, _can_trade, _strat.Get(STRAT_PARAM_SHIFT)); + if (_sentry.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_SIGNALS)) > 0) { + TradeSignal _signal(_sentry); + if (_signal.GetSignalClose() != _signal.GetSignalOpen()) { + tsm.SignalAdd(_signal); //, _tick.time); + } + StgProcessResult _strat_result = _strat.GetProcessResult(); + eresults.last_error = fmax(eresults.last_error, _strat_result.last_error); + eresults.stg_errored += (int)_strat_result.last_error > ERR_NO_ERROR; + eresults.stg_processed++; } - StgProcessResult _strat_result = _strat.GetProcessResult(); - eresults.last_error = fmax(eresults.last_error, _strat_result.last_error); - eresults.stg_errored += (int)_strat_result.last_error > ERR_NO_ERROR; - eresults.stg_processed++; + /* + */ } } } // Process all strategies' signals and trigger trading orders. - ProcessSignals(GetMarket().GetLastTick(), - eparams.Get(STRUCT_ENUM(EAParams, EA_PARAM_PROP_SIGNAL_FILTER))); + ProcessSignals(_tick, eparams.Get(STRUCT_ENUM(EAParams, EA_PARAM_PROP_SIGNAL_FILTER))); if (eresults.last_error > ERR_NO_ERROR) { // On error, print logs. logger.Flush(); @@ -574,6 +644,7 @@ class EA { * @return * Returns 1 when buy signal exists, -1 for sell, otherwise 0 for neutral signal. */ + /* @fixme: Convert into TradeSignal format. float GetSignalOpenFiltered(StrategySignal &_signal, unsigned int _sf) { float _result = _signal.GetSignalOpen(); ENUM_TIMEFRAMES _sig_tf = _signal.Get(STRUCT_ENUM(StrategySignal, STRATEGY_SIGNAL_PROP_TF)); @@ -600,15 +671,18 @@ class EA { } return _result; } + */ /** * Adds strategy's signal for further processing. */ + /* bool SignalAdd(StrategySignal &_signal, long _time) { DictStruct _ds = strat_signals.GetByKey(_time); _ds.Push(_signal); return strat_signals.Set(_time, _ds); } + */ /* Tasks */ diff --git a/Strategy.enum.h b/Strategy.enum.h index c9c3b36b7..fc5aeef66 100644 --- a/Strategy.enum.h +++ b/Strategy.enum.h @@ -80,7 +80,8 @@ enum ENUM_STRATEGY_PARAM { STRAT_PARAM_PPM, // Signal profit method STRAT_PARAM_PSL, // Price stop level STRAT_PARAM_PSM, // Price stop method - STRAT_PARAM_SCF, // Signal close filter + STRAT_PARAM_SCFM, // Signal close filter method + STRAT_PARAM_SCFT, // Signal close filter time STRAT_PARAM_SCL, // Signal close level STRAT_PARAM_SCM, // Signal close method STRAT_PARAM_SHIFT, // Shift diff --git a/Strategy.mqh b/Strategy.mqh index 84af95675..1acb68173 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -100,8 +100,8 @@ class Strategy : public Object { MqlTick last_tick; StgProcessResult sresult; Strategy *strat_sl, *strat_tp; // Strategy pointers for stop-loss and profit-take. - StrategySignal last_signals; // Last signals. Trade trade; // Trade instance. + // TradeSignalEntry last_signal; // Last signals. private: // Strategy statistics. @@ -166,53 +166,6 @@ class Strategy : public Object { /* Processing methods */ - /** - * Process strategy's signals. - * - * @param bool _should_open - * True if method should open the orders, otherwise only process the signals. - * @param bool _should_close - * True if method should close the orders, otherwise only process the signals. - * @param int _shift - * Bar shift. - * - * @return - * Returns StrategySignal struct. - */ - StrategySignal ProcessSignals(bool _trade_allowed = true, int _shift = -1) { - // float _bf = 1.0; - // float _ls = 0; - int _ss = _shift >= 0 ? _shift : sparams.shift; - StrategySignal _signal(THIS_PTR, trade.Get(CHART_PARAM_TF), - sparams.Get(STRAT_PARAM_WEIGHT)); - if (_trade_allowed) { - float _sol = sparams.Get(STRAT_PARAM_SOL); - int _sob = sparams.Get(STRAT_PARAM_SOB); - int _sofm = sparams.Get(STRAT_PARAM_SOFM); - int _soft = sparams.Get(STRAT_PARAM_SOFT); - int _som = sparams.Get(STRAT_PARAM_SOM); - // Process boost factor and lot size. - // sresult.SetBoostFactor(sparams.IsBoosted() ? SignalOpenBoost(ORDER_TYPE_BUY, _sob) : 1.0f); - // sresult.SetLotSize(sparams.GetLotSizeWithFactor()); - // Process open signals when trade is allowed. - _signal.SetSignal(STRAT_SIGNAL_OPEN_BUY, SignalOpen(ORDER_TYPE_BUY, _som, _sol, _ss)); - _signal.SetSignal(STRAT_SIGNAL_OPEN_BUY_PASS, SignalOpenFilterMethod(ORDER_TYPE_BUY, _sofm)); - _signal.SetSignal(STRAT_SIGNAL_OPEN_SELL, SignalOpen(ORDER_TYPE_SELL, _som, _sol, _ss)); - _signal.SetSignal(STRAT_SIGNAL_OPEN_SELL_PASS, SignalOpenFilterMethod(ORDER_TYPE_SELL, _sofm)); - _signal.SetSignal(STRAT_SIGNAL_TIME_PASS, SignalOpenFilterTime(_soft)); - } - // Process close signals. - float _scl = sparams.Get(STRAT_PARAM_SCL); - int _scf = sparams.Get(STRAT_PARAM_SCF); - int _scm = sparams.Get(STRAT_PARAM_SCM); - _signal.SetSignal(STRAT_SIGNAL_CLOSE_BUY, SignalClose(ORDER_TYPE_BUY, _scm, _scl, _ss)); - _signal.SetSignal(STRAT_SIGNAL_CLOSE_BUY_PASS, SignalCloseFilter(ORDER_TYPE_BUY, _scf)); - _signal.SetSignal(STRAT_SIGNAL_CLOSE_SELL, SignalClose(ORDER_TYPE_SELL, _scm, _scl, _ss)); - _signal.SetSignal(STRAT_SIGNAL_CLOSE_SELL_PASS, SignalCloseFilter(ORDER_TYPE_SELL, _scf)); - last_signals = _signal; - return _signal; - } - /** * Process strategy's signals and orders. * @@ -224,7 +177,7 @@ class Strategy : public Object { */ StgProcessResult Process(unsigned short _periods_started = DATETIME_NONE) { sresult.last_error = ERR_NO_ERROR; - last_signals = ProcessSignals(); + // last_signal = ProcessSignals(); if (_periods_started > 0) { ProcessTasks(); } @@ -369,9 +322,9 @@ class Strategy : public Object { } /** - * Get strategy's last signals. + * Get strategy's last signal entry. */ - StrategySignal GetLastSignals() { return last_signals; } + // TradeSignalEntry GetLastSignalEntry() { return last_signal; } /** * Gets pointer to strategy's stop-loss strategy. @@ -1122,7 +1075,7 @@ class Strategy : public Object { */ virtual float SignalOpen(int _method = 0, float _level = 0.0f, int _shift = 0) { // @todo - return false; + return 0.0f; }; /** @@ -1154,6 +1107,25 @@ class Strategy : public Object { return _result; } + /** + * Checks strategy's trade's close signal time filter. + * + * @param + * _method - method to filter a closing trade (bitwise AND operation) + * + * @result bool + * Returns true if trade should be closed, otherwise false. + */ + virtual bool SignalCloseFilterTime(int _method = 0) { + bool _result = true; + if (_method != 0) { + MarketTimeForex _mtf(::TimeGMT()); + _result &= _mtf.CheckHours(_method); // 0-127 + _method = _method > 0 ? _method : !_method; // -127-127 + } + return _result; + } + /** * Checks strategy's trade's open signal time filter. * @@ -1161,7 +1133,7 @@ class Strategy : public Object { * _method - method to filter a trade (bitwise AND operation) * * @result bool - * Returns true when trade should be opened, otherwise false. + * Returns true if trade should be opened, otherwise false. */ virtual bool SignalOpenFilterTime(int _method = 0) { bool _result = true; @@ -1324,8 +1296,6 @@ class Strategy : public Object { SerializerNodeType Serialize(Serializer &_s) { _s.PassStruct(THIS_REF, "strat-params", sparams); _s.PassStruct(THIS_REF, "strat-results", sresult, SERIALIZER_FIELD_FLAG_DYNAMIC); - _s.PassStruct(THIS_REF, "strat-signals", last_signals, - SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE); return SerializerNodeObject; } }; diff --git a/Strategy.struct.h b/Strategy.struct.h index 482822bbd..4af31a374 100644 --- a/Strategy.struct.h +++ b/Strategy.struct.h @@ -43,38 +43,39 @@ class Trade; /* Structure for strategy parameters. */ struct StgParams { // Strategy config parameters. - bool is_enabled; // State of the strategy (whether enabled or not). - bool is_suspended; // State of the strategy (whether suspended or not) - bool is_boosted; // State of the boost feature (to increase lot size). - float weight; // Weight of the strategy. - long order_close_time; // Order close time in mins (>0) or bars (<0). - float order_close_loss; // Order close loss (in pips). - float order_close_profit; // Order close profit (in pips). - int signal_open_method; // Signal open method. - float signal_open_level; // Signal open level. - int signal_open_filter_method; // Signal open filter method. - int signal_open_filter_time; // Signal open filter time. - int signal_open_boost; // Signal open boost method (for lot size increase). - int signal_close_method; // Signal close method. - float signal_close_level; // Signal close level. - int signal_close_filter; // Signal close filter method. - int price_profit_method; // Price profit method. - float price_profit_level; // Price profit level. - int price_stop_method; // Price stop method. - float price_stop_level; // Price stop level. - int tick_filter_method; // Tick filter. - float trend_threshold; // Trend strength threshold. - float lot_size; // Lot size to trade. - float lot_size_factor; // Lot size multiplier factor. - float max_risk; // Maximum risk to take (1.0 = normal, 2.0 = 2x). - float max_spread; // Maximum spread to trade (in pips). - int tp_max; // Hard limit on maximum take profit (in pips). - int sl_max; // Hard limit on maximum stop loss (in pips). - int type; // Strategy type (@see: ENUM_STRATEGY). - long id; // Unique identifier of the strategy. - datetime refresh_time; // Order refresh frequency (in sec). - short shift; // Shift (relative to the current bar, 0 - default) - ChartTf tf; // Main timeframe where strategy operates on. + bool is_enabled; // State of the strategy (whether enabled or not). + bool is_suspended; // State of the strategy (whether suspended or not) + bool is_boosted; // State of the boost feature (to increase lot size). + float weight; // Weight of the strategy. + long order_close_time; // Order close time in mins (>0) or bars (<0). + float order_close_loss; // Order close loss (in pips). + float order_close_profit; // Order close profit (in pips). + int signal_open_method; // Signal open method. + float signal_open_level; // Signal open level. + int signal_open_filter_method; // Signal open filter method. + int signal_open_filter_time; // Signal open filter time. + int signal_open_boost; // Signal open boost method (for lot size increase). + int signal_close_method; // Signal close method. + float signal_close_level; // Signal close level. + int signal_close_filter_method; // Signal close filter method. + int signal_close_filter_time; // Signal close filter method. + int price_profit_method; // Price profit method. + float price_profit_level; // Price profit level. + int price_stop_method; // Price stop method. + float price_stop_level; // Price stop level. + int tick_filter_method; // Tick filter. + float trend_threshold; // Trend strength threshold. + float lot_size; // Lot size to trade. + float lot_size_factor; // Lot size multiplier factor. + float max_risk; // Maximum risk to take (1.0 = normal, 2.0 = 2x). + float max_spread; // Maximum spread to trade (in pips). + int tp_max; // Hard limit on maximum take profit (in pips). + int sl_max; // Hard limit on maximum stop loss (in pips). + int type; // Strategy type (@see: ENUM_STRATEGY). + long id; // Unique identifier of the strategy. + datetime refresh_time; // Order refresh frequency (in sec). + short shift; // Shift (relative to the current bar, 0 - default) + ChartTf tf; // Main timeframe where strategy operates on. // Constructor. StgParams() : id(rand()), @@ -92,7 +93,8 @@ struct StgParams { signal_open_boost(0), signal_close_method(0), signal_close_level(0), - signal_close_filter(0), + signal_close_filter_method(0), + signal_close_filter_time(0), price_profit_method(0), price_profit_level(0), price_stop_method(0), @@ -118,7 +120,7 @@ struct StgParams { signal_open_level(_sol), signal_open_boost(_sob), signal_close_method(_scm), - signal_close_filter(_scf), + signal_close_filter_method(_scf), signal_close_level(_scl), price_profit_method(_psm), price_profit_level(_psl), @@ -138,9 +140,7 @@ struct StgParams { sl_max(0), type(0), refresh_time(0) {} - StgParams(StgParams &_stg_params) { - this = _stg_params; - } + StgParams(StgParams &_stg_params) { this = _stg_params; } // Deconstructor. ~StgParams() {} @@ -180,8 +180,10 @@ struct StgParams { return (T)signal_open_filter_time; case STRAT_PARAM_SOB: return (T)signal_open_boost; - case STRAT_PARAM_SCF: - return (T)signal_close_filter; + case STRAT_PARAM_SCFM: + return (T)signal_close_filter_method; + case STRAT_PARAM_SCFT: + return (T)signal_close_filter_time; case STRAT_PARAM_SCM: return (T)signal_close_method; case STRAT_PARAM_SHIFT: @@ -260,8 +262,11 @@ struct StgParams { case STRAT_PARAM_SOB: // Signal open boost method signal_open_boost = (int)_value; return; - case STRAT_PARAM_SCF: // Signal close filter - signal_close_filter = (int)_value; + case STRAT_PARAM_SCFM: // Signal close filter method + signal_close_filter_method = (int)_value; + return; + case STRAT_PARAM_SCFT: // Signal close filter time + signal_close_filter_time = (int)_value; return; case STRAT_PARAM_SCM: // Signal close method signal_close_method = (int)_value; @@ -336,6 +341,8 @@ struct StgParams { s.Pass(THIS_REF, "soft", signal_open_filter_time); s.Pass(THIS_REF, "sob", signal_open_boost); s.Pass(THIS_REF, "scm", signal_close_method); + s.Pass(THIS_REF, "scfm", signal_close_filter_method); + s.Pass(THIS_REF, "scft", signal_close_filter_time); s.Pass(THIS_REF, "scl", signal_close_level); s.Pass(THIS_REF, "ppm", price_profit_method); s.Pass(THIS_REF, "ppl", price_profit_level); diff --git a/Trade/TradeSignal.struct.h b/Trade/TradeSignal.struct.h index 2e3ed1789..6473dcd28 100644 --- a/Trade/TradeSignal.struct.h +++ b/Trade/TradeSignal.struct.h @@ -109,11 +109,9 @@ struct TradeSignalEntry { }; /* Constructor */ - TradeSignalEntry(unsigned int _signals, float _strength = 0.0f, long _magic_id = 0) - : magic_id(_magic_id), signals(_signals), strength(_strength), tf(PERIOD_CURRENT), weight(0.0f) {} - TradeSignalEntry(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, long _magic_id = 0, float _strength = 0.0f, - float _weight = 0.0f) - : magic_id(_magic_id), signals(0), strength(_strength), tf(_tf), weight(_weight) {} + TradeSignalEntry(unsigned int _signals = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, long _magic_id = 0, + float _strength = 0.0f, float _weight = 0.0f) + : magic_id(_magic_id), signals(_signals), strength(_strength), tf(_tf), weight(_weight) {} TradeSignalEntry(const TradeSignalEntry &_entry) { this = _entry; } /* Getters */ template diff --git a/tests/StrategyTest-RSI.mq5 b/tests/StrategyTest-RSI.mq5 index 77b7ffa8a..d9842b7da 100644 --- a/tests/StrategyTest-RSI.mq5 +++ b/tests/StrategyTest-RSI.mq5 @@ -106,14 +106,11 @@ int OnInit() { */ void OnTick() { if (stg_rsi.TickFilter(SymbolInfoStatic::GetTick(_Symbol), 1)) { - StrategySignal _signal = stg_rsi.ProcessSignals(); - if (_signal.CheckSignals(STRAT_SIGNAL_OPEN_BUY)) { - assertTrueOrExit(_signal.GetOpenDirection() == 1, "Wrong order open direction!"); + if (stg_rsi.SignalOpen(ORDER_TYPE_BUY)) { MqlTradeRequest _request = trade.GetTradeOpenRequest(ORDER_TYPE_BUY, 0, stg_rsi.Get(STRAT_PARAM_ID), stg_rsi.GetName()); trade.RequestSend(_request); - } else if (_signal.CheckSignals(STRAT_SIGNAL_OPEN_SELL)) { - assertTrueOrExit(_signal.GetOpenDirection() == -1, "Wrong order open direction!"); + } else if (stg_rsi.SignalOpen(ORDER_TYPE_SELL)) { MqlTradeRequest _request = trade.GetTradeOpenRequest(ORDER_TYPE_SELL, 0, stg_rsi.Get(STRAT_PARAM_ID), stg_rsi.GetName()); trade.RequestSend(_request); From 0103bef29fbdb94b584daa917021704c566f95ee Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 18:09:32 +0100 Subject: [PATCH 26/78] StrategyTest-RSI: Fixes test --- tests/StrategyTest-RSI.mq5 | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/StrategyTest-RSI.mq5 b/tests/StrategyTest-RSI.mq5 index d9842b7da..d372feaf5 100644 --- a/tests/StrategyTest-RSI.mq5 +++ b/tests/StrategyTest-RSI.mq5 @@ -48,7 +48,10 @@ class Stg_RSI : public Strategy { bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method = 0, float _level = 0.0f, int _shift = 0) { Indi_RSI *_indi = GetIndicator(); - return (_cmd == ORDER_TYPE_BUY && _indi[_shift][0] <= 20) || (_cmd == ORDER_TYPE_SELL && _indi[_shift][0] >= 80); + bool _result = _indi.GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift); + _result &= + (_cmd == ORDER_TYPE_BUY && _indi[_shift][0] <= 30) || (_cmd == ORDER_TYPE_SELL && _indi[_shift][0] >= 70); + return _result; } bool SignalClose(ENUM_ORDER_TYPE _cmd, int _method, float _level, int _shift) { @@ -62,6 +65,12 @@ class Stg_RSI : public Strategy { return _direction > 0 ? (float)_indi.GetPrice(PRICE_HIGH, _indi.GetHighest(_indi.GetPeriod() * 2)) : (float)_indi.GetPrice(PRICE_LOW, _indi.GetLowest(_indi.GetPeriod() * 2)); } + + virtual void OnPeriod(unsigned int _periods = DATETIME_NONE) { + if ((_periods & DATETIME_HOUR) != 0) { + // New hour started. + } + } }; // Global variables. @@ -105,7 +114,9 @@ int OnInit() { * Implements OnTick(). */ void OnTick() { - if (stg_rsi.TickFilter(SymbolInfoStatic::GetTick(_Symbol), 1)) { + static MqlTick _tick_last; + MqlTick _tick_new = SymbolInfoStatic::GetTick(_Symbol); + if (_tick_new.time % 60 < _tick_last.time % 60) { if (stg_rsi.SignalOpen(ORDER_TYPE_BUY)) { MqlTradeRequest _request = trade.GetTradeOpenRequest(ORDER_TYPE_BUY, 0, stg_rsi.Get(STRAT_PARAM_ID), stg_rsi.GetName()); @@ -114,14 +125,32 @@ void OnTick() { MqlTradeRequest _request = trade.GetTradeOpenRequest(ORDER_TYPE_SELL, 0, stg_rsi.Get(STRAT_PARAM_ID), stg_rsi.GetName()); trade.RequestSend(_request); - } else if (trade.Get(TRADE_STATE_ORDERS_ACTIVE)) { + } + if (trade.Get(TRADE_STATE_ORDERS_ACTIVE)) { + if (stg_rsi.SignalClose(ORDER_TYPE_BUY)) { + // Close signal for buy order. + trade.OrdersCloseViaProp2( + ORDER_MAGIC, stg_rsi.Get(STRAT_PARAM_ID), ORDER_TYPE, ORDER_TYPE_BUY, MATH_COND_EQ, + ORDER_REASON_CLOSED_BY_SIGNAL, stg_rsi.GetOrderCloseComment()); + } + if (stg_rsi.SignalClose(ORDER_TYPE_SELL)) { + trade.OrdersCloseViaProp2( + ORDER_MAGIC, stg_rsi.Get(STRAT_PARAM_ID), ORDER_TYPE, ORDER_TYPE_SELL, MATH_COND_EQ, + ORDER_REASON_CLOSED_BY_SIGNAL, stg_rsi.GetOrderCloseComment()); + } + } + if (_tick_new.time % 3600 < _tick_last.time % 3600) { stg_rsi.ProcessTasks(); + trade.UpdateStates(); + // Print strategy values every hour. + Print(stg_rsi.ToString()); } long _last_error = GetLastError(); if (_last_error > 0) { assertTrueOrExit(_last_error == ERR_NO_ERROR, StringFormat("Error occured! Code: %d", _last_error)); } } + _tick_last = _tick_new; } /** From 4e3fa6a79bc84ead7e7470239ab70fe140205595 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 18:10:46 +0100 Subject: [PATCH 27/78] EA/Strategy: Code cleanup --- EA.mqh | 28 ++------ Strategy.enum.h | 16 ----- Strategy.struct.h | 140 ------------------------------------- tests/StrategyTest-RSI.mq5 | 2 +- 4 files changed, 8 insertions(+), 178 deletions(-) diff --git a/EA.mqh b/EA.mqh index 412db9734..dcc8163a9 100644 --- a/EA.mqh +++ b/EA.mqh @@ -63,7 +63,6 @@ class EA { // Data variables. BufferStruct data_chart; - BufferStruct> strat_signals; BufferStruct data_symbol; Dict ddata; // Custom user data. Dict idata; // Custom user data. @@ -130,17 +129,17 @@ class EA { } /** - * Process strategy's signal entry. + * Gets a strategy's signal entry. * - * @param bool _should_open - * True if method should open the orders, otherwise only process the signals. - * @param bool _should_close - * True if method should close the orders, otherwise only process the signals. + * @param Strategy _strat + * Reference to strategy to get the signal from. + * @param bool _trade_allowed + * True if trade is allowed. * @param int _shift * Bar shift. * * @return - * Returns StrategySignal struct. + * Returns TradeSignalEntry struct. */ TradeSignalEntry GetStrategySignalEntry(Strategy *_strat, bool _trade_allowed = true, int _shift = -1) { // float _bf = 1.0; @@ -156,7 +155,6 @@ class EA { int _som = _strat.Get(STRAT_PARAM_SOM); int _ss = _shift >= 0 ? _shift : _strat.Get(STRAT_PARAM_SHIFT); unsigned int _signals = 0; - // StrategySignal _signal(THIS_PTR, trade.Get(CHART_PARAM_TF), // sparams.Get(STRAT_PARAM_WEIGHT)); if (_trade_allowed) { // Process boost factor and lot size. @@ -246,7 +244,6 @@ class EA { bool _result = true; int _last_error = ERR_NO_ERROR; ResetLastError(); - // DictStruct _ds = strat_signals.GetByKey(_tick.time); for (DictObjectIterator _iter = tsm.GetIterSignalsActive(); _iter.IsValid(); ++_iter) { bool _result_local = true; TradeSignal *_signal = _iter.Value(); @@ -673,17 +670,6 @@ class EA { } */ - /** - * Adds strategy's signal for further processing. - */ - /* - bool SignalAdd(StrategySignal &_signal, long _time) { - DictStruct _ds = strat_signals.GetByKey(_time); - _ds.Push(_signal); - return strat_signals.Set(_time, _ds); - } - */ - /* Tasks */ /** @@ -1116,6 +1102,7 @@ class EA { } if ((estate.new_periods & DATETIME_HOUR) != 0) { // New hour started. + tsm.Refresh(); } if ((estate.new_periods & DATETIME_DAY) != 0) { // New day started. @@ -1126,7 +1113,6 @@ class EA { } if ((estate.new_periods & DATETIME_WEEK) != 0) { // New week started. - strat_signals.Clear(); } if ((estate.new_periods & DATETIME_MONTH) != 0) { // New month started. diff --git a/Strategy.enum.h b/Strategy.enum.h index fc5aeef66..be20779b5 100644 --- a/Strategy.enum.h +++ b/Strategy.enum.h @@ -97,22 +97,6 @@ enum ENUM_STRATEGY_PARAM { FINAL_ENUM_STRATEGY_PARAM }; -/* Enumeration for strategy bitwise signal flags. */ -enum ENUM_STRATEGY_SIGNAL_FLAG { - STRAT_SIGNAL_NONE = 0 << 0, - STRAT_SIGNAL_CLOSE_BUY = 1 << 0, // Close signal for buy - STRAT_SIGNAL_CLOSE_BUY_PASS = 1 << 1, // Close signal for buy passed by filter - STRAT_SIGNAL_CLOSE_SELL = 1 << 2, // Close signal for sell - STRAT_SIGNAL_CLOSE_SELL_PASS = 1 << 3, // Close signal for sell passed by filter - STRAT_SIGNAL_OPEN_BUY = 1 << 4, // Open signal for buy - STRAT_SIGNAL_OPEN_BUY_PASS = 1 << 5, // Open signal for buy passed by filter - STRAT_SIGNAL_OPEN_SELL = 1 << 6, // Open signal for sell - STRAT_SIGNAL_OPEN_SELL_PASS = 1 << 7, // Open signal for sell passed by filter - STRAT_SIGNAL_PROCESSED = 1 << 8, // Signal proceed - STRAT_SIGNAL_TIME_PASS = 1 << 9, // Open signal passed by time filter - FINAL_ENUM_STRATEGY_SIGNAL_FLAG -}; - /* Enumeration for strategy periodical statistics. */ enum ENUM_STRATEGY_STATS_PERIOD { EA_STATS_DAILY, diff --git a/Strategy.struct.h b/Strategy.struct.h index 4af31a374..c9448eb2d 100644 --- a/Strategy.struct.h +++ b/Strategy.struct.h @@ -412,146 +412,6 @@ struct StgProcessResult { } }; -/* Structure for strategy's signals. */ -struct StrategySignal { - protected: - ENUM_TIMEFRAMES tf; // Timeframe. - float strength; // Signal strength. - float weight; // Signal weight. - unsigned int signals; // Store signals (@see: ENUM_STRATEGY_SIGNAL_FLAG). - Strategy *strat; - - public: - // Enumeration for strategy signal properties. - enum ENUM_STRATEGY_SIGNAL_PROP { - STRATEGY_SIGNAL_PROP_SIGNALS, - STRATEGY_SIGNAL_PROP_STRENGTH, - STRATEGY_SIGNAL_PROP_TF, - STRATEGY_SIGNAL_PROP_WEIGHT, - }; - // Enumeration for strategy signal types. - enum ENUM_STRATEGY_SIGNAL_TYPE { - STRAT_SIGNAL_SELL = -1, // Signal to sell. - STRAT_SIGNAL_NEUTRAL = 0, // Neutral signal. - STRAT_SIGNAL_BUY = 1, // Signal to buy. - }; - - /* Constructor */ - StrategySignal(Strategy *_strat = NULL, ENUM_TIMEFRAMES _tf = NULL, float _weight = 0.0f) - : signals(0), strat(_strat), tf(_tf), weight(_weight) {} - /* Getters */ - template - T Get(unsigned int _param) { - switch (_param) { - case STRATEGY_SIGNAL_PROP_SIGNALS: - return (T)signals; - case STRATEGY_SIGNAL_PROP_STRENGTH: - return (T)strength; - case STRATEGY_SIGNAL_PROP_TF: - return (T)tf; - case STRATEGY_SIGNAL_PROP_WEIGHT: - return (T)weight; - } - SetUserError(ERR_INVALID_PARAMETER); - return (T)WRONG_VALUE; - } - float GetSignalClose() { return float(int(ShouldClose(ORDER_TYPE_BUY)) - int(ShouldClose(ORDER_TYPE_SELL))); } - float GetSignalOpen() { return float(int(ShouldOpen(ORDER_TYPE_BUY)) - int(ShouldOpen(ORDER_TYPE_SELL))); } - Strategy *GetStrategy() { return strat; } - /* Setters */ - template - void Set(unsigned int _param, T _value) { - switch (_param) { - case STRATEGY_SIGNAL_PROP_SIGNALS: - signals = (unsigned int)_value; - return; - case STRATEGY_SIGNAL_PROP_STRENGTH: - strength = (float)_value; - return; - case STRATEGY_SIGNAL_PROP_TF: - tf = (ENUM_TIMEFRAMES)_value; - return; - case STRATEGY_SIGNAL_PROP_WEIGHT: - weight = (float)_value; - return; - } - SetUserError(ERR_INVALID_PARAMETER); - } - void SetStrategy(Strategy *_strat) { strat = _strat; } - /* Signal open and close methods */ - bool ShouldClose(ENUM_ORDER_TYPE _cmd) { - switch (_cmd) { - case ORDER_TYPE_BUY: - return CheckSignalsAll(STRAT_SIGNAL_CLOSE_BUY | STRAT_SIGNAL_CLOSE_BUY_PASS); - case ORDER_TYPE_SELL: - return CheckSignalsAll(STRAT_SIGNAL_CLOSE_SELL | STRAT_SIGNAL_CLOSE_SELL_PASS); - } - return false; - } - bool ShouldOpen(ENUM_ORDER_TYPE _cmd) { - switch (_cmd) { - case ORDER_TYPE_BUY: - return CheckSignalsAll(STRAT_SIGNAL_OPEN_BUY | STRAT_SIGNAL_OPEN_BUY_PASS | STRAT_SIGNAL_TIME_PASS); - case ORDER_TYPE_SELL: - return CheckSignalsAll(STRAT_SIGNAL_OPEN_SELL | STRAT_SIGNAL_OPEN_SELL_PASS | STRAT_SIGNAL_TIME_PASS); - } - return false; - } - /* Signal methods for bitwise operations */ - bool CheckSignals(unsigned int _flags) { return (signals & _flags) != 0; } - bool CheckSignalsAll(unsigned int _flags) { return (signals & _flags) == _flags; } - char GetCloseDirection() { - if (CheckSignals(STRAT_SIGNAL_CLOSE_BUY & ~STRAT_SIGNAL_CLOSE_SELL)) { - return 1; - } else if (CheckSignals(STRAT_SIGNAL_CLOSE_SELL & ~STRAT_SIGNAL_CLOSE_BUY)) { - return -1; - } - return 0; - } - char GetOpenDirection() { - if (CheckSignals(STRAT_SIGNAL_OPEN_BUY & ~STRAT_SIGNAL_OPEN_SELL)) { - return 1; - } else if (CheckSignals(STRAT_SIGNAL_OPEN_SELL & ~STRAT_SIGNAL_OPEN_BUY)) { - return -1; - } - return 0; - } - unsigned int GetSignals() { return signals; } - /* Setters */ - void AddSignals(unsigned int _flags) { signals |= _flags; } - void RemoveSignals(unsigned int _flags) { signals &= ~_flags; } - void SetSignal(ENUM_STRATEGY_SIGNAL_FLAG _flag, bool _value = true) { - if (_value) { - AddSignals(_flag); - } else { - RemoveSignals(_flag); - } - } - void SetSignals(unsigned int _flags) { signals = _flags; } - // Serializers. - SERIALIZER_EMPTY_STUB; - SerializerNodeType Serialize(Serializer &_s) { - _s.PassEnum(THIS_REF, "tf", tf); - _s.Pass(THIS_REF, "strenght", strength, SERIALIZER_FIELD_FLAG_DYNAMIC); - _s.Pass(THIS_REF, "weight", weight, SERIALIZER_FIELD_FLAG_DYNAMIC); - if (Object::IsValid(strat)) { - string _sname = strat.GetName(); - _s.Pass(THIS_REF, "strat", _sname); - } - int _size = sizeof(int) * 8; - for (int i = 0; i < _size; i++) { - int _value = CheckSignals(1 << i) ? 1 : 0; - _s.Pass(THIS_REF, (string)(i + 1), _value, SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE); - } - return SerializerNodeObject; - } - string ToString() { - // SerializerConverter _stub = SerializerConverter::MakeStubObject(SERIALIZER_FLAG_SKIP_HIDDEN); - return SerializerConverter::FromObject(THIS_REF, SERIALIZER_FLAG_SKIP_HIDDEN) - .ToString(SERIALIZER_JSON_NO_WHITESPACES); - } -}; - /* Struture for strategy statistics */ struct StgStats { uint orders_open; // Number of current opened orders. diff --git a/tests/StrategyTest-RSI.mq5 b/tests/StrategyTest-RSI.mq5 index d372feaf5..74019a57d 100644 --- a/tests/StrategyTest-RSI.mq5 +++ b/tests/StrategyTest-RSI.mq5 @@ -50,7 +50,7 @@ class Stg_RSI : public Strategy { Indi_RSI *_indi = GetIndicator(); bool _result = _indi.GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift); _result &= - (_cmd == ORDER_TYPE_BUY && _indi[_shift][0] <= 30) || (_cmd == ORDER_TYPE_SELL && _indi[_shift][0] >= 70); + (_cmd == ORDER_TYPE_BUY && _indi[_shift][0] <= 20) || (_cmd == ORDER_TYPE_SELL && _indi[_shift][0] >= 80); return _result; } From 2d1fa16cbaec897aafa2584e1d50e8c783c2544c Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 18:31:36 +0100 Subject: [PATCH 28/78] GHA: Adds Test for Trade directory --- .github/workflows/test-trade.yml | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/test-trade.yml diff --git a/.github/workflows/test-trade.yml b/.github/workflows/test-trade.yml new file mode 100644 index 000000000..455093df1 --- /dev/null +++ b/.github/workflows/test-trade.yml @@ -0,0 +1,59 @@ +--- +name: Test Trade + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Trade/**.h' + - '.github/workflows/test-trade.yml' + push: + paths: + - 'Trade/**.h' + - '.github/workflows/test-trade.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: 'Trade/' + 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' + + Trade-Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Trade/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - TradeSignalTest + steps: + - uses: actions/download-artifact@v2 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} From 4ffcd1c6451340600ffc1465dda535e832248990 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 18:36:39 +0100 Subject: [PATCH 29/78] GHA: Adds Test for Indicators directory --- .github/workflows/test-indicators.yml | 128 ++++++++++++++++++++++++++ .github/workflows/test-trade.yml | 2 +- 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-indicators.yml diff --git a/.github/workflows/test-indicators.yml b/.github/workflows/test-indicators.yml new file mode 100644 index 000000000..386146758 --- /dev/null +++ b/.github/workflows/test-indicators.yml @@ -0,0 +1,128 @@ +--- +name: Test Indicators + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Indicator**' + - 'Indicators/**' + - '.github/workflows/test-indicators.yml' + push: + paths: + - 'Indicator**' + - 'Indicators/**' + - '.github/workflows/test-indicators.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/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_AC.test + - Indi_AD.test + # - Indi_ADX.test + - Indi_ADXW.test + - Indi_AMA.test + - Indi_AO.test + - Indi_ASI.test + - Indi_ATR.test + - Indi_Alligator.test + # - Indi_AppliedPrice.test + # - Indi_BWMFI.test + # - Indi_BWZT.test + # - Indi_Bands.test + # - Indi_BearsPower.test + # - Indi_BullsPower.test + # - Indi_CCI.test + # - Indi_CHO.test + # - Indi_CHV.test + # - Indi_ColorBars.test + # - Indi_ColorCandlesDaily.test + # - Indi_ColorLine.test + # - Indi_CustomMovingAverage.test + # - Indi_DEMA.test + # - Indi_DeMarker.test + # - Indi_Demo.test + # - Indi_DetrendedPrice.test + # - Indi_Drawer.test + # - Indi_Envelopes.test + # - Indi_Force.test + # - Indi_FractalAdaptiveMA.test + # - Indi_Fractals.test + # - Indi_Gator.test + # - Indi_HeikenAshi.test + # - Indi_Ichimoku.test + # - Indi_MA.test + # - Indi_MACD.test + # - Indi_MFI.test + # - Indi_MarketFacilitationIndex.test + # - Indi_MassIndex.test + # - Indi_Momentum.test + # - Indi_OBV.test + # - Indi_OsMA.test + # - Indi_Pattern.test + # - Indi_Pivot.test + # - Indi_Price.test + # - Indi_PriceChannel.test + # - Indi_PriceFeeder.test + # - Indi_PriceVolumeTrend.test + # - Indi_RS.test + # - Indi_RSI.test + # - Indi_RVI.test + # - Indi_RateOfChange.test + # - Indi_SAR.test + # - Indi_StdDev.test + # - Indi_Stochastic.test + # - Indi_TEMA.test + # - Indi_TRIX.test + # - Indi_UltimateOscillator.test + # - Indi_VIDYA.test + # - Indi_VROC.test + # - Indi_Volumes.test + # - Indi_WPR.test + # - Indi_WilliamsAD.test + # - Indi_ZigZag.test + # - Indi_ZigZagColor.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 }} diff --git a/.github/workflows/test-trade.yml b/.github/workflows/test-trade.yml index 455093df1..babad58bd 100644 --- a/.github/workflows/test-trade.yml +++ b/.github/workflows/test-trade.yml @@ -22,7 +22,7 @@ jobs: uses: fx31337/mql-compile-action@master with: init-platform: true - path: 'Trade/' + path: 'Trade/tests' verbose: true - name: Print compiled files run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' From 564f5f91160ea7f2caf2305aa746a81108c20c1e Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 28 Sep 2021 19:07:24 +0100 Subject: [PATCH 30/78] OrderQuery: Adds CalcSumByPropWithCond() and FindPropBySum() --- OrderQuery.h | 48 ++++++++++++++++++++++++++++++++++++++++ tests/OrderQueryTest.mq5 | 19 ++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/OrderQuery.h b/OrderQuery.h index e3cc6db4f..aede72e81 100644 --- a/OrderQuery.h +++ b/OrderQuery.h @@ -53,6 +53,9 @@ class OrderQuery : public Dynamic { /** * Calculates sum of order's value based on the property's enum. * + * @param + * _prop Order's property to sum by (e.g. ORDER_PROP_PROFIT). + * * @return * Returns sum of order's values. */ @@ -65,6 +68,24 @@ class OrderQuery : public Dynamic { return _sum; } + /** + * Calculates sum of order's value based on the property's enum with condition. + * + * @return + * Returns sum of order's values based on the condition. + */ + template + T CalcSumByPropWithCond(E _prop, ECT _prop_cond_type, ECV _prop_cond_value) { + T _sum = 0; + for (DictStructIterator> iter = orders.Begin(); iter.IsValid(); ++iter) { + Order *_order = iter.Value().Ptr(); + if (_order.Get(_prop_cond_type) == _prop_cond_value) { + _sum += _order.Get(_prop); + } + } + return _sum; + } + /** * Find order by comparing property's value given the comparison operator. * @@ -111,6 +132,33 @@ class OrderQuery : public Dynamic { return _order_ref_found; } + /** + * Find property enum with the highest sum based on another property's enums. + * + * For example, you can find order's type which has the highest profit. + * + * @param + * _props Array of properties to group the sums by. + * _prop_sum Order's property to sum by (e.g. ORDER_PROP_PROFIT). + * + * @return + * Returns property enum having the highest sum. + */ + template + EP FindPropBySum(ARRAY_REF(EP, _props), ES _prop_sum, ECT _prop_sum_type, + STRUCT_ENUM(OrderQuery, ORDER_QUERY_OP) _op = STRUCT_ENUM(OrderQuery, ORDER_QUERY_OP_GT)) { + EP _peak_type = _props[0]; + T _peak_sum = CalcSumByPropWithCond(_prop_sum, _prop_sum_type, _peak_type); + for (int _i = 1; _i < ArraySize(_props); _i++) { + T _sum = CalcSumByPropWithCond(_prop_sum, _prop_sum_type, _props[_i]); + if (Compare(_sum, _op, _peak_sum)) { + _peak_sum = _sum; + _peak_type = _props[_i]; + } + } + return _peak_type; + } + /** * Perform a comparison operation on two values. * diff --git a/tests/OrderQueryTest.mq5 b/tests/OrderQueryTest.mq5 index 64e88781c..8a4ada61b 100644 --- a/tests/OrderQueryTest.mq5 +++ b/tests/OrderQueryTest.mq5 @@ -36,6 +36,7 @@ bool Test01() { for (int i = -10; i <= 10; i++) { OrderData _odata; _odata.Set(ORDER_PROP_PROFIT, (float)i); + _odata.Set(ORDER_TYPE, i % 2 == 0 ? ORDER_TYPE_BUY : ORDER_TYPE_SELL); Ref _order = new Order(_odata); orders.Push(_order); } @@ -71,6 +72,24 @@ bool Test01() { assertTrueOrReturnFalse(_order_profit_gt_2.Ptr().Get(ORDER_PROP_PROFIT) > 2, "Order with profit greater than 2 not found!"); + // Calculate profit sums (all, buys and sells). + float _order_profit_all = _oquery.CalcSumByProp(ORDER_PROP_PROFIT); + assertTrueOrReturnFalse(_order_profit_all == 0, "All profit should be 0!"); + float _order_profit_buy = + _oquery.CalcSumByPropWithCond( + ORDER_PROP_PROFIT, ORDER_TYPE, ORDER_TYPE_BUY); + float _order_profit_sell = + _oquery.CalcSumByPropWithCond( + ORDER_PROP_PROFIT, ORDER_TYPE, ORDER_TYPE_SELL); + assertTrueOrReturnFalse(_order_profit_buy == _order_profit_sell, "Profit of buys should equal profit of sells!"); + + // Find order type with the highest profit. + ENUM_ORDER_TYPE _order_types[] = {ORDER_TYPE_BUY, ORDER_TYPE_SELL}; + ENUM_ORDER_TYPE _order_type_highest_profit = + _oquery.FindPropBySum( + _order_types, ORDER_PROP_PROFIT, ORDER_TYPE); + assertTrueOrReturnFalse(_order_type_highest_profit == 0.0f, "Highest profitable order type incorrect!"); + //_order_profit_best.ToString(); // @todo //_order_profit_worst.ToString(); // @todo return _result; From 7382f9a34cffa7f2cfa63e64f65631f6e494f484 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 19:07:33 +0100 Subject: [PATCH 31/78] Indicators: Adds missing includes --- Indicators/Indi_CHO.mqh | 1 + Indicators/Indi_CHV.mqh | 1 + Indicators/Indi_ColorBars.mqh | 1 + Indicators/Indi_ColorCandlesDaily.mqh | 1 + Indicators/Indi_ColorLine.mqh | 1 + Indicators/Indi_DetrendedPrice.mqh | 1 + Indicators/Indi_FractalAdaptiveMA.mqh | 9 +-- Indicators/Indi_MA.mqh | 4 +- Indicators/Indi_MassIndex.mqh | 1 + Indicators/Indi_PriceVolumeTrend.mqh | 1 + Indicators/Indi_RateOfChange.mqh | 1 + Indicators/Indi_UltimateOscillator.mqh | 1 + Indicators/Indi_VROC.mqh | 1 + Indicators/Indi_Volumes.mqh | 1 + Indicators/Indi_WilliamsAD.mqh | 1 + .../tests/Indi_FractalAdaptiveMA.test.mq5 | 2 +- .../Indi_MarketFacilitationIndex.test.mq4 | 27 --------- .../Indi_MarketFacilitationIndex.test.mq5 | 57 ------------------- tests/IndicatorsTest.mq5 | 2 +- 19 files changed, 22 insertions(+), 92 deletions(-) delete mode 100644 Indicators/tests/Indi_MarketFacilitationIndex.test.mq4 delete mode 100644 Indicators/tests/Indi_MarketFacilitationIndex.test.mq5 diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 407700a8d..96f845699 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" #include "Indi_MA.mqh" // Structs. diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 42bbae1a4..824f45c53 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" #include "Indi_MA.mqh" // Enums. diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 4e25b15a8..866b907e9 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" // Structs. struct ColorBarsParams : IndicatorParams { diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index d941b67ec..e494b316c 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" // Structs. struct ColorCandlesDailyParams : IndicatorParams { diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 9503ddf4b..6668ace94 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" #include "Indi_MA.mqh" // Structs. diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index deed98b25..158851dea 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.price.h" #include "Indi_MA.mqh" // Structs. diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index d885c15ab..638d14f76 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -23,15 +23,16 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.price.h" // Structs. -struct FrIndiAMAParams : IndicatorParams { +struct IndiFrAMAParams : IndicatorParams { unsigned int frama_shift; unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void FrIndiAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { + void IndiFrAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { frama_shift = _frama_shift; itype = INDI_FRAMA; max_modes = 1; @@ -47,12 +48,12 @@ struct FrIndiAMAParams : IndicatorParams { /** * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ -class Indi_FrAMA : public Indicator { +class Indi_FrAMA : public Indicator { public: /** * Class constructor. */ - Indi_FrAMA(FrIndiAMAParams &_params) : Indicator(_params){}; + Indi_FrAMA(IndiFrAMAParams &_params) : Indicator(_params){}; Indi_FrAMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FRAMA, _tf){}; /** diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index 30375285a..c4ed6d7c2 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -121,11 +121,11 @@ class Indi_MA : public Indicator { /** * Calculates MA on another indicator. */ - static double iMAOnIndicator(IndicatorCalculateCache *cache, IndicatorBase *indi, int indi_mode, + static double iMAOnIndicator(IndicatorCalculateCache *cache, IndicatorBase *_indi, int indi_mode, string symbol, ENUM_TIMEFRAMES tf, unsigned int ma_period, unsigned int ma_shift, ENUM_MA_METHOD ma_method, // (MT4/MT5): MODE_SMA, MODE_EMA, MODE_SMMA, MODE_LWMA int shift = 0) { - return iMAOnArray(indi.GetValueStorage(indi_mode), 0, ma_period, ma_shift, ma_method, shift, cache); + return iMAOnArray(_indi.GetValueStorage(indi_mode), 0, ma_period, ma_shift, ma_method, shift, cache); } /** diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index e4901872c..c007b744c 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" #include "Indi_MA.mqh" // Structs. diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index f3e7b498c..a1ae526dd 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" // Structs. struct PriceVolumeTrendParams : IndicatorParams { diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index 3d8836c36..4fc5fc7e3 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.price.h" // Structs. struct RateOfChangeParams : IndicatorParams { diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index dbeaa1656..8948f031b 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" #include "Indi_ATR.mqh" // Structs. diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index a913707cf..b8eb6b318 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" // Structs. struct VROCParams : IndicatorParams { diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 21f8b4ba8..a4a6cf5aa 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" // Structs. struct VolumesParams : IndicatorParams { diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index a8d4345de..2c6f9079e 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -23,6 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" +#include "../Storage/ValueStorage.all.h" // Structs. struct WilliamsADParams : IndicatorParams { diff --git a/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 index 3a7f4d9c8..9b8555261 100644 --- a/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 +++ b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 @@ -28,7 +28,7 @@ * Test functionality of Indi_FractalAdaptiveMA indicator class. */ -Indi_FractalAdaptiveMA indi(PERIOD_CURRENT); +Indi_FrAMA indi(PERIOD_CURRENT); /** * Implements Init event handler. diff --git a/Indicators/tests/Indi_MarketFacilitationIndex.test.mq4 b/Indicators/tests/Indi_MarketFacilitationIndex.test.mq4 deleted file mode 100644 index 7528e9508..000000000 --- a/Indicators/tests/Indi_MarketFacilitationIndex.test.mq4 +++ /dev/null @@ -1,27 +0,0 @@ -//+------------------------------------------------------------------+ -//| 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 . - */ - -/** - * @file - * Test functionality of Indi_MarketFacilitationIndex indicator class. - */ - -#include "Indi_MarketFacilitationIndex.test.mq5" diff --git a/Indicators/tests/Indi_MarketFacilitationIndex.test.mq5 b/Indicators/tests/Indi_MarketFacilitationIndex.test.mq5 deleted file mode 100644 index a4f58f32d..000000000 --- a/Indicators/tests/Indi_MarketFacilitationIndex.test.mq5 +++ /dev/null @@ -1,57 +0,0 @@ -//+------------------------------------------------------------------+ -//| 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 . - */ - -// Includes. -#include "../../Test.mqh" -#include "../Indi_MarketFacilitationIndex.mqh" - -/** - * @file - * Test functionality of Indi_MarketFacilitationIndex indicator class. - */ - -Indi_MarketFacilitationIndex indi(PERIOD_CURRENT); - -/** - * Implements Init event handler. - */ -int OnInit() { - bool _result = true; - assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); - // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); - 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()); - } - } - _tick_last = _tick_new; -} diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index 13b3879f9..2fce00468 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -264,7 +264,7 @@ bool InitIndicators() { indis.Push(new Indi_Fractals()); // Fractal Adaptive Moving Average (FRAMA). - FrIndiAMAParams frama_params(); + IndiFrAMAParams frama_params(); indis.Push(new Indi_FrAMA(frama_params)); // Gator Oscillator. From f8f048583ee30fc74a67bf8318bc23e7ec5319ed Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 20:24:20 +0100 Subject: [PATCH 32/78] Indicators: Fixes compilation errors --- Indicators/Indi_DEMA.mqh | 6 +++--- Indicators/Indi_Envelopes.mqh | 2 +- Indicators/Indi_Ichimoku.mqh | 2 +- Indicators/Indi_Killzones.mqh | 13 +++++-------- Indicators/Indi_PriceFeeder.mqh | 1 + Indicators/Indi_UltimateOscillator.mqh | 1 + Indicators/tests/Indi_Killzones.test.mq5 | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 2625dc29c..f14c4cf87 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -80,7 +80,7 @@ class Indi_DEMA : public Indicator { * Class constructor. */ Indi_DEMA(DEMAParams &_p) : Indicator(_p) {} - Indi_DEMA(DEMAParams &_p, ENUM_TIMEFRAMES _tf) : Indicator(INDI_DEMA, _tf) {} + Indi_DEMA(ENUM_TIMEFRAMES _tf) : Indicator(INDI_DEMA, _tf) {} /** * Updates the indicator value. @@ -125,9 +125,9 @@ class Indi_DEMA : public Indicator { #endif } - static double iDEMAOnIndicator(IndicatorCalculateCache *cache, IndicatorBase *indi, int indi_mode, + static double iDEMAOnIndicator(IndicatorCalculateCache *cache, IndicatorBase *_indi, int indi_mode, unsigned int ma_period, unsigned int ma_shift, int shift) { - return iDEMAOnArray(indi.GetValueStorage(indi_mode), 0, ma_period, ma_shift, shift, cache); + return iDEMAOnArray(_indi.GetValueStorage(indi_mode), 0, ma_period, ma_shift, shift, cache); } static double iDEMAOnArray(ValueStorage &price, int total, unsigned int ma_period, unsigned int ma_shift, diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 9c75e8e31..6247c0579 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -75,7 +75,7 @@ class Indi_Envelopes : public Indicator { * Class constructor. */ Indi_Envelopes(EnvelopesParams &_p) : Indicator(_p) {} - Indi_Envelopes(EnvelopesParams &_p, ENUM_TIMEFRAMES _tf) : Indicator(INDI_ENVELOPES, _tf) {} + Indi_Envelopes(ENUM_TIMEFRAMES _tf) : Indicator(INDI_ENVELOPES, _tf) {} /** * Returns the indicator value. diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index fd9f4dea8..fa1c029f1 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -87,7 +87,7 @@ class Indi_Ichimoku : public Indicator { * Class constructor. */ Indi_Ichimoku(IchimokuParams &_p) : Indicator(_p) {} - Indi_Ichimoku(IchimokuParams &_p, ENUM_TIMEFRAMES _tf) : Indicator(INDI_ICHIMOKU, _tf) {} + Indi_Ichimoku(ENUM_TIMEFRAMES _tf) : Indicator(INDI_ICHIMOKU, _tf) {} /** * Returns the indicator value. diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index 4bd704643..f88948fe0 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -93,19 +93,16 @@ struct Indi_Killzones_Time : MarketTimeForex { /** * Implements Pivot Detector. */ -class Indi_Killzones : public Indicator { +class Indi_Killzones : public Indicator { protected: Indi_Killzones_Time ikt; - IndiKillzonesParams iparams; public: /** * Class constructor. */ - Indi_Killzones(IndiKillzonesParams &_params) : iparams(_params), Indicator((IndicatorParams)_params){}; - Indi_Killzones(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : Indicator(INDI_KILLZONES, _tf, _shift) { - iparams.tf = _tf; - }; + Indi_Killzones(IndiKillzonesParams &_p) : Indicator(_p) {} + Indi_Killzones(ENUM_TIMEFRAMES _tf) : Indicator(INDI_KILLZONES, _tf) {} /** * Returns the indicator's value. @@ -114,7 +111,7 @@ class Indi_Killzones : public Indicator { ResetLastError(); float _value = FLT_MAX; int _index = (int)floor(_mode / 2); - switch (params.idstype) { + switch (iparams.idstype) { case IDATA_BUILTIN: // Builtin mode not supported. SetUserError(ERR_INVALID_PARAMETER); @@ -149,7 +146,7 @@ class Indi_Killzones : public Indicator { if (!_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) { _entry.Resize(iparams.GetMaxModes()); _entry.timestamp = GetBarTime(_shift); - for (unsigned int _mode = 0; _mode < iparams.GetMaxModes(); _mode++) { + for (unsigned int _mode = 0; _mode < (uint)iparams.GetMaxModes(); _mode++) { float _value = GetValue(_mode, _shift); if (IsValidValue(_value, _mode, _shift)) { _entry.values[_mode] = _value; diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index ad4d37cf4..30a984342 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -65,6 +65,7 @@ class Indi_PriceFeeder : public Indicator { Indi_PriceFeeder(const double& _price_data[], int _total = 0) : Indicator(INDI_PRICE_FEEDER) { ArrayCopy(iparams.price_data, _price_data); }; + Indi_PriceFeeder(ENUM_TIMEFRAMES _tf) : Indicator(INDI_PRICE_FEEDER, _tf) {} void SetPrices(const double& _price_data[], int _total = 0) { iparams = PriceFeederIndiParams(_price_data, _total); } diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 8948f031b..c479a552b 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -25,6 +25,7 @@ #include "../Indicator.mqh" #include "../Storage/ValueStorage.all.h" #include "Indi_ATR.mqh" +#include "Indi_MA.mqh" // Structs. struct UltimateOscillatorParams : IndicatorParams { diff --git a/Indicators/tests/Indi_Killzones.test.mq5 b/Indicators/tests/Indi_Killzones.test.mq5 index 45d8d0fc3..d925e3e0c 100644 --- a/Indicators/tests/Indi_Killzones.test.mq5 +++ b/Indicators/tests/Indi_Killzones.test.mq5 @@ -28,7 +28,7 @@ * Test functionality of Indi_Killzones indicator class. */ -Indi_Killzones indi(PERIOD_CURRENT, 1); +Indi_Killzones indi(PERIOD_CURRENT); /** * Implements Init event handler. From 0fb8a9c7b456a3bd67971176b458aa86f19d905b Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 20:44:47 +0100 Subject: [PATCH 33/78] Indicator/Strategy: Fixes compilation errors --- Indicator.mqh | 25 ++++++++----------------- Indicators/Indi_FractalAdaptiveMA.mqh | 2 +- Strategy.mqh | 9 ++++----- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/Indicator.mqh b/Indicator.mqh index d7da6e157..423ea365b 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -359,14 +359,15 @@ class Indicator : public IndicatorBase { void ValidateDataSourceMode(int& _out_mode) { if (_out_mode == -1) { // First mode will be used by default, or, if selected indicator has more than one mode, error will happen. - if (iparams.max_modes != 1) { + if (iparams.GetMaxModes() != 1) { Alert("Error: ", GetName(), " must have exactly one possible mode in order to skip using SetDataSourceMode()!"); DebugBreak(); } _out_mode = 0; - } else if (_out_mode + 1 > (int)iparams.max_modes) { - Alert("Error: ", GetName(), " have ", iparams.max_modes, " mode(s) buy you tried to reference mode with index ", - _out_mode, "! Ensure that you properly set mode via SetDataSourceMode()."); + } else if (_out_mode + 1 > (int)iparams.GetMaxModes()) { + Alert("Error: ", GetName(), " have ", iparams.GetMaxModes(), + " mode(s) buy you tried to reference mode with index ", _out_mode, + "! Ensure that you properly set mode via SetDataSourceMode()."); DebugBreak(); } } @@ -464,21 +465,11 @@ class Indicator : public IndicatorBase { return _signals; } - /** - * Get indicator type. - */ - ENUM_INDICATOR_TYPE GetType() { return iparams.itype; } - /** * Get pointer to data of indicator. */ BufferStruct* GetData() { return GetPointer(idata); } - /** - * Get data type of indicator. - */ - ENUM_DATATYPE GetDataType() { return iparams.dtype; } - /** * Get name of the indicator. */ @@ -510,7 +501,7 @@ class Indicator : public IndicatorBase { break; } - name += IntegerToString(iparams.max_modes) + (iparams.max_modes == 1 ? " mode" : " modes"); + name += IntegerToString(iparams.GetMaxModes()) + (iparams.GetMaxModes() == 1 ? " mode" : " modes"); return name + ")"; } @@ -765,7 +756,7 @@ class Indicator : public IndicatorBase { if (iparams.is_draw) { // Print("Drawing ", GetName(), iparams.indi_data != NULL ? (" (over " + iparams.indi_data.GetName() + ")") : ""); - for (int i = 0; i < (int)iparams.max_modes; ++i) + for (int i = 0; i < (int)iparams.GetMaxModes(); ++i) draw.DrawLineTo(GetName() + "_" + IntegerToString(i) + "_" + IntegerToString(iparams.GetDataSourceMode()), GetBarTime(0), GetEntry(0)[i], iparams.draw_window); } @@ -797,7 +788,7 @@ class Indicator : public IndicatorBase { * Returns the indicator's struct value. */ virtual IndicatorDataEntry GetEntry(int _shift = 0) { - IndicatorDataEntry _entry(iparams.max_modes); + IndicatorDataEntry _entry(iparams.GetMaxModes()); _entry = idata.GetByKey(GetBarTime(_shift), _entry); return _entry; }; diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 638d14f76..05a37919a 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -23,7 +23,7 @@ // Includes. #include "../BufferStruct.mqh" #include "../Indicator.mqh" -#include "../Storage/ValueStorage.price.h" +#include "../Storage/ValueStorage.all.h" // Structs. struct IndiFrAMAParams : IndicatorParams { diff --git a/Strategy.mqh b/Strategy.mqh index 87d258ad4..21eba8bdf 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -93,8 +93,8 @@ class Strategy : public Object { Dict ddata; Dict fdata; Dict idata; - Dict indicators_unmanaged; // Indicators list (unmanaged). - DictStruct>> indicators_managed; // Indicators list (managed). + Dict indicators_unmanaged; // Indicators list (unmanaged). + DictStruct> indicators_managed; // Indicators list (managed). DictStruct tasks; Log logger; // Log instance. MqlTick last_tick; @@ -322,7 +322,7 @@ class Strategy : public Object { /** * Returns strategy's indicators. */ - DictStruct>> GetIndicators() { return indicators_managed; } + DictStruct> GetIndicators() { return indicators_managed; } /* Struct getters */ @@ -587,10 +587,9 @@ class Strategy : public Object { /** * Sets reference to indicator. */ - template void SetIndicator(IndicatorBase *_indi, int _id = 0, bool _managed = true) { if (_managed) { - Ref> _ref = _indi; + Ref _ref = _indi; indicators_managed.Set(_id, _ref); } else { indicators_unmanaged.Set(_id, _indi); From 9ff55dc769371827b3e26edf50084b82535e5b22 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 20:46:17 +0100 Subject: [PATCH 34/78] GHA: Enables all indicator tests --- .github/workflows/test.yml | 113 ++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 86ca1ebf2..96a7d552d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -102,70 +102,69 @@ jobs: test: - Indi_AC.test - Indi_AD.test - # - Indi_ADX.test + - Indi_ADX.test - Indi_ADXW.test - Indi_AMA.test - Indi_AO.test - Indi_ASI.test - Indi_ATR.test - Indi_Alligator.test - # - Indi_AppliedPrice.test - # - Indi_BWMFI.test - # - Indi_BWZT.test - # - Indi_Bands.test - # - Indi_BearsPower.test - # - Indi_BullsPower.test - # - Indi_CCI.test - # - Indi_CHO.test - # - Indi_CHV.test - # - Indi_ColorBars.test - # - Indi_ColorCandlesDaily.test - # - Indi_ColorLine.test - # - Indi_CustomMovingAverage.test - # - Indi_DEMA.test - # - Indi_DeMarker.test - # - Indi_Demo.test - # - Indi_DetrendedPrice.test - # - Indi_Drawer.test - # - Indi_Envelopes.test - # - Indi_Force.test - # - Indi_FractalAdaptiveMA.test - # - Indi_Fractals.test - # - Indi_Gator.test - # - Indi_HeikenAshi.test - # - Indi_Ichimoku.test + - Indi_AppliedPrice.test + - Indi_BWMFI.test + - Indi_BWZT.test + - Indi_Bands.test + - Indi_BearsPower.test + - Indi_BullsPower.test + - Indi_CCI.test + - Indi_CHO.test + - Indi_CHV.test + - Indi_ColorBars.test + - Indi_ColorCandlesDaily.test + - Indi_ColorLine.test + - Indi_CustomMovingAverage.test + - Indi_DEMA.test + - Indi_DeMarker.test + - Indi_Demo.test + - Indi_DetrendedPrice.test + - Indi_Drawer.test + - Indi_Envelopes.test + - Indi_Force.test + - Indi_FractalAdaptiveMA.test + - Indi_Fractals.test + - Indi_Gator.test + - Indi_HeikenAshi.test + - Indi_Ichimoku.test - Indi_Killzones.test - # - Indi_MA.test - # - Indi_MACD.test - # - Indi_MFI.test - # - Indi_MarketFacilitationIndex.test - # - Indi_MassIndex.test - # - Indi_Momentum.test - # - Indi_OBV.test - # - Indi_OsMA.test - # - Indi_Pattern.test - # - Indi_Pivot.test - # - Indi_Price.test - # - Indi_PriceChannel.test - # - Indi_PriceFeeder.test - # - Indi_PriceVolumeTrend.test - # - Indi_RS.test - # - Indi_RSI.test - # - Indi_RVI.test - # - Indi_RateOfChange.test - # - Indi_SAR.test - # - Indi_StdDev.test - # - Indi_Stochastic.test - # - Indi_TEMA.test - # - Indi_TRIX.test - # - Indi_UltimateOscillator.test - # - Indi_VIDYA.test - # - Indi_VROC.test - # - Indi_Volumes.test - # - Indi_WPR.test - # - Indi_WilliamsAD.test - # - Indi_ZigZag.test - # - Indi_ZigZagColor.test + - Indi_MA.test + - Indi_MACD.test + - Indi_MFI.test + - Indi_MassIndex.test + - Indi_Momentum.test + - Indi_OBV.test + - Indi_OsMA.test + - Indi_Pattern.test + - Indi_Pivot.test + - Indi_Price.test + - Indi_PriceChannel.test + - Indi_PriceFeeder.test + - Indi_PriceVolumeTrend.test + - Indi_RS.test + - Indi_RSI.test + - Indi_RVI.test + - Indi_RateOfChange.test + - Indi_SAR.test + - Indi_StdDev.test + - Indi_Stochastic.test + - Indi_TEMA.test + - Indi_TRIX.test + - Indi_UltimateOscillator.test + - Indi_VIDYA.test + - Indi_VROC.test + - Indi_Volumes.test + - Indi_WPR.test + - Indi_WilliamsAD.test + - Indi_ZigZag.test + - Indi_ZigZagColor.test steps: - uses: actions/download-artifact@v2 with: From 4c5a67faacaac17a806929b4eea7a448f0a2df5b Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 21:55:00 +0100 Subject: [PATCH 35/78] Indicator: Improves constructor syntax by accepting indi_src --- Chart.struct.tf.h | 2 +- Indicator.mqh | 3 +-- Indicator.struct.h | 24 ++++++++--------- IndicatorBase.h | 14 +++++----- Indicators/Bitwise/Indi_Candle.mqh | 6 ++--- Indicators/Indi_AC.mqh | 2 +- Indicators/Indi_AD.mqh | 2 +- Indicators/Indi_ADX.mqh | 6 ++--- Indicators/Indi_ADXW.mqh | 6 ++--- Indicators/Indi_AMA.mqh | 6 ++--- Indicators/Indi_AO.mqh | 2 +- Indicators/Indi_ASI.mqh | 2 +- Indicators/Indi_ATR.mqh | 6 ++--- Indicators/Indi_Alligator.mqh | 2 +- Indicators/Indi_AppliedPrice.mqh | 3 ++- Indicators/Indi_BWMFI.mqh | 2 +- Indicators/Indi_BWZT.mqh | 2 +- Indicators/Indi_Bands.mqh | 2 +- Indicators/Indi_BearsPower.mqh | 2 +- Indicators/Indi_BullsPower.mqh | 2 +- Indicators/Indi_CCI.mqh | 2 +- Indicators/Indi_CHO.mqh | 2 +- Indicators/Indi_CHV.mqh | 2 +- Indicators/Indi_ColorBars.mqh | 2 +- Indicators/Indi_ColorCandlesDaily.mqh | 3 ++- Indicators/Indi_ColorLine.mqh | 2 +- Indicators/Indi_CustomMovingAverage.mqh | 3 ++- Indicators/Indi_DEMA.mqh | 6 ++--- Indicators/Indi_DeMarker.mqh | 2 +- Indicators/Indi_Demo.mqh | 6 ++--- Indicators/Indi_DetrendedPrice.mqh | 3 ++- Indicators/Indi_Drawer.mqh | 5 +++- Indicators/Indi_Drawer.struct.h | 4 +-- Indicators/Indi_Envelopes.mqh | 2 +- Indicators/Indi_Force.mqh | 2 +- Indicators/Indi_FractalAdaptiveMA.mqh | 2 +- Indicators/Indi_Fractals.mqh | 2 +- Indicators/Indi_Gator.mqh | 2 +- Indicators/Indi_HeikenAshi.mqh | 2 +- Indicators/Indi_Ichimoku.mqh | 2 +- Indicators/Indi_Killzones.mqh | 7 ++--- Indicators/Indi_MA.mqh | 6 ++--- Indicators/Indi_MACD.mqh | 2 +- Indicators/Indi_MFI.mqh | 2 +- Indicators/Indi_MassIndex.mqh | 2 +- Indicators/Indi_Momentum.mqh | 2 +- Indicators/Indi_OBV.mqh | 2 +- Indicators/Indi_OsMA.mqh | 2 +- Indicators/Indi_Pattern.mqh | 2 +- Indicators/Indi_Pivot.mqh | 2 +- Indicators/Indi_Price.mqh | 2 +- Indicators/Indi_PriceChannel.mqh | 3 ++- Indicators/Indi_PriceFeeder.mqh | 3 ++- Indicators/Indi_PriceVolumeTrend.mqh | 3 ++- Indicators/Indi_RS.mqh | 16 ++++++------ Indicators/Indi_RSI.mqh | 20 +++++++-------- Indicators/Indi_RVI.mqh | 2 +- Indicators/Indi_RateOfChange.mqh | 3 ++- Indicators/Indi_SAR.mqh | 2 +- Indicators/Indi_StdDev.mqh | 2 +- Indicators/Indi_Stochastic.mqh | 2 +- Indicators/Indi_TEMA.mqh | 2 +- Indicators/Indi_TRIX.mqh | 2 +- Indicators/Indi_UltimateOscillator.mqh | 3 ++- Indicators/Indi_VIDYA.mqh | 2 +- Indicators/Indi_VROC.mqh | 2 +- Indicators/Indi_Volumes.mqh | 2 +- Indicators/Indi_WPR.mqh | 2 +- Indicators/Indi_WilliamsAD.mqh | 2 +- Indicators/Indi_ZigZag.mqh | 2 +- Indicators/Indi_ZigZagColor.mqh | 3 ++- Indicators/Special/Indi_Math.mqh | 6 ++--- tests/DrawIndicatorTest.mq5 | 34 ++++++++++++------------- tests/StrategyTest-RSI.mq5 | 5 ++-- 74 files changed, 160 insertions(+), 146 deletions(-) diff --git a/Chart.struct.tf.h b/Chart.struct.tf.h index 46c80f026..cc9e1d3e9 100644 --- a/Chart.struct.tf.h +++ b/Chart.struct.tf.h @@ -122,7 +122,7 @@ struct ChartTf { * @param * _tf ENUM_TIMEFRAMES_INDEX Specify timeframe index enum. */ - static ENUM_TIMEFRAMES IndexToTf(ENUM_TIMEFRAMES_INDEX index) { + static ENUM_TIMEFRAMES const IndexToTf(ENUM_TIMEFRAMES_INDEX index) { // @todo: Convert it into a loop and using tf constant, see: TfToIndex(). switch (index) { case M1: diff --git a/Indicator.mqh b/Indicator.mqh index 423ea365b..86bea5dad 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -77,8 +77,7 @@ class Indicator : public IndicatorBase { /** * Class constructor. */ - // Indicator() : IndicatorBase() {} - Indicator(TS& _iparams) : IndicatorBase(_iparams.GetTf()) { + Indicator(const TS& _iparams, IndicatorBase* _indi_src = NULL) : IndicatorBase(_iparams.GetTf(), NULL, _indi_src) { iparams = _iparams; SetName(_iparams.name != "" ? _iparams.name : EnumToString(iparams.itype)); Init(); diff --git a/Indicator.struct.h b/Indicator.struct.h index 630ef9dd3..2fa6be1ff 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -411,19 +411,19 @@ struct IndicatorParams { }; void Init() {} /* Getters */ - string GetCustomIndicatorName() { return custom_indi_name; } - int GetDataSourceId() { return indi_data_source_id; } - int GetDataSourceMode() { return indi_data_source_mode; } - color GetIndicatorColor() { return indi_color; } - int GetMaxModes() { return (int)max_modes; } - int GetMaxParams() { return (int)max_params; } - int GetShift() { return shift; } - ENUM_DATATYPE GetDataValueType() { return dtype; } - ENUM_IDATA_SOURCE_TYPE GetDataSourceType() { return idstype; } - ENUM_IDATA_VALUE_RANGE GetIDataValueRange() { return idvrange; } - ENUM_TIMEFRAMES GetTf() { return tf.GetTf(); } + string GetCustomIndicatorName() const { return custom_indi_name; } + int GetDataSourceId() const { return indi_data_source_id; } + int GetDataSourceMode() const { return indi_data_source_mode; } + color GetIndicatorColor() const { return indi_color; } + int GetMaxModes() const { return (int)max_modes; } + int GetMaxParams() const { return (int)max_params; } + int GetShift() const { return shift; } + ENUM_DATATYPE GetDataValueType() const { return dtype; } + ENUM_IDATA_SOURCE_TYPE GetDataSourceType() const { return idstype; } + ENUM_IDATA_VALUE_RANGE GetIDataValueRange() const { return idvrange; } + ENUM_TIMEFRAMES GetTf() const { return tf.GetTf(); } template - T GetInputParam(int _index, T _default) { + T GetInputParam(int _index, T _default) const { DataParamEntry _param = input_params[_index]; switch (_param.type) { case TYPE_BOOL: diff --git a/IndicatorBase.h b/IndicatorBase.h index 9cca8daf5..fa5d42d00 100644 --- a/IndicatorBase.h +++ b/IndicatorBase.h @@ -71,7 +71,6 @@ int IndicatorCounted(int _value = 0) { */ class IndicatorBase : public Chart { protected: - // Structs. BufferStruct idata; DrawIndicator* draw; IndicatorState istate; @@ -103,23 +102,23 @@ class IndicatorBase : public Chart { /** * Class constructor. */ - IndicatorBase() { + IndicatorBase() : indi_src(NULL) { is_feeding = is_fed = false; - indi_src = NULL; } /** * Class constructor. */ - IndicatorBase(ChartParams& _cparams) : Chart(_cparams) { + IndicatorBase(ChartParams& _cparams) + : indi_src(NULL), Chart(_cparams) { is_feeding = is_fed = false; - indi_src = NULL; } /** * Class constructor. */ - IndicatorBase(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL) : Chart(_tf, _symbol) { + IndicatorBase(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL, IndicatorBase* _indi_src = NULL) + : indi_src(_indi_src), Chart(_tf, _symbol) { is_feeding = is_fed = false; indi_src = NULL; } @@ -127,7 +126,8 @@ class IndicatorBase : public Chart { /** * Class constructor. */ - IndicatorBase(ENUM_TIMEFRAMES_INDEX _tfi, string _symbol = NULL) : Chart(_tfi, _symbol) { + IndicatorBase(ENUM_TIMEFRAMES_INDEX _tfi, string _symbol = NULL, IndicatorBase* _indi_src = NULL) + : indi_src(_indi_src), Chart(_tfi, _symbol) { is_feeding = is_fed = false; indi_src = NULL; } diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index 67e05527c..3daf292a1 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -41,8 +41,8 @@ struct CandleParams : IndicatorParams { shift = _shift; tf = _tf; }; - void CandleParams(CandleParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; + void CandleParams(CandleParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _p; tf = _tf; }; }; @@ -55,7 +55,7 @@ class Indi_Candle : public Indicator { /** * Class constructor. */ - Indi_Candle(CandleParams &_params) : Indicator(_params){}; + Indi_Candle(CandleParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_Candle(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CANDLE, _tf) { iparams.tf = _tf; }; /** diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 9472946d3..945c49bf4 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -50,7 +50,7 @@ class Indi_AC : public Indicator { /** * Class constructor. */ - Indi_AC(ACParams &_params) : Indicator(_params){}; + Indi_AC(ACParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_AC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AC, _tf){}; /** diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index f5fdf23a0..ecbdd2870 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -49,7 +49,7 @@ class Indi_AD : public Indicator { /** * Class constructor. */ - Indi_AD(ADParams &_p) : Indicator(_p){}; + Indi_AD(ADParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_AD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AD, _tf) { iparams.SetTf(_tf); }; /** diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 7d1f9cba1..b0559ebb0 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -61,8 +61,8 @@ struct ADXParams : IndicatorParams { break; } }; - void ADXParams(ADXParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; + void ADXParams(ADXParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _p; tf = _tf; }; }; @@ -75,7 +75,7 @@ class Indi_ADX : public Indicator { /** * Class constructor. */ - Indi_ADX(ADXParams &_p) : Indicator(_p) {} + Indi_ADX(ADXParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_ADX(ENUM_TIMEFRAMES _tf) : Indicator(INDI_ADX, _tf) {} /** diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index 32fc007bc..6c07e48ac 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -46,8 +46,8 @@ struct ADXWParams : ADXParams { break; } }; - void ADXWParams(ADXWParams &_params) { THIS_REF = _params; } - void ADXWParams(ADXParams &_params) { THIS_REF = _params; } + void ADXWParams(ADXWParams &_p, IndicatorBase *_indi_src = NULL) { THIS_REF = _p; } + void ADXWParams(ADXParams &_p) { THIS_REF = _p; } }; /** @@ -58,7 +58,7 @@ class Indi_ADXW : public Indicator { /** * Class constructor. */ - Indi_ADXW(ADXWParams &_params) : Indicator(_params){}; + Indi_ADXW(ADXWParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_ADXW(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ADXW, _tf){}; /** diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index bed13c120..be7627719 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -63,8 +63,8 @@ struct IndiAMAParams : IndicatorParams { break; } }; - void IndiAMAParams(IndiAMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; + void IndiAMAParams(IndiAMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _p; tf = _tf; }; }; @@ -77,7 +77,7 @@ class Indi_AMA : public Indicator { /** * Class constructor. */ - Indi_AMA(IndiAMAParams &_params) : Indicator(_params){}; + Indi_AMA(IndiAMAParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_AMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AMA, _tf){}; /** diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index dad8da0e6..335e93aa3 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -53,7 +53,7 @@ class Indi_AO : public Indicator { /** * Class constructor. */ - Indi_AO(AOParams &_p) : Indicator(_p){}; + Indi_AO(AOParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_AO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_AO, _tf){}; /** diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index 7d7250127..a0fe033b8 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -49,7 +49,7 @@ class Indi_ASI : public Indicator { /** * Class constructor. */ - Indi_ASI(ASIParams &_params) : Indicator(_params){}; + Indi_ASI(ASIParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_ASI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ASI, _tf){}; /** diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index 8b84cad2a..c55565864 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -54,7 +54,7 @@ class Indi_ATR : public Indicator { /** * Class constructor. */ - Indi_ATR(ATRParams &_p) : Indicator(_p) {} + Indi_ATR(ATRParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_ATR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ATR, _tf){}; /** @@ -159,8 +159,8 @@ class Indi_ATR : public Indicator { Indi_ATR *_ptr; string _key = Util::MakeKey(_symbol, (int)_tf, _period); if (!Objects::TryGet(_key, _ptr)) { - ATRParams _params(_period, _tf); - _ptr = Objects::Set(_key, new Indi_ATR(_params)); + ATRParams _p(_period, _tf); + _ptr = Objects::Set(_key, new Indi_ATR(_p)); _ptr.SetSymbol(_symbol); } return _ptr; diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index bb22a2020..f4e714d1a 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -97,7 +97,7 @@ class Indi_Alligator : public Indicator { /** * Class constructor. */ - Indi_Alligator(AlligatorParams &_p) : Indicator(_p) {} + Indi_Alligator(AlligatorParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_Alligator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ADX, _tf){}; /** diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index 5cb963ab4..fc15a4c92 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -47,7 +47,8 @@ class Indi_AppliedPrice : public Indicator { /** * Class constructor. */ - Indi_AppliedPrice(AppliedPriceParams &_params) : Indicator(_params){}; + Indi_AppliedPrice(AppliedPriceParams &_p, IndicatorBase *_indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_AppliedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE, _tf){}; static double iAppliedPriceOnIndicator(IndicatorBase *_indi, ENUM_APPLIED_PRICE _applied_price, int _shift = 0) { diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index bd9db39ad..b4aecab2c 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -61,7 +61,7 @@ class Indi_BWMFI : public Indicator { /** * Class constructor. */ - Indi_BWMFI(BWMFIParams &_p) : Indicator(_p) {} + Indi_BWMFI(BWMFIParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_BWMFI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BWMFI, _tf) {} /** diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 4b461e975..f599b7ed3 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -51,7 +51,7 @@ class Indi_BWZT : public Indicator { /** * Class constructor. */ - Indi_BWZT(BWZTParams &_params) : Indicator(_params){}; + Indi_BWZT(BWZTParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_BWZT(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_BWZT, _tf){}; /** diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 91e1c8159..aa1ad7698 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -84,7 +84,7 @@ class Indi_Bands : public Indicator { /** * Class constructor. */ - Indi_Bands(BandsParams &_p) : Indicator(_p) {} + Indi_Bands(BandsParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_Bands(ENUM_TIMEFRAMES _tf) : Indicator(INDI_BANDS, _tf) {} /** diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index e4b539968..4f97a6a9f 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -54,7 +54,7 @@ class Indi_BearsPower : public Indicator { /** * Class constructor. */ - Indi_BearsPower(BearsPowerParams &_p) : Indicator(_p) {} + Indi_BearsPower(BearsPowerParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_BearsPower(ENUM_TIMEFRAMES _tf) : Indicator(INDI_BEARS, _tf) {} /** diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index b493f1bb8..904f95f05 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -54,7 +54,7 @@ class Indi_BullsPower : public Indicator { /** * Class constructor. */ - Indi_BullsPower(BullsPowerParams &_p) : Indicator(_p) {} + Indi_BullsPower(BullsPowerParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_BullsPower(ENUM_TIMEFRAMES _tf) : Indicator(INDI_BULLS, _tf) {} /** diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index ffec64f4f..58f17030a 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -60,7 +60,7 @@ class Indi_CCI : public Indicator { /** * Class constructor. */ - Indi_CCI(CCIParams &_p) : Indicator(_p) {} + Indi_CCI(CCIParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_CCI(ENUM_TIMEFRAMES _tf) : Indicator(INDI_CCI, _tf) {} /** diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 96f845699..fec4fac42 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -56,7 +56,7 @@ class Indi_CHO : public Indicator { /** * Class constructor. */ - Indi_CHO(CHOParams &_params) : Indicator(_params){}; + Indi_CHO(CHOParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_CHO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN, _tf){}; /** diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 824f45c53..fdebe89b2 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -57,7 +57,7 @@ class Indi_CHV : public Indicator { /** * Class constructor. */ - Indi_CHV(CHVParams &_params) : Indicator(_params){}; + Indi_CHV(CHVParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_CHV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CHAIKIN_V, _tf){}; /** diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 866b907e9..7211754a3 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -46,7 +46,7 @@ class Indi_ColorBars : public Indicator { /** * Class constructor. */ - Indi_ColorBars(ColorBarsParams &_params) : Indicator(_params){}; + Indi_ColorBars(ColorBarsParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_ColorBars(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_BARS, _tf){}; /** diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index e494b316c..ab64e7412 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -46,7 +46,8 @@ class Indi_ColorCandlesDaily : public Indicator { /** * Class constructor. */ - Indi_ColorCandlesDaily(ColorCandlesDailyParams &_params) : Indicator(_params){}; + Indi_ColorCandlesDaily(ColorCandlesDailyParams &_p, IndicatorBase *_indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_ColorCandlesDaily(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_CANDLES_DAILY, _tf){}; /** diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 6668ace94..09c2f8dca 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -47,7 +47,7 @@ class Indi_ColorLine : public Indicator { /** * Class constructor. */ - Indi_ColorLine(ColorLineParams &_params) : Indicator(_params){}; + Indi_ColorLine(ColorLineParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_ColorLine(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_COLOR_LINE, _tf){}; /** diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index 88c1cb3a0..36e55cf82 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -53,7 +53,8 @@ class Indi_CustomMovingAverage : public Indicator { /** * Class constructor. */ - Indi_CustomMovingAverage(CustomMovingAverageParams &_params) : Indicator(_params){}; + Indi_CustomMovingAverage(CustomMovingAverageParams& _p, IndicatorBase* _indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_CustomMovingAverage(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CUSTOM_MOVING_AVG, _tf){}; /** diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index f14c4cf87..a03870201 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -65,8 +65,8 @@ struct DEMAParams : IndicatorParams { break; } }; - void DEMAParams(DEMAParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; + void DEMAParams(DEMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _p; tf = _tf; }; }; @@ -79,7 +79,7 @@ class Indi_DEMA : public Indicator { /** * Class constructor. */ - Indi_DEMA(DEMAParams &_p) : Indicator(_p) {} + Indi_DEMA(DEMAParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_DEMA(ENUM_TIMEFRAMES _tf) : Indicator(INDI_DEMA, _tf) {} /** diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index 58e160022..a08f6d7e9 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -53,7 +53,7 @@ class Indi_DeMarker : public Indicator { /** * Class constructor. */ - Indi_DeMarker(DeMarkerParams &_p) : Indicator(_p) {} + Indi_DeMarker(DeMarkerParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_DeMarker(ENUM_TIMEFRAMES _tf) : Indicator(INDI_DEMARKER, _tf) {} /** diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index 1dbb97398..7ad4bdcfc 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -56,8 +56,8 @@ struct DemoIndiParams : IndicatorParams { break; } }; - void DemoIndiParams(DemoIndiParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; + void DemoIndiParams(DemoIndiParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _p; tf = _tf; }; }; @@ -70,7 +70,7 @@ class Indi_Demo : public Indicator { /** * Class constructor. */ - Indi_Demo(DemoIndiParams &_params) : Indicator(_params){}; + Indi_Demo(DemoIndiParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_Demo(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DEMO, _tf){}; /** diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 158851dea..4899163a6 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -51,7 +51,8 @@ class Indi_DetrendedPrice : public Indicator { /** * Class constructor. */ - Indi_DetrendedPrice(DetrendedPriceParams &_params) : Indicator(_params){}; + Indi_DetrendedPrice(DetrendedPriceParams &_p, IndicatorBase *_indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_DetrendedPrice(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_DETRENDED_PRICE, _tf){}; /** diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index e891597f7..61093149c 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -48,7 +48,10 @@ class Indi_Drawer : public Indicator { /** * Class constructor. */ - Indi_Drawer(const DrawerParams &_params) : Indicator(_params), redis(true) { Init(); } + Indi_Drawer(const DrawerParams &_p, IndicatorBase *_indi_src = NULL) + : Indicator(_p, _indi_src), redis(true) { + Init(); + } Indi_Drawer(ENUM_TIMEFRAMES _tf) : Indicator(INDI_DRAWER, _tf), redis(true) { Init(); } void Init() { diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index 7e27de388..940172f0e 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -41,8 +41,8 @@ struct DrawerParams : IndicatorParams { SetCustomIndicatorName("Examples\\Drawer"); SetDataValueType(TYPE_DOUBLE); }; - void DrawerParams(DrawerParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; + void DrawerParams(DrawerParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _p; tf = _tf; }; // Serializers. diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 6247c0579..59fc06e62 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -74,7 +74,7 @@ class Indi_Envelopes : public Indicator { /** * Class constructor. */ - Indi_Envelopes(EnvelopesParams &_p) : Indicator(_p) {} + Indi_Envelopes(EnvelopesParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_Envelopes(ENUM_TIMEFRAMES _tf) : Indicator(INDI_ENVELOPES, _tf) {} /** diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index da8b13ee1..f1b12bbc9 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -69,7 +69,7 @@ class Indi_Force : public Indicator { /** * Class constructor. */ - Indi_Force(ForceParams &_p) : Indicator(_p) {} + Indi_Force(ForceParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_Force(ENUM_TIMEFRAMES _tf) : Indicator(INDI_FORCE, _tf) {} /** diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 05a37919a..417f1c42c 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -53,7 +53,7 @@ class Indi_FrAMA : public Indicator { /** * Class constructor. */ - Indi_FrAMA(IndiFrAMAParams &_params) : Indicator(_params){}; + Indi_FrAMA(IndiFrAMAParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_FrAMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FRAMA, _tf){}; /** diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index 71a8a55a1..c69493d8c 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -51,7 +51,7 @@ class Indi_Fractals : public Indicator { /** * Class constructor. */ - Indi_Fractals(FractalsParams &_p) : Indicator(_p) {} + Indi_Fractals(FractalsParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_Fractals(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_FRACTALS, _tf) {} /** diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index 7588e765f..89ae2612b 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -105,7 +105,7 @@ class Indi_Gator : public Indicator { /** * Class constructor. */ - Indi_Gator(GatorParams &_p) : Indicator(_p) {} + Indi_Gator(GatorParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_Gator(ENUM_TIMEFRAMES _tf) : Indicator(INDI_GATOR, _tf) {} /** diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index 5381364e1..2ede4b3e2 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -72,7 +72,7 @@ class Indi_HeikenAshi : public Indicator { /** * Class constructor. */ - Indi_HeikenAshi(HeikenAshiParams &_p) : Indicator(_p) {} + Indi_HeikenAshi(HeikenAshiParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_HeikenAshi(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_HEIKENASHI, _tf) {} /** diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index fa1c029f1..7eb98bb85 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -86,7 +86,7 @@ class Indi_Ichimoku : public Indicator { /** * Class constructor. */ - Indi_Ichimoku(IchimokuParams &_p) : Indicator(_p) {} + Indi_Ichimoku(IchimokuParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_Ichimoku(ENUM_TIMEFRAMES _tf) : Indicator(INDI_ICHIMOKU, _tf) {} /** diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index f88948fe0..8568b7464 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -58,8 +58,8 @@ struct IndiKillzonesParams : IndicatorParams { SetShift(_shift); tf = _tf; }; - void IndiKillzonesParams(IndiKillzonesParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; + void IndiKillzonesParams(IndiKillzonesParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _p; tf = _tf; }; }; @@ -101,7 +101,8 @@ class Indi_Killzones : public Indicator { /** * Class constructor. */ - Indi_Killzones(IndiKillzonesParams &_p) : Indicator(_p) {} + Indi_Killzones(IndiKillzonesParams &_p, IndicatorBase *_indi_src = NULL) + : Indicator(_p, _indi_src) {} Indi_Killzones(ENUM_TIMEFRAMES _tf) : Indicator(INDI_KILLZONES, _tf) {} /** diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index c4ed6d7c2..ac3168c21 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -72,7 +72,7 @@ class Indi_MA : public Indicator { /** * Class constructor. */ - Indi_MA(MAParams &_p) : Indicator(_p) {} + Indi_MA(MAParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_MA(ENUM_TIMEFRAMES _tf) : Indicator(INDI_MA, _tf) {} /** @@ -689,8 +689,8 @@ class Indi_MA : public Indicator { Indi_MA *_ptr; string _key = Util::MakeKey(_symbol, (int)_tf, _period, _ma_shift, (int)_ma_method, (int)_ap); if (!Objects::TryGet(_key, _ptr)) { - MAParams _params(_period, _ma_shift, _ma_method, _ap); - _ptr = Objects::Set(_key, new Indi_MA(_params)); + MAParams _p(_period, _ma_shift, _ma_method, _ap); + _ptr = Objects::Set(_key, new Indi_MA(_p)); _ptr.SetSymbol(_symbol); } return _ptr; diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index 2d42406a6..74caa4ce1 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -58,7 +58,7 @@ class Indi_MACD : public Indicator { /** * Class constructor. */ - Indi_MACD(MACDParams &_p) : Indicator(_p) {} + Indi_MACD(MACDParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_MACD(ENUM_TIMEFRAMES _tf) : Indicator(INDI_MACD, _tf) {} /** diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index e3e8f815c..ee77aac06 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -54,7 +54,7 @@ class Indi_MFI : public Indicator { /** * Class constructor. */ - Indi_MFI(MFIParams &_p) : Indicator(_p) {} + Indi_MFI(MFIParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_MFI(ENUM_TIMEFRAMES _tf) : Indicator(INDI_MFI, _tf) {} /** diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index c007b744c..045702419 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -53,7 +53,7 @@ class Indi_MassIndex : public Indicator { /** * Class constructor. */ - Indi_MassIndex(MassIndexParams &_params) : Indicator(_params){}; + Indi_MassIndex(MassIndexParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_MassIndex(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_MASS_INDEX, _tf){}; /** diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 740049890..99396448c 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -64,7 +64,7 @@ class Indi_Momentum : public Indicator { /** * Class constructor. */ - Indi_Momentum(MomentumParams &_p) : Indicator(_p) {} + Indi_Momentum(MomentumParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_Momentum(ENUM_TIMEFRAMES _tf) : Indicator(INDI_MOMENTUM, _tf) {} /** diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 06f73aa4f..ea512882b 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -67,7 +67,7 @@ class Indi_OBV : public Indicator { /** * Class constructor. */ - Indi_OBV(OBVParams &_p) : Indicator(_p) {} + Indi_OBV(OBVParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_OBV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_OBV, _tf) {} /** diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 4d5306c96..f05170ec3 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -57,7 +57,7 @@ class Indi_OsMA : public Indicator { /** * Class constructor. */ - Indi_OsMA(OsMAParams &_p) : Indicator(_p) {} + Indi_OsMA(OsMAParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_OsMA(ENUM_TIMEFRAMES _tf) : Indicator(INDI_OSMA, _tf) {} /** diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index 145b7ce31..aea4946c0 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -49,7 +49,7 @@ class Indi_Pattern : public Indicator { /** * Class constructor. */ - Indi_Pattern(IndiPatternParams &_params) : Indicator(_params){}; + Indi_Pattern(IndiPatternParams& _p, IndicatorBase* _indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_Pattern(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PATTERN, _tf) { iparams.tf = _tf; }; /** diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index 2d4cb411b..aee038599 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -48,7 +48,7 @@ class Indi_Pivot : public Indicator { /** * Class constructor. */ - Indi_Pivot(IndiPivotParams &_params) : Indicator(_params){}; + Indi_Pivot(IndiPivotParams& _p, IndicatorBase* _indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_Pivot(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PIVOT, _tf) { iparams.tf = _tf; }; /** diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index 14d8f620e..38c8b65f7 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -55,7 +55,7 @@ class Indi_Price : public Indicator { /** * Class constructor. */ - Indi_Price(PriceIndiParams &_p) : Indicator(_p){}; + Indi_Price(PriceIndiParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_Price(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE, _tf){}; /** diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index e87435ca5..92897aef0 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -48,7 +48,8 @@ class Indi_PriceChannel : public Indicator { /** * Class constructor. */ - Indi_PriceChannel(PriceChannelParams &_params) : Indicator(_params){}; + Indi_PriceChannel(PriceChannelParams& _p, IndicatorBase* _indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_PriceChannel(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_CHANNEL, _tf){}; /** diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index 30a984342..1db57347f 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -61,7 +61,8 @@ class Indi_PriceFeeder : public Indicator { /** * Class constructor. */ - Indi_PriceFeeder(PriceFeederIndiParams& _p) : Indicator(_p){}; + Indi_PriceFeeder(PriceFeederIndiParams& _p, IndicatorBase* _indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_PriceFeeder(const double& _price_data[], int _total = 0) : Indicator(INDI_PRICE_FEEDER) { ArrayCopy(iparams.price_data, _price_data); }; diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index a1ae526dd..26628660b 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -48,7 +48,8 @@ class Indi_PriceVolumeTrend : public Indicator { /** * Class constructor. */ - Indi_PriceVolumeTrend(PriceVolumeTrendParams &_params) : Indicator(_params){}; + Indi_PriceVolumeTrend(PriceVolumeTrendParams &_p, IndicatorBase *_indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_PriceVolumeTrend(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_PRICE_VOLUME_TREND, _tf){}; /** diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index c1d352bb3..220ebdf2e 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -51,22 +51,22 @@ class Indi_RS : public Indicator { /** * Class constructor. */ - Indi_RS(RSParams &_params) : Indicator(_params) { Init(); }; + Indi_RS(RSParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) { Init(); }; Indi_RS(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RS, _tf) { Init(); }; void Init() { if (iparams.GetDataSourceType() == IDATA_MATH) { - PriceIndiParams _iprice_params(); + PriceIndiParams _iprice_p(); // @todo Symbol should be already defined for a chart. // @todo If it's not, move initialization to GetValue()/GetEntry() method. Indi_Price *_iprice = Indi_Price::GetCached(GetSymbol(), GetTf(), 0); - MathParams _imath0_params(MATH_OP_SUB, PRICE_CLOSE, 0, PRICE_CLOSE, 1); - MathParams _imath1_params(MATH_OP_SUB, PRICE_CLOSE, 1, PRICE_CLOSE, 0); - _imath0_params.SetTf(GetTf()); - _imath1_params.SetTf(GetTf()); - Ref _imath0 = new Indi_Math(_imath0_params); - Ref _imath1 = new Indi_Math(_imath1_params); + MathParams _imath0_p(MATH_OP_SUB, PRICE_CLOSE, 0, PRICE_CLOSE, 1); + MathParams _imath1_p(MATH_OP_SUB, PRICE_CLOSE, 1, PRICE_CLOSE, 0); + _imath0_p.SetTf(GetTf()); + _imath1_p.SetTf(GetTf()); + Ref _imath0 = new Indi_Math(_imath0_p); + Ref _imath1 = new Indi_Math(_imath1_p); _imath0.Ptr().SetDataSource(_iprice, false, 0); _imath1.Ptr().SetDataSource(_iprice, false, 0); imath.Set(0, _imath0); diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index d5aff005c..d970edf44 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -57,8 +57,8 @@ struct RSIParams : IndicatorParams { SetCustomIndicatorName("Examples\\RSI"); SetPeriod(_period); }; - void RSIParams(RSIParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; + void RSIParams(RSIParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _p; tf = _tf; }; // Getters. @@ -95,7 +95,7 @@ class Indi_RSI : public Indicator { /** * Class constructor. */ - Indi_RSI(const RSIParams &_params) : Indicator(_params) {} + Indi_RSI(RSIParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_RSI(ENUM_TIMEFRAMES _tf) : Indicator(INDI_RSI, _tf) {} /** @@ -376,25 +376,25 @@ class Indi_RSI : public Indicator { */ virtual IndicatorBase *FetchDataSource(ENUM_INDICATOR_TYPE _id) { if (_id == INDI_BANDS) { - BandsParams bands_params(); + BandsParams bands_params; return new Indi_Bands(bands_params); } else if (_id == INDI_CCI) { - CCIParams cci_params(); + CCIParams cci_params; return new Indi_CCI(cci_params); } else if (_id == INDI_ENVELOPES) { - EnvelopesParams env_params(); + EnvelopesParams env_params; return new Indi_Envelopes(env_params); } else if (_id == INDI_MOMENTUM) { - MomentumParams mom_params(); + MomentumParams mom_params; return new Indi_Momentum(mom_params); } else if (_id == INDI_MA) { - MAParams ma_params(); + MAParams ma_params; return new Indi_MA(ma_params); } else if (_id == INDI_RSI) { - RSIParams _rsi_params(); + RSIParams _rsi_params; return new Indi_RSI(_rsi_params); } else if (_id == INDI_STDDEV) { - StdDevParams stddev_params(); + StdDevParams stddev_params; return new Indi_StdDev(stddev_params); } diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index e7b278129..c96116eed 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -52,7 +52,7 @@ class Indi_RVI : public Indicator { /** * Class constructor. */ - Indi_RVI(const RVIParams &_p) : Indicator(_p) {} + Indi_RVI(const RVIParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_RVI(ENUM_TIMEFRAMES _tf) : Indicator(INDI_RVI, _tf) {} /** diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index 4fc5fc7e3..bdfc9e4fc 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -50,7 +50,8 @@ class Indi_RateOfChange : public Indicator { /** * Class constructor. */ - Indi_RateOfChange(RateOfChangeParams &_params) : Indicator(_params){}; + Indi_RateOfChange(RateOfChangeParams &_p, IndicatorBase *_indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_RateOfChange(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_RATE_OF_CHANGE, _tf){}; /** diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index bb08d262d..31e1dcf6c 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -53,7 +53,7 @@ class Indi_SAR : public Indicator { /** * Class constructor. */ - Indi_SAR(SARParams &_p) : Indicator(_p) {} + Indi_SAR(SARParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_SAR(ENUM_TIMEFRAMES _tf) : Indicator(INDI_SAR, _tf) {} /** diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index 4687dec08..2d377a54f 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -70,7 +70,7 @@ class Indi_StdDev : public Indicator { /** * Class constructor. */ - Indi_StdDev(StdDevParams &_p) : Indicator(_p) {} + Indi_StdDev(StdDevParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_StdDev(ENUM_TIMEFRAMES _tf) : Indicator(INDI_STDDEV, _tf) {} /** diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index e498d9740..162097043 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -60,7 +60,7 @@ class Indi_Stochastic : public Indicator { /** * Class constructor. */ - Indi_Stochastic(StochParams &_p) : Indicator(_p) {} + Indi_Stochastic(StochParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_Stochastic(ENUM_TIMEFRAMES _tf) : Indicator(INDI_STOCHASTIC, _tf) {} /** diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index a04359918..35007603b 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -53,7 +53,7 @@ class Indi_TEMA : public Indicator { /** * Class constructor. */ - Indi_TEMA(TEMAParams &_params) : Indicator(_params){}; + Indi_TEMA(TEMAParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_TEMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TEMA, _tf){}; /** diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index 8bb2141f9..e00e299de 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -52,7 +52,7 @@ class Indi_TRIX : public Indicator { /** * Class constructor. */ - Indi_TRIX(TRIXParams &_params) : Indicator(_params){}; + Indi_TRIX(TRIXParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_TRIX(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_TRIX, _tf){}; /** diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index c479a552b..442ae9da5 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -62,7 +62,8 @@ class Indi_UltimateOscillator : public Indicator { /** * Class constructor. */ - Indi_UltimateOscillator(UltimateOscillatorParams &_params) : Indicator(_params){}; + Indi_UltimateOscillator(UltimateOscillatorParams &_p, IndicatorBase *_indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_UltimateOscillator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ULTIMATE_OSCILLATOR, _tf){}; /** diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index ae77b51c0..a27330737 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -56,7 +56,7 @@ class Indi_VIDYA : public Indicator { /** * Class constructor. */ - Indi_VIDYA(VIDYAParams &_params) : Indicator(_params){}; + Indi_VIDYA(VIDYAParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_VIDYA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VIDYA, _tf){}; /** diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index b8eb6b318..dc6a6ee3e 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -50,7 +50,7 @@ class Indi_VROC : public Indicator { /** * Class constructor. */ - Indi_VROC(VROCParams &_params) : Indicator(_params){}; + Indi_VROC(VROCParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_VROC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf){}; /** diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index a4a6cf5aa..00fe5d563 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -49,7 +49,7 @@ class Indi_Volumes : public Indicator { /** * Class constructor. */ - Indi_Volumes(VolumesParams &_params) : Indicator(_params){}; + Indi_Volumes(VolumesParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_Volumes(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VOLUMES, _tf){}; /** diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index 827c01c45..928b1b420 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -52,7 +52,7 @@ class Indi_WPR : public Indicator { /** * Class constructor. */ - Indi_WPR(WPRParams &_p) : Indicator(_p) {} + Indi_WPR(WPRParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_WPR(ENUM_TIMEFRAMES _tf) : Indicator(INDI_WPR, _tf) {} /** diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index 2c6f9079e..258719a2c 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -46,7 +46,7 @@ class Indi_WilliamsAD : public Indicator { /** * Class constructor. */ - Indi_WilliamsAD(WilliamsADParams &_params) : Indicator(_params){}; + Indi_WilliamsAD(WilliamsADParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_WilliamsAD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_WILLIAMS_AD, _tf){}; /** diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index 2a5f8b883..6f4429bb1 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -59,7 +59,7 @@ class Indi_ZigZag : public Indicator { /** * Class constructor. */ - Indi_ZigZag(ZigZagParams &_p) : Indicator(_p) {} + Indi_ZigZag(ZigZagParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} Indi_ZigZag(ENUM_TIMEFRAMES _tf) : Indicator(INDI_ZIGZAG, _tf) {} /** diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index f09c80792..556fef64c 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -54,7 +54,8 @@ class Indi_ZigZagColor : public Indicator { /** * Class constructor. */ - Indi_ZigZagColor(ZigZagColorParams &_params) : Indicator(_params){}; + Indi_ZigZagColor(ZigZagColorParams& _p, IndicatorBase* _indi_src = NULL) + : Indicator(_p, _indi_src){}; Indi_ZigZagColor(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_VROC, _tf){}; /** diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 46c38eea9..220678cf6 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -77,8 +77,8 @@ struct MathParams : IndicatorParams { tf = _tf; }; - void MathParams(MathParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _params; + void MathParams(MathParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + this = _p; tf = _tf; }; }; @@ -91,7 +91,7 @@ class Indi_Math : public Indicator { /** * Class constructor. */ - Indi_Math(MathParams &_params) : Indicator(_params){}; + Indi_Math(MathParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src){}; Indi_Math(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_SPECIAL_MATH, _tf){}; /** diff --git a/tests/DrawIndicatorTest.mq5 b/tests/DrawIndicatorTest.mq5 index f13ef9837..a289d8bf8 100644 --- a/tests/DrawIndicatorTest.mq5 +++ b/tests/DrawIndicatorTest.mq5 @@ -36,7 +36,7 @@ // Global variables. Chart *chart; -Dict indis; +Dict indis; int bar_processed; /** @@ -64,8 +64,8 @@ void OnTick() { if (chart.IsNewBar()) { bar_processed++; - for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { - Indicator *_indi = iter.Value(); + for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { + IndicatorBase *_indi = iter.Value(); _indi.OnTick(); IndicatorDataEntry _entry = _indi.GetEntry(); if (_indi.Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY)) && _entry.IsValid()) { @@ -81,7 +81,7 @@ void OnTick() { void OnDeinit(const int reason) { delete chart; - for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { + for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { delete iter.Value(); } } @@ -98,7 +98,7 @@ bool InitIndicators() { // Moving Average. MAParams ma_params(13, 10, MODE_SMA, PRICE_OPEN); - Indicator *indi_ma = new Indi_MA(ma_params); + IndicatorBase *indi_ma = new Indi_MA(ma_params); indis.Set(INDI_MA, indi_ma); // Relative Strength Index (RSI). @@ -109,38 +109,38 @@ bool InitIndicators() { // Demo/Dummy Indicator. DemoIndiParams demo_params; - Indicator *indi_demo = new Indi_Demo(demo_params); + IndicatorBase *indi_demo = new Indi_Demo(demo_params); indis.Set(INDI_DEMO, indi_demo); // Current Price (used by custom indicators) . PriceIndiParams price_params(); price_params.SetDraw(clrGreenYellow); - Indicator *indi_price = new Indi_Price(price_params); + IndicatorBase *indi_price = new Indi_Price(price_params); indis.Set(INDI_PRICE, indi_price); // Bollinger Bands over Price indicator. PriceIndiParams price_params_4_bands(); - Indicator *indi_price_4_bands = new Indi_Price(price_params_4_bands); + IndicatorBase *indi_price_4_bands = new Indi_Price(price_params_4_bands); BandsParams bands_on_price_params(); bands_on_price_params.SetDraw(clrCadetBlue); - bands_on_price_params.SetDataSource(indi_price_4_bands, true, INDI_PRICE_MODE_OPEN); - indis.Set(INDI_BANDS_ON_PRICE, new Indi_Bands(bands_on_price_params)); + // bands_on_price_params.SetDataSource(indi_price_4_bands, true, INDI_PRICE_MODE_OPEN); + indis.Set(INDI_BANDS_ON_PRICE, new Indi_Bands(bands_on_price_params, indi_price_4_bands)); // Moving Average (MA) over Price indicator. PriceIndiParams price_params_4_ma(); - Indicator *indi_price_4_ma = new Indi_Price(price_params_4_ma); + IndicatorBase *indi_price_4_ma = new Indi_Price(price_params_4_ma); MAParams ma_on_price_params(); ma_on_price_params.SetDraw(clrYellowGreen); - ma_on_price_params.SetDataSource(indi_price_4_ma, true, INDI_PRICE_MODE_OPEN); + // ma_on_price_params.SetDataSource(indi_price_4_ma, true, INDI_PRICE_MODE_OPEN); ma_on_price_params.SetIndicatorType(INDI_MA_ON_PRICE); - Indicator *indi_ma_on_price = new Indi_MA(ma_on_price_params); + IndicatorBase *indi_ma_on_price = new Indi_MA(ma_on_price_params, indi_price_4_ma); indis.Set(INDI_MA_ON_PRICE, indi_ma_on_price); // Relative Strength Index (RSI) over Price indicator. PriceIndiParams price_params_4_rsi(); - Indicator *indi_price_4_rsi = new Indi_Price(price_params_4_rsi); + IndicatorBase *indi_price_4_rsi = new Indi_Price(price_params_4_rsi); RSIParams rsi_on_price_params(); - rsi_on_price_params.SetDataSource(indi_price_4_rsi, true, INDI_PRICE_MODE_OPEN); + // rsi_on_price_params.SetDataSource(indi_price_4_rsi, true, INDI_PRICE_MODE_OPEN); rsi_on_price_params.SetDraw(clrBisque, 1); indis.Set(INDI_RSI_ON_PRICE, indi_price_4_rsi); @@ -151,8 +151,8 @@ bool InitIndicators() { * Print indicators. */ bool PrintIndicators(string _prefix = "") { - for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { - Indicator *_indi = iter.Value(); + for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { + IndicatorBase *_indi = iter.Value(); MqlParam _value = _indi.GetEntryValue(); if (GetLastError() == ERR_INDICATOR_DATA_NOT_FOUND || GetLastError() == ERR_USER_ERROR_FIRST + ERR_USER_INVALID_BUFF_NUM) { diff --git a/tests/StrategyTest-RSI.mq5 b/tests/StrategyTest-RSI.mq5 index 77b7ffa8a..0327f4cd2 100644 --- a/tests/StrategyTest-RSI.mq5 +++ b/tests/StrategyTest-RSI.mq5 @@ -57,10 +57,11 @@ class Stg_RSI : public Strategy { float PriceStop(ENUM_ORDER_TYPE _cmd, ENUM_ORDER_TYPE_VALUE _mode, int _method = 0, float _level = 0.0) { Indi_RSI *_indi = GetIndicator(); + RSIParams _iparams = _indi.GetParams();; double _trail = _level * Market().GetPipSize(); int _direction = Order::OrderDirection(_cmd, _mode); - return _direction > 0 ? (float)_indi.GetPrice(PRICE_HIGH, _indi.GetHighest(_indi.GetPeriod() * 2)) - : (float)_indi.GetPrice(PRICE_LOW, _indi.GetLowest(_indi.GetPeriod() * 2)); + return _direction > 0 ? (float)_indi.GetPrice(PRICE_HIGH, _indi.GetHighest(_iparams.GetPeriod() * 2)) + : (float)_indi.GetPrice(PRICE_LOW, _indi.GetLowest(_iparams.GetPeriod() * 2)); } }; From 068ea4118c3a97dcb713940f8a6a29c97e17d2ca Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 22:46:26 +0100 Subject: [PATCH 36/78] Indicators/Indi_Drawer: Comments out previously disabled code --- Indicators/Indi_Drawer.mqh | 59 ++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index 61093149c..f4ae68bba 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -221,39 +221,36 @@ class Indi_Drawer : public Indicator { double diff; int _mode = _obj.GetDataSourceMode(); - /* - @fixit - if (!_obj.aux_data.KeyExists(_bar_time_prev, data_position)) { - // No previous SMMA-based average gain and loss. Calculating SMA-based ones. - double sum_gain = 0; - double sum_loss = 0; - - for (i = 1; i < (int)_period; i++) { - double price_new = _indi[(_shift + 1) + i - 1][_mode]; - double price_old = _indi[(_shift + 1) + i][_mode]; - - if (price_new == 0.0 || price_old == 0.0) { - // Missing history price data, skipping calculations. - return 0.0; - } - - diff = price_new - price_old; - - if (diff > 0) { - sum_gain += diff; - } else { - sum_loss += -diff; - } - } - - // Calculating SMA-based values. - last_data.avg_gain = sum_gain / _period; - last_data.avg_loss = sum_loss / _period; + if (!_obj.aux_data.KeyExists(_bar_time_prev, data_position)) { + // No previous SMMA-based average gain and loss. Calculating SMA-based ones. + double sum_gain = 0; + double sum_loss = 0; + + for (i = 1; i < (int)_period; i++) { + double price_new = _indi[(_shift + 1) + i - 1][_mode]; + double price_old = _indi[(_shift + 1) + i][_mode]; + + if (price_new == 0.0 || price_old == 0.0) { + // Missing history price data, skipping calculations. + return 0.0; + } + + diff = price_new - price_old; + + if (diff > 0) { + sum_gain += diff; } else { - // Data already exists, retrieving it by position got by KeyExists(). - last_data = _obj.aux_data.GetByPos(data_position); + sum_loss += -diff; } - */ + } + + // Calculating SMA-based values. + last_data.avg_gain = sum_gain / _period; + last_data.avg_loss = sum_loss / _period; + } else { + // Data already exists, retrieving it by position got by KeyExists(). + last_data = _obj.aux_data.GetByPos(data_position); + } diff = _indi[_shift][_mode] - _indi[_shift + 1][_mode]; From 6becf21556841f2ea1c69c42c5eb915f7f188ba5 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 3 Oct 2021 00:07:55 +0100 Subject: [PATCH 37/78] Indicator: Adds GetFlag() from IndicatorBase --- Indicator.mqh | 10 ++++++++++ IndicatorBase.h | 8 -------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Indicator.mqh b/Indicator.mqh index 86bea5dad..e4e2ed682 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -140,6 +140,16 @@ class Indicator : public IndicatorBase { } } + /* Getters */ + + /** + * Gets an indicator property flag. + */ + bool GetFlag(INDICATOR_ENTRY_FLAGS _prop, int _shift = -1) { + IndicatorDataEntry _entry = GetEntry(_shift >= 0 ? _shift : iparams.GetShift()); + return _entry.CheckFlag(_prop); + } + /* Buffer methods */ virtual string CacheKey() { return GetName(); } diff --git a/IndicatorBase.h b/IndicatorBase.h index 9abbfccbb..f6520fb92 100644 --- a/IndicatorBase.h +++ b/IndicatorBase.h @@ -450,14 +450,6 @@ class IndicatorBase : public Chart { */ virtual int GetModeCount() { return 0; } - /** - * Gets an indicator property flag. - */ - bool GetFlag(INDICATOR_ENTRY_FLAGS _prop, int _shift = -1) { - IndicatorDataEntry _entry = GetEntry(_shift >= 0 ? _shift : iparams.GetShift()); - return _entry.CheckFlag(_prop); - } - /* State methods */ /** From ef62ae19a672a66bfc039d517110c980cb50af3c Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 3 Oct 2021 00:08:04 +0100 Subject: [PATCH 38/78] Revert "Indicators/Indi_Drawer: Comments out previously disabled code" This reverts commit 068ea4118c3a97dcb713940f8a6a29c97e17d2ca. --- Indicators/Indi_Drawer.mqh | 59 ++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index f4ae68bba..61093149c 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -221,36 +221,39 @@ class Indi_Drawer : public Indicator { double diff; int _mode = _obj.GetDataSourceMode(); - if (!_obj.aux_data.KeyExists(_bar_time_prev, data_position)) { - // No previous SMMA-based average gain and loss. Calculating SMA-based ones. - double sum_gain = 0; - double sum_loss = 0; - - for (i = 1; i < (int)_period; i++) { - double price_new = _indi[(_shift + 1) + i - 1][_mode]; - double price_old = _indi[(_shift + 1) + i][_mode]; - - if (price_new == 0.0 || price_old == 0.0) { - // Missing history price data, skipping calculations. - return 0.0; - } - - diff = price_new - price_old; - - if (diff > 0) { - sum_gain += diff; + /* + @fixit + if (!_obj.aux_data.KeyExists(_bar_time_prev, data_position)) { + // No previous SMMA-based average gain and loss. Calculating SMA-based ones. + double sum_gain = 0; + double sum_loss = 0; + + for (i = 1; i < (int)_period; i++) { + double price_new = _indi[(_shift + 1) + i - 1][_mode]; + double price_old = _indi[(_shift + 1) + i][_mode]; + + if (price_new == 0.0 || price_old == 0.0) { + // Missing history price data, skipping calculations. + return 0.0; + } + + diff = price_new - price_old; + + if (diff > 0) { + sum_gain += diff; + } else { + sum_loss += -diff; + } + } + + // Calculating SMA-based values. + last_data.avg_gain = sum_gain / _period; + last_data.avg_loss = sum_loss / _period; } else { - sum_loss += -diff; + // Data already exists, retrieving it by position got by KeyExists(). + last_data = _obj.aux_data.GetByPos(data_position); } - } - - // Calculating SMA-based values. - last_data.avg_gain = sum_gain / _period; - last_data.avg_loss = sum_loss / _period; - } else { - // Data already exists, retrieving it by position got by KeyExists(). - last_data = _obj.aux_data.GetByPos(data_position); - } + */ diff = _indi[_shift][_mode] - _indi[_shift + 1][_mode]; From be58886e779cdcbaef2bd4ea8d483f35c1d0d96b Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 3 Oct 2021 01:07:59 +0100 Subject: [PATCH 39/78] GHA: Sets ignore-warnings to true --- .github/workflows/compile.yml | 1 + .github/workflows/test.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index ee997c3c7..c6007bd57 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -19,6 +19,7 @@ jobs: - name: Compile uses: fx31337/mql-compile-action@master with: + ignore-warnings: true init-platform: true verbose: true - name: Print compiled files diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55bfb7bc7..9fd471907 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,7 @@ jobs: - name: Compile uses: fx31337/mql-compile-action@master with: + ignore-warnings: true init-platform: true verbose: true - name: Print compiled files From 0be2f03d3f56d62e7bab3f7819da7bd452b75591 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Mon, 4 Oct 2021 13:27:30 +0200 Subject: [PATCH 40/78] Fixed passing of data source through Indicator class. Note additional arguments required for Indicator constructor (`bool _managed = true, int _mode = 0`). These parameters need to be passed to `Indi_Bands` (as an example) and all other indicators. `_managed` flag indicates that passed indicator pointer will be automatically deleted by the target indicator. Without the flag, you must delete source indicator by your own, when target indicator won't be longer used. --- Indicator.mqh | 6 +++++- IndicatorBase.h | 15 ++++----------- Indicators/Indi_Bands.mqh | 3 ++- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Indicator.mqh b/Indicator.mqh index e4e2ed682..73a4ad1f7 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -77,9 +77,13 @@ class Indicator : public IndicatorBase { /** * Class constructor. */ - Indicator(const TS& _iparams, IndicatorBase* _indi_src = NULL) : IndicatorBase(_iparams.GetTf(), NULL, _indi_src) { + Indicator(const TS& _iparams, IndicatorBase* _indi_src = NULL, bool _indi_managed = true, int _indi_mode = 0) + : IndicatorBase(_iparams.GetTf(), NULL) { iparams = _iparams; SetName(_iparams.name != "" ? _iparams.name : EnumToString(iparams.itype)); + if (_indi_src != NULL) { + SetDataSource(_indi_src, _indi_managed, _indi_mode); + } Init(); } Indicator(const TS& _iparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorBase(_tf) { diff --git a/IndicatorBase.h b/IndicatorBase.h index f6520fb92..7951c1675 100644 --- a/IndicatorBase.h +++ b/IndicatorBase.h @@ -102,23 +102,17 @@ class IndicatorBase : public Chart { /** * Class constructor. */ - IndicatorBase() : indi_src(NULL) { - is_feeding = is_fed = false; - } + IndicatorBase() : indi_src(NULL) { is_feeding = is_fed = false; } /** * Class constructor. */ - IndicatorBase(ChartParams& _cparams) - : indi_src(NULL), Chart(_cparams) { - is_feeding = is_fed = false; - } + IndicatorBase(ChartParams& _cparams) : indi_src(NULL), Chart(_cparams) { is_feeding = is_fed = false; } /** * Class constructor. */ - IndicatorBase(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL, IndicatorBase* _indi_src = NULL) - : indi_src(_indi_src), Chart(_tf, _symbol) { + IndicatorBase(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL) : Chart(_tf, _symbol) { is_feeding = is_fed = false; indi_src = NULL; } @@ -126,8 +120,7 @@ class IndicatorBase : public Chart { /** * Class constructor. */ - IndicatorBase(ENUM_TIMEFRAMES_INDEX _tfi, string _symbol = NULL, IndicatorBase* _indi_src = NULL) - : indi_src(_indi_src), Chart(_tfi, _symbol) { + IndicatorBase(ENUM_TIMEFRAMES_INDEX _tfi, string _symbol = NULL) : Chart(_tfi, _symbol) { is_feeding = is_fed = false; indi_src = NULL; } diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index aa1ad7698..961af7618 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -84,7 +84,8 @@ class Indi_Bands : public Indicator { /** * Class constructor. */ - Indi_Bands(BandsParams &_p, IndicatorBase *_indi_src = NULL) : Indicator(_p, _indi_src) {} + Indi_Bands(BandsParams &_p, IndicatorBase *_indi_src = NULL, bool _managed = true, int _mode = 0) + : Indicator(_p, _indi_src, _managed, _mode) {} Indi_Bands(ENUM_TIMEFRAMES _tf) : Indicator(INDI_BANDS, _tf) {} /** From c7f1eee13c9bfd84fd5f12f825cfe1e8954956c8 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Mon, 4 Oct 2021 14:08:52 +0200 Subject: [PATCH 41/78] Fixed Indi_AppliedPrice invalid pointer access. --- Indicators/Indi_AppliedPrice.mqh | 3 +++ Indicators/Indi_Drawer.struct.h | 1 + Indicators/tests/Indi_AppliedPrice.test.mq5 | 9 ++++++--- tests/DrawIndicatorTest.mq5 | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index fc15a4c92..14aff825f 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -69,6 +69,9 @@ class Indi_AppliedPrice : public Indicator { // Future validation of indi_src will check if we set mode for source indicator // (e.g. for applied price of Indi_Price). iparams.SetDataSourceMode(GetAppliedPrice()); + } else { + Print("Indi_AppliedPrice requires source indicator to be set via SetDataSource()!"); + DebugBreak(); } // @fixit diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index 940172f0e..9d6948dd8 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -64,4 +64,5 @@ SerializerNodeType DrawerParams::Serialize(Serializer &s) { struct DrawerGainLossData { double avg_gain; double avg_loss; + DrawerGainLossData() { avg_gain = avg_loss = 0.0; } }; diff --git a/Indicators/tests/Indi_AppliedPrice.test.mq5 b/Indicators/tests/Indi_AppliedPrice.test.mq5 index df8173f45..e635ac3b6 100644 --- a/Indicators/tests/Indi_AppliedPrice.test.mq5 +++ b/Indicators/tests/Indi_AppliedPrice.test.mq5 @@ -22,20 +22,23 @@ // Includes. #include "../../Test.mqh" #include "../Indi_AppliedPrice.mqh" +#include "../Indi_Price.mqh" /** * @file * Test functionality of Indi_AppliedPrice indicator class. */ -Indi_AppliedPrice indi(PERIOD_CURRENT); +Indi_Price *indi_source_price = new Indi_Price(); +AppliedPriceParams indi_params(); +Ref indi = new Indi_AppliedPrice(indi_params, indi_source_price); /** * Implements Init event handler. */ int OnInit() { bool _result = true; - assertTrueOrFail(indi.IsValid(), "Error on IsValid!"); + assertTrueOrFail(indi.IsSet(), "Error on IsSet!"); // assertTrueOrFail(indi.IsValidEntry(), "Error on IsValidEntry!"); return (_result && _LastError == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED); } @@ -50,7 +53,7 @@ void OnTick() { // Process ticks each minute. if (_tick_new.time % 3600 < _tick_last.time % 3600) { // Print indicator values every hour. - Print(indi.ToString()); + Print(indi.Ptr().ToString()); } } _tick_last = _tick_new; diff --git a/tests/DrawIndicatorTest.mq5 b/tests/DrawIndicatorTest.mq5 index a289d8bf8..c9fd8436f 100644 --- a/tests/DrawIndicatorTest.mq5 +++ b/tests/DrawIndicatorTest.mq5 @@ -124,7 +124,7 @@ bool InitIndicators() { BandsParams bands_on_price_params(); bands_on_price_params.SetDraw(clrCadetBlue); // bands_on_price_params.SetDataSource(indi_price_4_bands, true, INDI_PRICE_MODE_OPEN); - indis.Set(INDI_BANDS_ON_PRICE, new Indi_Bands(bands_on_price_params, indi_price_4_bands)); + indis.Set(INDI_BANDS_ON_PRICE, new Indi_Bands(bands_on_price_params, indi_price_4_bands, true)); // Moving Average (MA) over Price indicator. PriceIndiParams price_params_4_ma(); From c471aeea735c04be07f19e0006cec48d71d616c1 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Mon, 4 Oct 2021 15:08:45 +0200 Subject: [PATCH 42/78] Fixes Indi_CustomMovingAverage for MT4. --- Indicators/Indi_CustomMovingAverage.mqh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index 36e55cf82..196870871 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -37,7 +37,11 @@ struct CustomMovingAverageParams : IndicatorParams { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_ICUSTOM); +#ifdef __MQL5__ SetCustomIndicatorName("Examples\\Custom Moving Average"); +#else + SetCustomIndicatorName("Custom Moving Averages"); +#endif shift = _shift; smooth_method = _smooth_method; smooth_period = _smooth_period; From 9f283dc9ee57f189df24d58522d40ef5faf1152c Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Mon, 4 Oct 2021 17:44:27 +0200 Subject: [PATCH 43/78] Finally fixed ValueStorage.volume.h and ChartStatic::iVolume() by general, as it propagated the missing data error too far. --- Chart.struct.static.h | 12 +++++++++--- Indicators/Indi_Volumes.mqh | 7 ------- Storage/ValueStorage.volume.h | 10 +++++++++- tests/IndicatorsTest.mq5 | 5 ----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Chart.struct.static.h b/Chart.struct.static.h index 937056401..d99b1e523 100644 --- a/Chart.struct.static.h +++ b/Chart.struct.static.h @@ -277,10 +277,16 @@ struct ChartStatic { * * If local history is empty (not loaded), function returns 0. */ - static long iVolume(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, uint _shift = 0) { + static long iVolume(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) { #ifdef __MQL4__ - return ::iVolume(_symbol, _tf, _shift); // Same as: Volume[_shift] -#else // __MQL5__ + ResetLastError(); + long _volume = ::iVolume(_symbol, _tf, _shift); // Same as: Volume[_shift] + if (_LastError != ERR_NO_ERROR) { + _volume = EMPTY_VALUE; + ResetLastError(); + } + return _volume; +#else // __MQL5__ ARRAY(long, _arr); ArraySetAsSeries(_arr, true); return (_shift >= 0 && CopyTickVolume(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : -1; diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 00fe5d563..5c0c00a23 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -79,10 +79,6 @@ class Indi_Volumes : public Indicator { _cache.SetPrevCalculated(Indi_Volumes::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _cache.GetBuffer(1), _av)); - for (int i = 0; i < _cache.NumBuffers(); ++i) { - Print("(Mode #", _mode, ", Buffer #", i, " = ", _cache.GetTailValue(i, _shift)); - } - return _cache.GetTailValue(_mode, _shift); } @@ -120,8 +116,6 @@ class Indi_Volumes : public Indicator { // Calculate indicator. ExtVolumesBuffer[i] = curr_volume; ExtColorsBuffer[i] = (curr_volume > prev_volume) ? 0.0 : 1.0; - - Print("Volume: ", ExtVolumesBuffer[i].Get(), ", ", ExtColorsBuffer[i].Get()); } } @@ -161,7 +155,6 @@ class Indi_Volumes : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { double _v = GetValue(_mode, _shift); _entry.values[_mode] = _v; - Print("Volumes[", _mode, "] = ", _v); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(EMPTY_VALUE)); if (_entry.IsValid()) { diff --git a/Storage/ValueStorage.volume.h b/Storage/ValueStorage.volume.h index 69644d53c..4eb51f188 100644 --- a/Storage/ValueStorage.volume.h +++ b/Storage/ValueStorage.volume.h @@ -58,5 +58,13 @@ class VolumeValueStorage : public HistoryValueStorage { /** * Fetches value from a given shift. Takes into consideration as-series flag. */ - virtual long Fetch(int _shift) { return iVolume(symbol, tf, RealShift(_shift)); } + virtual long Fetch(int _shift) { + ResetLastError(); + long _volume = iVolume(symbol, tf, RealShift(_shift)); + if (_LastError != ERR_NO_ERROR) { + Print("Cannot fetch iVolume! Error: ", _LastError); + DebugBreak(); + } + return _volume; + } }; diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index 2fce00468..e68f2f05c 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -532,12 +532,9 @@ bool InitIndicators() { VIDYAParams vidya_params(); indis.Push(new Indi_VIDYA(vidya_params)); -#ifdef __MQL5__ - // @fixit Should work also in MT4! // Volumes. VolumesParams volumes_params(); indis.Push(new Indi_Volumes(volumes_params)); -#endif // Volume Rate of Change. VROCParams vol_rate_of_change_params(); @@ -553,11 +550,9 @@ bool InitIndicators() { indis.Push(new Indi_ZigZagColor(zigzag_color_params)); #endif -#ifdef __MQL5__ // Custom Moving Average. CustomMovingAverageParams cma_params(); indis.Push(new Indi_CustomMovingAverage(cma_params)); -#endif // Math (specialized indicator). MathParams math_params(MATH_OP_SUB, BAND_UPPER, BAND_LOWER, 0, 0); From 7c2a3aabe6e28fb320eaa475d31b7a828fa9db2a Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Mon, 4 Oct 2021 18:15:14 +0200 Subject: [PATCH 44/78] Indi_ColorLine.mqh probably has too few history values for MA. --- Indicators/Indi_ColorLine.mqh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 09c2f8dca..e416facb2 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -92,7 +92,8 @@ class Indi_ColorLine : public Indicator { static int ticks = 0, modified = 0; // Check data. int i, calculated = BarsCalculated(ExtMAHandle, rates_total); - if (calculated < rates_total && calculated < 1000) { + // @added History of 100 values should be enough for MA. + if (calculated < rates_total && calculated < 100) { // Not all data of ExtMAHandle is calculated. Print("Not all MA data calculate for ColorLine! Expected ", rates_total, ", got only ", calculated); return (0); From 65f612dcde9629405098f0b2aa896a16e948024e Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Mon, 4 Oct 2021 19:02:13 +0200 Subject: [PATCH 45/78] Indi_PriceChannel and Indi_ZigZagColor are not yet MT4-ready. Should be? --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9fd471907..25fad8690 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -147,7 +147,6 @@ jobs: - Indi_Pattern.test - Indi_Pivot.test - Indi_Price.test - - Indi_PriceChannel.test - Indi_PriceFeeder.test - Indi_PriceVolumeTrend.test - Indi_RS.test @@ -166,7 +165,6 @@ jobs: - Indi_WPR.test - Indi_WilliamsAD.test - Indi_ZigZag.test - - Indi_ZigZagColor.test steps: - uses: actions/download-artifact@v2 with: From 6d4e11f994c9da79427146195e10727a45d3f8c8 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Tue, 5 Oct 2021 17:14:19 +0200 Subject: [PATCH 46/78] Dict can now fill holes after Unset in List mode, so elements will stay contiguous, but unsorted, as last element is moved into slot hole. --- Dict.mqh | 6 +- DictBase.mqh | 105 +++++++++++++++++++++++-- DictIteratorBase.mqh | 50 +++++++++--- DictObject.mqh | 2 +- DictStruct.mqh | 2 +- Trade/TradeSignalManager.h | 10 ++- Trade/tests/TradeSignalManagerTest.mq5 | 4 +- 7 files changed, 153 insertions(+), 26 deletions(-) diff --git a/Dict.mqh b/Dict.mqh index b4f160dbc..099002d7a 100644 --- a/Dict.mqh +++ b/Dict.mqh @@ -298,7 +298,7 @@ class Dict : public DictBase { /** * Shrinks or expands array of DictSlots. */ - bool Resize(unsigned int new_size) { + bool Resize(int new_size) { if (new_size <= MathMin(_DictSlots_ref._num_used, ArraySize(_DictSlots_ref.DictSlots))) { // We already use minimum number of slots possible. return true; @@ -308,7 +308,7 @@ class Dict : public DictBase { if (ArrayResize(new_DictSlots.DictSlots, new_size) == -1) return false; - unsigned int i; + int i; for (i = 0; i < new_size; ++i) { new_DictSlots.DictSlots[i].SetFlags(0); @@ -317,7 +317,7 @@ class Dict : public DictBase { new_DictSlots._num_used = 0; // Copies entire array of DictSlots into new array of DictSlots. Hashes will be rehashed. - for (i = 0; i < (unsigned int)ArraySize(_DictSlots_ref.DictSlots); ++i) { + for (i = 0; i < ArraySize(_DictSlots_ref.DictSlots); ++i) { if (!_DictSlots_ref.DictSlots[i].IsUsed()) continue; if (_DictSlots_ref.DictSlots[i].HasKey()) { diff --git a/DictBase.mqh b/DictBase.mqh index 8976c3514..cde978864 100644 --- a/DictBase.mqh +++ b/DictBase.mqh @@ -43,6 +43,14 @@ enum ENUM_DICT_OVERFLOW_REASON { DICT_OVERFLOW_REASON_TOO_MANY_CONFLICTS, }; +/** + * Dictionary flags. + */ +enum ENUM_DICT_FLAG { + DICT_FLAG_NONE = 0, + DICT_FLAG_FILL_HOLES_UNSORTED = 1, +}; + /** * Dictionary overflow listener. arguments are: * - ENUM_DICT_OVERFLOW_REASON overflow_reason @@ -65,11 +73,15 @@ class DictBase { // Whether Dict operates in yet uknown mode, as dict or as list. DictMode _mode; + // Dictionary flags. + int _flags; + public: DictBase() { _hash = rand(); _current_id = 0; _mode = DictModeUnknown; + _flags = 0; } /** @@ -92,6 +104,16 @@ class DictBase { const unsigned int GetSlotCount() const { return ArraySize(_DictSlots_ref.DictSlots); } + /** + * Adds flags to dict. + */ + void AddFlags(int flags) { _flags |= flags; } + + /** + * Checks whether dict have all given flags. + */ + bool HasFlags(int flags) { return (_flags & flags) == flags; } + DictSlot* GetSlot(const unsigned int index) { if (index >= GetSlotCount()) { // Index of out bounds. @@ -146,16 +168,50 @@ class DictBase { int GetMode() { return _mode; } + /** + * Removes value from the dictionary by the given iterator. Could be used to remove value on Dict with + * DICT_FLAG_FILL_HOLES_UNSORTED flag. + */ + void Unset(DictIteratorBase& iter) { + InternalUnset(iter.Key()); + if (HasFlags(DICT_FLAG_FILL_HOLES_UNSORTED)) { + // After incrementing, iterator will use moved slot. + iter.ShiftPosition(-1, true); + } + } + /** * Removes value from the dictionary by the given key (if exists). */ void Unset(const K key) { + if (HasFlags(DICT_FLAG_FILL_HOLES_UNSORTED)) { + Print( + "Unset on Dict with DICT_FLAG_FILL_HOLES_UNSORTED flag must be called by passing the iterator, instead of " + "the key. Thus way iterator will continue with proper value after incrementation."); + DebugBreak(); + return; + } + InternalUnset(key); + } + + /** + * Removes value from the dictionary by the given key (if exists). + */ + void InternalUnset(const K key) { if (ArraySize(_DictSlots_ref.DictSlots) == 0) { // Nothing to unset. return; } - unsigned int position = Hash(key) % ArraySize(_DictSlots_ref.DictSlots); + unsigned int position; + + if (GetMode() == DictModeList) { + // In list mode value index is the slot index. + position = (int)key; + } else { + position = Hash(key) % ArraySize(_DictSlots_ref.DictSlots); + } + unsigned int tries_left = ArraySize(_DictSlots_ref.DictSlots); while (tries_left-- > 0) { @@ -164,11 +220,32 @@ class DictBase { return; } - if (_DictSlots_ref.DictSlots[position].IsUsed() && _DictSlots_ref.DictSlots[position].HasKey() && - _DictSlots_ref.DictSlots[position].key == key) { - // Key perfectly matches, it indicates key exists in the dictionary. + bool _should_be_removed = false; + + if (_DictSlots_ref.DictSlots[position].IsUsed()) { + if (GetMode() == DictModeList) { + _should_be_removed = position == (int)key; + } else { + _should_be_removed = + _DictSlots_ref.DictSlots[position].HasKey() && _DictSlots_ref.DictSlots[position].key == key; + } + } + + if (_should_be_removed) { + // Key/index perfectly matches, it indicates key/index exists in the dictionary. _DictSlots_ref.DictSlots[position].RemoveFlags(DICT_SLOT_IS_USED); - --_DictSlots_ref._num_used; + + if (GetMode() == DictModeDict) { + // In List mode we don't decrement number of used elements. + --_DictSlots_ref._num_used; + } else if (HasFlags(DICT_FLAG_FILL_HOLES_UNSORTED)) { + // This is List mode and we need to fill this hole. + FillHoleUnsorted(position); + } + return; + } else if (GetMode() == DictModeList) { + Print("Internal error. Slot should have been removed!"); + DebugBreak(); return; } @@ -179,6 +256,24 @@ class DictBase { // No key found. } + /** + * Moves last slot to given one to fill the hole after removing the value. + */ + void FillHoleUnsorted(int _hole_slot_idx) { + // After moving last element to fill the hole we + if (_hole_slot_idx == Size() - 1) { + // We've just removed last element, thus don't need to do anything. + } else { + // Moving last slot into given one. + _DictSlots_ref.DictSlots[_hole_slot_idx] = _DictSlots_ref.DictSlots[Size() - 1]; + + // Marking last slot as unused. + _DictSlots_ref.DictSlots[Size() - 1].RemoveFlags(DICT_SLOT_IS_USED); + } + // One element less in the List-based Dict. + --_DictSlots_ref._num_used; + } + /** * Returns number of used DictSlots. */ diff --git a/DictIteratorBase.mqh b/DictIteratorBase.mqh index 330a3c84d..ca72c86cc 100644 --- a/DictIteratorBase.mqh +++ b/DictIteratorBase.mqh @@ -36,20 +36,23 @@ class DictIteratorBase { protected: DictBase* _dict; int _hash; - unsigned int _slotIdx; - unsigned int _index; + int _slotIdx; + int _index; + bool _invalid_until_incremented; public: /** * Constructor. */ - DictIteratorBase() : _dict(NULL) {} + DictIteratorBase() : _dict(NULL) { _invalid_until_incremented = false; } /** * Constructor. */ - DictIteratorBase(DictBase& dict, unsigned int slotIdx) - : _dict(&dict), _hash(dict.GetHash()), _slotIdx(slotIdx), _index(0) {} + DictIteratorBase(DictBase& dict, int slotIdx) + : _dict(&dict), _hash(dict.GetHash()), _slotIdx(slotIdx), _index(0) { + _invalid_until_incremented = false; + } /** * Copy constructor. @@ -58,7 +61,9 @@ class DictIteratorBase { : _dict(right._dict), _hash(right._dict ? right._dict.GetHash() : 0), _slotIdx(right._slotIdx), - _index(right._index) {} + _index(right._index) { + _invalid_until_incremented = false; + } /** * Iterator incrementation operator. @@ -67,6 +72,7 @@ class DictIteratorBase { // Going to the next slot. ++_slotIdx; ++_index; + _invalid_until_incremented = false; DictSlot* slot = _dict.GetSlot(_slotIdx); @@ -83,15 +89,31 @@ class DictIteratorBase { bool HasKey() { return _dict.GetSlot(_slotIdx).HasKey(); } - K Key() { return _dict.GetMode() == DictModeList ? (K)_slotIdx : _dict.GetSlot(_slotIdx).key; } + K Key() { + CheckValidity(); + return _dict.GetMode() == DictModeList ? (K)_slotIdx : _dict.GetSlot(_slotIdx).key; + } string KeyAsString(bool includeQuotes = false) { return HasKey() ? SerializerConversions::ValueToString(Key(), includeQuotes) : ""; } - unsigned int Index() { return _index; } + int Index() { + CheckValidity(); + return _index; + } + + V Value() { + CheckValidity(); + return _dict.GetSlot(_slotIdx).value; + } - V Value() { return _dict.GetSlot(_slotIdx).value; } + void CheckValidity() { + if (_invalid_until_incremented) { + Alert("Iterator must be incremented before using it again!"); + DebugBreak(); + } + } bool IsValid() { return _dict != NULL; } @@ -108,6 +130,12 @@ class DictIteratorBase { return _index == _dict.Size() - 1; } + + void ShiftPosition(int shift, bool invalid_until_incremented = false) { + _slotIdx += shift; + _index += shift; + _invalid_until_incremented |= invalid_until_incremented; + } }; template @@ -118,9 +146,9 @@ struct DictSlotsRef { DictSlot DictSlots[]; // Incremental index for dict operating in list mode. - unsigned int _list_index; + int _list_index; - unsigned int _num_used; + int _num_used; DictSlotsRef() { _list_index = 0; diff --git a/DictObject.mqh b/DictObject.mqh index bc29d7282..880ae132f 100644 --- a/DictObject.mqh +++ b/DictObject.mqh @@ -285,7 +285,7 @@ class DictObject : public DictBase { /** * Shrinks or expands array of DictSlots. */ - bool Resize(unsigned int new_size) { + bool Resize(int new_size) { if (new_size <= MathMin(_DictSlots_ref._num_used, ArraySize(_DictSlots_ref.DictSlots))) { // We already use minimum number of slots possible. return true; diff --git a/DictStruct.mqh b/DictStruct.mqh index f7d65833f..d55c5051e 100644 --- a/DictStruct.mqh +++ b/DictStruct.mqh @@ -326,7 +326,7 @@ class DictStruct : public DictBase { /** * Shrinks or expands array of DictSlots. */ - bool Resize(unsigned int new_size) { + bool Resize(int new_size) { if (new_size <= MathMin(_DictSlots_ref._num_used, ArraySize(_DictSlots_ref.DictSlots))) { // We already use minimum number of slots possible. return true; diff --git a/Trade/TradeSignalManager.h b/Trade/TradeSignalManager.h index 30227f961..a421dd1fb 100644 --- a/Trade/TradeSignalManager.h +++ b/Trade/TradeSignalManager.h @@ -42,7 +42,11 @@ class TradeSignalManager : Dynamic { /** * Class constructor. */ - TradeSignalManager() {} + TradeSignalManager() { + signals_active.AddFlags(DICT_FLAG_FILL_HOLES_UNSORTED); + signals_expired.AddFlags(DICT_FLAG_FILL_HOLES_UNSORTED); + signals_processed.AddFlags(DICT_FLAG_FILL_HOLES_UNSORTED); + } /* Getters */ @@ -93,12 +97,12 @@ class TradeSignalManager : Dynamic { for (DictObjectIterator iter = GetIterSignalsActive(); iter.IsValid(); ++iter) { TradeSignal *_signal = iter.Value(); if (_signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED))) { - signals_active.Unset(iter.Key()); + signals_active.Unset(iter); signals_processed.Push(_signal); continue; } if (_signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_EXPIRED))) { - signals_active.Unset(iter.Key()); + signals_active.Unset(iter); signals_expired.Push(_signal); continue; } diff --git a/Trade/tests/TradeSignalManagerTest.mq5 b/Trade/tests/TradeSignalManagerTest.mq5 index 10131d2c1..dd0bb64ed 100644 --- a/Trade/tests/TradeSignalManagerTest.mq5 +++ b/Trade/tests/TradeSignalManagerTest.mq5 @@ -45,8 +45,8 @@ bool TestSignalsProcessed() { _signal.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); } _tsm.Refresh(); - // @fixme: // _result &= _tsm.GetSignalsActive().Size() == 0; - // @fixme: // _result &= _tsm.GetSignalsExpired().Size() == 0; + _result &= _tsm.GetSignalsActive().Size() == 0; + _result &= _tsm.GetSignalsExpired().Size() == 0; _result &= _tsm.GetSignalsProcessed().Size() == 10; Print(_tsm.ToString()); return _result; From 3daec2fc85ffefc96f522188d18e48eaf2afb8c1 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 5 Oct 2021 21:49:45 +0100 Subject: [PATCH 47/78] EA: EAState: Converts ushort to uint to avoid ambiguous call to overloaded function error --- EA.struct.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/EA.struct.h b/EA.struct.h index aa36c2e5e..cc8cda2ba 100644 --- a/EA.struct.h +++ b/EA.struct.h @@ -222,16 +222,16 @@ struct EAProcessResult { /* Defines EA state variables. */ struct EAState { - unsigned short flags; // Action flags. + unsigned int flags; // Action flags. unsigned int new_periods; // Started periods. DateTime last_updated; // Last updated. // Constructor. - EAState() { AddFlags(EA_STATE_FLAG_ACTIVE | EA_STATE_FLAG_ENABLED); } + EAState() { EAState::AddFlags(EA_STATE_FLAG_ACTIVE | EA_STATE_FLAG_ENABLED); } // Struct methods. // Flag methods. - bool CheckFlag(unsigned short _flag) { return bool(flags & _flag); } - void AddFlags(unsigned short _flags) { flags |= _flags; } - void RemoveFlags(unsigned short _flags) { flags &= ~_flags; } + bool CheckFlag(unsigned int _flag) { return bool(flags & _flag); } + void AddFlags(unsigned int _flags) { flags |= _flags; } + void RemoveFlags(unsigned int _flags) { flags &= ~_flags; } void SetFlag(ENUM_EA_STATE_FLAGS _flag, bool _value) { if (_value) { AddFlags(_flag); @@ -239,7 +239,7 @@ struct EAState { RemoveFlags(_flag); } } - void SetFlags(unsigned short _flags) { flags = _flags; } + void SetFlags(unsigned int _flags) { flags = _flags; } // State methods. bool IsActive() { return CheckFlag(EA_STATE_FLAG_ACTIVE); } bool IsConnected() { return CheckFlag(EA_STATE_FLAG_CONNECTED); } From ca335d3ef678beaa7e8e4114936159520cde89c0 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 5 Oct 2021 22:15:50 +0100 Subject: [PATCH 48/78] TradeSignalEntry: Adds timestamp property --- EA.mqh | 1 + Trade/TradeSignal.struct.h | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/EA.mqh b/EA.mqh index dcc8163a9..aeec998b2 100644 --- a/EA.mqh +++ b/EA.mqh @@ -175,6 +175,7 @@ class EA { _signals |= !_strat.SignalCloseFilterTime(_scfm) ? SIGNAL_OPEN_TIME_FILTER : 0; TradeSignalEntry _sentry(_signals, _strat.Get(STRAT_PARAM_TF), _strat.Get(STRAT_PARAM_ID)); _sentry.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_STRENGTH), _strat.SignalOpen(_sofm, _sol, _ss)); + _sentry.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_TIME), ::TimeGMT()); return _sentry; } diff --git a/Trade/TradeSignal.struct.h b/Trade/TradeSignal.struct.h index 6473dcd28..bc942ede7 100644 --- a/Trade/TradeSignal.struct.h +++ b/Trade/TradeSignal.struct.h @@ -57,6 +57,7 @@ struct TradeSignalEntry { float strength; // Signal strength. float weight; // Signal weight. long magic_id; // Magic identifier. + long timestamp; // Creation timestamp unsigned int signals; // Store signals (@see: ENUM_TRADE_SIGNAL_FLAG). public: @@ -99,6 +100,7 @@ struct TradeSignalEntry { TRADE_SIGNAL_PROP_SIGNALS, TRADE_SIGNAL_PROP_STRENGTH, TRADE_SIGNAL_PROP_TF, + TRADE_SIGNAL_PROP_TIME, TRADE_SIGNAL_PROP_WEIGHT, }; // Enumeration for strategy signal types. @@ -110,8 +112,8 @@ struct TradeSignalEntry { /* Constructor */ TradeSignalEntry(unsigned int _signals = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, long _magic_id = 0, - float _strength = 0.0f, float _weight = 0.0f) - : magic_id(_magic_id), signals(_signals), strength(_strength), tf(_tf), weight(_weight) {} + float _strength = 0.0f, float _weight = 0.0f, long _time = 0) + : magic_id(_magic_id), signals(_signals), strength(_strength), tf(_tf), timestamp(_time), weight(_weight) {} TradeSignalEntry(const TradeSignalEntry &_entry) { this = _entry; } /* Getters */ template @@ -125,6 +127,8 @@ struct TradeSignalEntry { return (T)strength; case TRADE_SIGNAL_PROP_TF: return (T)tf; + case TRADE_SIGNAL_PROP_TIME: + return (T)timestamp; case TRADE_SIGNAL_PROP_WEIGHT: return (T)weight; } @@ -148,6 +152,9 @@ struct TradeSignalEntry { case TRADE_SIGNAL_PROP_TF: tf = (ENUM_TIMEFRAMES)_value; return; + case TRADE_SIGNAL_PROP_TIME: + timestamp = (long)_value; + return; case TRADE_SIGNAL_PROP_WEIGHT: weight = (float)_value; return; From 236068eb62ccd6ad8d42b072a0c8a1b29665f8f3 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 5 Oct 2021 22:19:46 +0100 Subject: [PATCH 49/78] GHA: Adds TradeSignalManagerTest --- .github/workflows/test-trade.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-trade.yml b/.github/workflows/test-trade.yml index babad58bd..744585359 100644 --- a/.github/workflows/test-trade.yml +++ b/.github/workflows/test-trade.yml @@ -49,6 +49,7 @@ jobs: matrix: test: - TradeSignalTest + - TradeSignalManagerTest steps: - uses: actions/download-artifact@v2 with: From 293fe43608c323ac3868d56e59ddbaa567cf2919 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 5 Oct 2021 22:32:47 +0100 Subject: [PATCH 50/78] GHA: Comments out failing indicators --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 25fad8690..d2d40a420 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -147,6 +147,7 @@ jobs: - Indi_Pattern.test - Indi_Pivot.test - Indi_Price.test + # - Indi_PriceChannel.test - Indi_PriceFeeder.test - Indi_PriceVolumeTrend.test - Indi_RS.test @@ -164,7 +165,8 @@ jobs: - Indi_Volumes.test - Indi_WPR.test - Indi_WilliamsAD.test - - Indi_ZigZag.test + # - Indi_ZigZag.test + # - Indi_ZigZagColor.test steps: - uses: actions/download-artifact@v2 with: From 5abb56d23b3521afce2f4058eafe376e765c6768 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 2 Oct 2021 18:36:39 +0100 Subject: [PATCH 51/78] GHA: Adds separate test for Indicators directory --- .github/workflows/test-indicators.yml | 128 ++++++++++++++++++++++++++ .github/workflows/test.yml | 87 ----------------- 2 files changed, 128 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/test-indicators.yml diff --git a/.github/workflows/test-indicators.yml b/.github/workflows/test-indicators.yml new file mode 100644 index 000000000..d49351f5e --- /dev/null +++ b/.github/workflows/test-indicators.yml @@ -0,0 +1,128 @@ +--- +name: Test Indicators + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Indicator**' + - 'Indicators/**' + - '.github/workflows/test-indicators.yml' + push: + paths: + - 'Indicator**' + - 'Indicators/**' + - '.github/workflows/test-indicators.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/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_AC.test + - Indi_AD.test + - Indi_ADX.test + - Indi_ADXW.test + - Indi_AMA.test + - Indi_AO.test + - Indi_ASI.test + - Indi_ATR.test + - Indi_Alligator.test + - Indi_AppliedPrice.test + - Indi_BWMFI.test + - Indi_BWZT.test + - Indi_Bands.test + - Indi_BearsPower.test + - Indi_BullsPower.test + - Indi_CCI.test + - Indi_CHO.test + - Indi_CHV.test + - Indi_ColorBars.test + - Indi_ColorCandlesDaily.test + - Indi_ColorLine.test + - Indi_CustomMovingAverage.test + - Indi_DEMA.test + - Indi_DeMarker.test + - Indi_Demo.test + - Indi_DetrendedPrice.test + - Indi_Drawer.test + - Indi_Envelopes.test + - Indi_Force.test + - Indi_FractalAdaptiveMA.test + - Indi_Fractals.test + - Indi_Gator.test + - Indi_HeikenAshi.test + - Indi_Ichimoku.test + - Indi_Killzones.test + - Indi_MA.test + - Indi_MACD.test + - Indi_MFI.test + - Indi_MassIndex.test + - Indi_Momentum.test + - Indi_OBV.test + - Indi_OsMA.test + - Indi_Pattern.test + - Indi_Pivot.test + - Indi_Price.test + # - Indi_PriceChannel.test + - Indi_PriceFeeder.test + - Indi_PriceVolumeTrend.test + - Indi_RS.test + - Indi_RSI.test + - Indi_RVI.test + - Indi_RateOfChange.test + - Indi_SAR.test + - Indi_StdDev.test + - Indi_Stochastic.test + - Indi_TEMA.test + - Indi_TRIX.test + - Indi_UltimateOscillator.test + - Indi_VIDYA.test + - Indi_VROC.test + - Indi_Volumes.test + - Indi_WPR.test + - Indi_WilliamsAD.test + # - Indi_ZigZag.test + # - Indi_ZigZagColor.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 }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2d40a420..e10865956 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -92,93 +92,6 @@ jobs: BtYears: 2020 TestExpert: ${{ matrix.test }} - Indicators-MQL4: - defaults: - run: - shell: bash - working-directory: Indicators/tests - needs: Compile - runs-on: ubuntu-latest - strategy: - matrix: - test: - - Indi_AC.test - - Indi_AD.test - - Indi_ADX.test - - Indi_ADXW.test - - Indi_AMA.test - - Indi_AO.test - - Indi_ASI.test - - Indi_ATR.test - - Indi_Alligator.test - - Indi_AppliedPrice.test - - Indi_BWMFI.test - - Indi_BWZT.test - - Indi_Bands.test - - Indi_BearsPower.test - - Indi_BullsPower.test - - Indi_CCI.test - - Indi_CHO.test - - Indi_CHV.test - - Indi_ColorBars.test - - Indi_ColorCandlesDaily.test - - Indi_ColorLine.test - - Indi_CustomMovingAverage.test - - Indi_DEMA.test - - Indi_DeMarker.test - - Indi_Demo.test - - Indi_DetrendedPrice.test - - Indi_Drawer.test - - Indi_Envelopes.test - - Indi_Force.test - - Indi_FractalAdaptiveMA.test - - Indi_Fractals.test - - Indi_Gator.test - - Indi_HeikenAshi.test - - Indi_Ichimoku.test - - Indi_Killzones.test - - Indi_MA.test - - Indi_MACD.test - - Indi_MFI.test - - Indi_MassIndex.test - - Indi_Momentum.test - - Indi_OBV.test - - Indi_OsMA.test - - Indi_Pattern.test - - Indi_Pivot.test - - Indi_Price.test - # - Indi_PriceChannel.test - - Indi_PriceFeeder.test - - Indi_PriceVolumeTrend.test - - Indi_RS.test - - Indi_RSI.test - - Indi_RVI.test - - Indi_RateOfChange.test - - Indi_SAR.test - - Indi_StdDev.test - - Indi_Stochastic.test - - Indi_TEMA.test - - Indi_TRIX.test - - Indi_UltimateOscillator.test - - Indi_VIDYA.test - - Indi_VROC.test - - Indi_Volumes.test - - Indi_WPR.test - - Indi_WilliamsAD.test - # - Indi_ZigZag.test - # - Indi_ZigZagColor.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 }} - Scripts-MQL4: defaults: run: From b19d54fd567ee3a040aca11fbd12532841a980a2 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 5 Oct 2021 23:48:24 +0100 Subject: [PATCH 52/78] EA/Strategy/Trade: Code cleanup --- EA.mqh | 12 +++--------- Strategy.mqh | 27 --------------------------- Trade/TradeSignal.struct.h | 1 + 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/EA.mqh b/EA.mqh index aeec998b2..bfbcb86d7 100644 --- a/EA.mqh +++ b/EA.mqh @@ -143,7 +143,6 @@ class EA { */ TradeSignalEntry GetStrategySignalEntry(Strategy *_strat, bool _trade_allowed = true, int _shift = -1) { // float _bf = 1.0; - // float _ls = 0; float _scl = _strat.Get(STRAT_PARAM_SCL); float _sol = _strat.Get(STRAT_PARAM_SOL); int _scfm = _strat.Get(STRAT_PARAM_SCFM); @@ -252,11 +251,9 @@ class EA { // Ignores already processed signals. continue; } - // Strategy *_strat = _signal.GetStrategy(); Trade *_trade = trade.GetByKey(_Symbol); Strategy *_strat = strats.GetByKey(_signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID))).Ptr(); - // _signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID)), if (_trade.Get(TRADE_STATE_ORDERS_ACTIVE)) { float _sig_close = _signal.GetSignalClose(); string _comment_close = @@ -287,7 +284,7 @@ class EA { if (_sig_open >= 0.5f) { // Open signal for buy. // When H1 or H4 signal filter is enabled, do not open minute-based orders on opposite or neutral signals. - if (_sig_f == 0) { // || GetSignalOpenFiltered(_signal, _sig_f) >= 0.5f) { + if (_sig_f == 0) { // @fixme: || GetSignalOpenFiltered(_signal, _sig_f) >= 0.5f) { _strat.Set(TRADE_PARAM_ORDER_COMMENT, _comment_open); // Buy order open. _result_local &= TradeRequest(ORDER_TYPE_BUY, _Symbol, _strat); @@ -300,7 +297,7 @@ class EA { if (_sig_open <= -0.5f) { // Open signal for sell. // When H1 or H4 signal filter is enabled, do not open minute-based orders on opposite or neutral signals. - if (_sig_f == 0) { // || GetSignalOpenFiltered(_signal, _sig_f) <= -0.5f) { + if (_sig_f == 0) { // @fixme: || GetSignalOpenFiltered(_signal, _sig_f) <= -0.5f) { _strat.Set(TRADE_PARAM_ORDER_COMMENT, _comment_open); // Sell order open. _result_local &= TradeRequest(ORDER_TYPE_SELL, _Symbol, _strat); @@ -330,8 +327,7 @@ class EA { if (_last_error > 0) { logger.Warning(StringFormat("Processing signals failed! Code: %d", _last_error), __FUNCTION_LINE__); } - // Remove signals after processing. - // strat_signals.Unset(_tick.time); + // Refresh signals after processing. tsm.Refresh(); return _result && _last_error == 0; } @@ -403,8 +399,6 @@ class EA { eresults.stg_errored += (int)_strat_result.last_error > ERR_NO_ERROR; eresults.stg_processed++; } - /* - */ } } } diff --git a/Strategy.mqh b/Strategy.mqh index 1acb68173..759533a48 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -144,17 +144,6 @@ class Strategy : public Object { Log *GetLogger() { return GetPointer(logger); } - /** - * Class copy constructor. - */ - /* - Strategy(const Strategy &_strat) { - // @todo - sparams = _strat.GetParams(); - // ... - } - */ - /** * Class deconstructor. */ @@ -177,7 +166,6 @@ class Strategy : public Object { */ StgProcessResult Process(unsigned short _periods_started = DATETIME_NONE) { sresult.last_error = ERR_NO_ERROR; - // last_signal = ProcessSignals(); if (_periods_started > 0) { ProcessTasks(); } @@ -253,11 +241,6 @@ class Strategy : public Object { /* Class getters */ - /** - * Returns access to Chart information. - */ - // Chart *GetChart() { return trade.GetChart(); } - /** * Returns handler to the strategy's indicator class. */ @@ -321,11 +304,6 @@ class Strategy : public Object { return _entry; } - /** - * Get strategy's last signal entry. - */ - // TradeSignalEntry GetLastSignalEntry() { return last_signal; } - /** * Gets pointer to strategy's stop-loss strategy. */ @@ -346,11 +324,6 @@ class Strategy : public Object { */ virtual long GetId() { return sparams.id; } - /** - * Get strategy's timeframe. - */ - // ENUM_TIMEFRAMES GetTf() { return trade.GetChart().GetTf(); } - /** * Get strategy's signal open method. */ diff --git a/Trade/TradeSignal.struct.h b/Trade/TradeSignal.struct.h index bc942ede7..f4b3a9c61 100644 --- a/Trade/TradeSignal.struct.h +++ b/Trade/TradeSignal.struct.h @@ -182,6 +182,7 @@ struct TradeSignalEntry { SERIALIZER_EMPTY_STUB; SerializerNodeType Serialize(Serializer &_s) { _s.PassEnum(THIS_REF, "tf", tf); + _s.Pass(THIS_REF, "timestamp", timestamp, SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE); _s.Pass(THIS_REF, "strength", strength, SERIALIZER_FIELD_FLAG_DYNAMIC); _s.Pass(THIS_REF, "weight", weight, SERIALIZER_FIELD_FLAG_DYNAMIC); int _size = sizeof(int) * 8; From a51f6fc605f34fba03fd2b12d631723f1a9304e9 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Wed, 6 Oct 2021 13:04:44 +0200 Subject: [PATCH 53/78] Fixed Indi_Killzones's value validity check. --- Indicators/Indi_Killzones.mqh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index 8568b7464..697b9dbda 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -111,7 +111,7 @@ class Indi_Killzones : public Indicator { float GetValue(unsigned int _mode, int _shift = 0) { ResetLastError(); float _value = FLT_MAX; - int _index = (int)floor(_mode / 2); + int _index = (int)_mode / 2; switch (iparams.idstype) { case IDATA_BUILTIN: // Builtin mode not supported. @@ -149,9 +149,7 @@ class Indi_Killzones : public Indicator { _entry.timestamp = GetBarTime(_shift); for (unsigned int _mode = 0; _mode < (uint)iparams.GetMaxModes(); _mode++) { float _value = GetValue(_mode, _shift); - if (IsValidValue(_value, _mode, _shift)) { - _entry.values[_mode] = _value; - } + _entry.values[_mode] = IsValidValue(_value, _mode, _shift) ? _value : 0.0f; } _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.IsGe(0) && !_entry.HasValue(FLT_MAX)); if (_entry.IsValid()) { From 2e2c04fd473e96004c9c431677e5439917d1206a Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Wed, 6 Oct 2021 14:01:10 +0200 Subject: [PATCH 54/78] Cleaned up Indi_Drawer. --- Indicators/Indi_Drawer.mqh | 161 +++----------------------------- Indicators/Indi_Drawer.struct.h | 1 + 2 files changed, 13 insertions(+), 149 deletions(-) diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index 61093149c..fa7071062 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -31,13 +31,6 @@ struct IndicatorParams; #include "Indi_Drawer.struct.h" #include "Indi_Price.mqh" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iDrawer(string _symbol, int _tf, int _period, int _ap, int _shift) { - return Indi_Drawer::iDrawer(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, _shift); -} -#endif - /** * Implements the Relative Strength Index indicator. */ @@ -155,154 +148,27 @@ class Indi_Drawer : public Indicator { * - https://docs.mql4.com/indicators/irsi * - https://www.mql5.com/en/docs/indicators/irsi */ - static double iDrawer(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, - ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, IndicatorBase *_obj = NULL) { + static double iDrawer(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, + IndicatorBase *_obj = NULL) { return 1.0; } /** - * Calculates non-SMMA version of Drawer on another indicator (uses iDrawerOnArray). - */ - static double iDrawerOnArrayOnIndicator(IndicatorBase *_indi, string _symbol = NULL, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, - ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, - Indi_Drawer *_obj = NULL) { - int i; - double indi_values[]; - ArrayResize(indi_values, _period); - - double result; - - for (i = _shift; i < (int)_shift + (int)_period; i++) { - indi_values[_shift + _period - (i - _shift) - 1] = _indi[i][_obj.GetDataSourceMode()]; - } - - result = iDrawerOnArray(indi_values, 0, _period - 1, 0); - - return result; - } - - /** - * Calculates SMMA-based (same as iDrawer method) Drawer on another indicator. - * - * @see https://school.stockcharts.com/doku.php?id=technical_indicators:relative_strength_index_rsi - * - * Reson behind iDrawer with SSMA and not just iDrawerOnArray() (from above website): - * - * "Taking the prior value plus the current value is a smoothing technique - * similar to that used in calculating an exponential moving average. This - * also means that Drawer values become more accurate as the calculation period - * extends. SharpCharts uses at least 250 data points prior to the starting - * date of any chart (assuming that much data exists) when calculating its - * Drawer values. To exactly replicate our Drawer numbers, a formula will need at - * least 250 data points." + * Performs drawing on data from other indicator. */ static double iDrawerOnIndicator(IndicatorBase *_indi, Indi_Drawer *_obj, string _symbol = NULL, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, - ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0) { - long _bar_time_curr = _obj.GetBarTime(_shift); - long _bar_time_prev = _obj.GetBarTime(_shift + 1); - if (fmin(_bar_time_curr, _bar_time_prev) < 0) { - // Return empty value on invalid bar time. - return EMPTY_VALUE; - } - // Looks like MT uses specified period as start of the SMMA calculations. - _obj.FeedHistoryEntries(_period); - - // int i; - double indi_values[]; - ArrayResize(indi_values, _period); - - double result; - - // SMMA-based version of Drawer. - DrawerGainLossData last_data, new_data; - // unsigned int data_position; - double diff; - int _mode = _obj.GetDataSourceMode(); - - /* - @fixit - if (!_obj.aux_data.KeyExists(_bar_time_prev, data_position)) { - // No previous SMMA-based average gain and loss. Calculating SMA-based ones. - double sum_gain = 0; - double sum_loss = 0; - - for (i = 1; i < (int)_period; i++) { - double price_new = _indi[(_shift + 1) + i - 1][_mode]; - double price_old = _indi[(_shift + 1) + i][_mode]; - - if (price_new == 0.0 || price_old == 0.0) { - // Missing history price data, skipping calculations. - return 0.0; - } - - diff = price_new - price_old; - - if (diff > 0) { - sum_gain += diff; - } else { - sum_loss += -diff; - } - } - - // Calculating SMA-based values. - last_data.avg_gain = sum_gain / _period; - last_data.avg_loss = sum_loss / _period; - } else { - // Data already exists, retrieving it by position got by KeyExists(). - last_data = _obj.aux_data.GetByPos(data_position); - } - */ - - diff = _indi[_shift][_mode] - _indi[_shift + 1][_mode]; - - double curr_gain = 0; - double curr_loss = 0; - - if (diff > 0) - curr_gain += diff; - else - curr_loss += -diff; - - new_data.avg_gain = (last_data.avg_gain * (_period - 1) + curr_gain) / _period; - new_data.avg_loss = (last_data.avg_loss * (_period - 1) + curr_loss) / _period; - - /* - @fixit - _obj.aux_data.Set(_bar_time_curr, new_data); - */ - - if (new_data.avg_loss == 0.0) - // @fixme Why 0 loss? - return 0; - - double rs = new_data.avg_gain / new_data.avg_loss; - - result = 100.0 - (100.0 / (1.0 + rs)); - - return result; + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) { + // This method is not yet implemented. + return 1.0; } /** - * Calculates Drawer on the array of values. + * Performs drawing from data in array. */ static double iDrawerOnArray(double &array[], int total, int period, int shift) { return 0; } /** * Returns the indicator's value. - * - * For IDATA_ICUSTOM mode, use those three externs: - * - * extern unsigned int period; - * extern ENUM_APPLIED_PRICE applied_price; // Required only for MQL4. - * extern int shift; - * - * Also, remember to use iparams.SetCustomIndicatorName(name) method to choose - * indicator name, e.g.,: iparams.SetCustomIndicatorName("Examples\\Drawer"); - * - * Note that in MQL5 Applied Price must be passed as the last parameter - * (before mode and shift). */ double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); @@ -310,17 +176,13 @@ class Indi_Drawer : public Indicator { switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_Drawer::iDrawer(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _shift, THIS_PTR); - break; - case IDATA_ICUSTOM: - istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, /* [ */ GetPeriod(), - GetAppliedPrice() /* ] */, 0, _shift); + _value = Indi_Drawer::iDrawer(GetSymbol(), GetTf(), _shift, THIS_PTR); break; case IDATA_INDICATOR: - _value = Indi_Drawer::iDrawerOnIndicator(GetDataSource(), THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), - GetAppliedPrice(), _shift); + _value = Indi_Drawer::iDrawerOnIndicator(GetDataSource(), THIS_PTR, GetSymbol(), GetTf(), _shift); break; + default: + SetUserError(ERR_INVALID_PARAMETER); } istate.is_changed = false; return _value; @@ -348,6 +210,7 @@ class Indi_Drawer : public Indicator { _entry.timestamp = GetBarTime(_shift); for (i = 0; i < iparams.GetMaxModes(); ++i) { + // Fetching history data is not yet implemented. _entry.values[i] = 0; } diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index 9d6948dd8..989de8f63 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -37,6 +37,7 @@ struct DrawerParams : IndicatorParams { DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap) { itype = INDI_DRAWER; + // Fetching history data is not yet implemented. max_modes = 0; SetCustomIndicatorName("Examples\\Drawer"); SetDataValueType(TYPE_DOUBLE); From 35e18488d7442f6c6ce1ac0fbb0822e2ab03f37c Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Wed, 6 Oct 2021 14:05:27 +0200 Subject: [PATCH 55/78] Enabled back BWZT and Ultimate Oscillator to be tested. --- tests/IndicatorsTest.mq5 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index e68f2f05c..0a7788476 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -510,7 +510,7 @@ bool InitIndicators() { // Bill Williams' Zone Trade. BWZTParams bwzt_params(); - // indis.Push(new Indi_BWZT(bwzt_params)); + indis.Push(new Indi_BWZT(bwzt_params)); // Rate of Change. RateOfChangeParams rate_of_change_params(); @@ -526,7 +526,7 @@ bool InitIndicators() { // Ultimate Oscillator. UltimateOscillatorParams ultimate_oscillator_params(); - // indis.Push(new Indi_UltimateOscillator(ultimate_oscillator_params)); + indis.Push(new Indi_UltimateOscillator(ultimate_oscillator_params)); // VIDYA. VIDYAParams vidya_params(); From b88be35848647226e8abaa5ae682923ef17ad731 Mon Sep 17 00:00:00 2001 From: kenorb Date: Wed, 6 Oct 2021 23:57:34 +0100 Subject: [PATCH 56/78] Indicator: Adds GetEntry() and GetValue() virtual methods --- Indicator.mqh | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Indicator.mqh b/Indicator.mqh index 73a4ad1f7..05860da5b 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -800,11 +800,27 @@ class Indicator : public IndicatorBase { /** * Returns the indicator's struct value. */ - virtual IndicatorDataEntry GetEntry(int _shift = 0) { - IndicatorDataEntry _entry(iparams.GetMaxModes()); - _entry = idata.GetByKey(GetBarTime(_shift), _entry); + IndicatorDataEntry GetEntry(int _shift = 0) { + long _bar_time = GetBarTime(_shift); + IndicatorDataEntry _entry = idata.GetByKey(_bar_time); + if (!_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) { + _entry.Resize(iparams.GetMaxModes()); + _entry.timestamp = GetBarTime(_shift); + for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { + _entry.values[_mode] = GetValue(_mode, _shift); + } + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && + !_entry.HasValue(EMPTY_VALUE) && + !_entry.HasValue(DBL_MAX)); + if (_entry.IsValid()) { + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); + idata.Add(_entry, _bar_time); + } else { + _entry.AddFlags(INDI_ENTRY_FLAG_INSUFFICIENT_DATA); + } + } return _entry; - }; + } /** * Returns the indicator's entry value. @@ -815,6 +831,15 @@ class Indicator : public IndicatorBase { return _param; } + /** + * Returns the indicator's value. + */ + virtual double GetValue(int _mode = 0, int _shift = 0) { + istate.is_changed = false; + istate.is_ready = false; + return EMPTY_VALUE; + } + /** * Returns the indicator's value in plain format. */ From 3c73c4081c11fb402ba6f2840cec9334f226c5dd Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 10 Oct 2021 22:11:39 +0100 Subject: [PATCH 57/78] Revert "GHA: Sets ignore-warnings to true" This reverts commit be58886e779cdcbaef2bd4ea8d483f35c1d0d96b. --- .github/workflows/compile.yml | 1 - .github/workflows/test.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index c6007bd57..ee997c3c7 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -19,7 +19,6 @@ jobs: - name: Compile uses: fx31337/mql-compile-action@master with: - ignore-warnings: true init-platform: true verbose: true - name: Print compiled files diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e10865956..b3a06b032 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,6 @@ jobs: - name: Compile uses: fx31337/mql-compile-action@master with: - ignore-warnings: true init-platform: true verbose: true - name: Print compiled files From baa9779b5a5ec3437d3d855fb792135edab3efb0 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 10 Oct 2021 22:20:29 +0100 Subject: [PATCH 58/78] Indicators: Improves syntax for itype --- Indicators/Bitwise/Indi_Candle.mqh | 2 +- Indicators/Indi_AC.mqh | 2 +- Indicators/Indi_AD.mqh | 2 +- Indicators/Indi_AMA.mqh | 2 +- Indicators/Indi_AO.mqh | 2 +- Indicators/Indi_ASI.mqh | 2 +- Indicators/Indi_ATR.mqh | 2 +- Indicators/Indi_Alligator.mqh | 2 +- Indicators/Indi_AppliedPrice.mqh | 2 +- Indicators/Indi_BWMFI.mqh | 2 +- Indicators/Indi_BWZT.mqh | 2 +- Indicators/Indi_Bands.mqh | 2 +- Indicators/Indi_BearsPower.mqh | 2 +- Indicators/Indi_BullsPower.mqh | 2 +- Indicators/Indi_CCI.mqh | 2 +- Indicators/Indi_CHO.mqh | 2 +- Indicators/Indi_CHV.mqh | 2 +- Indicators/Indi_ColorBars.mqh | 2 +- Indicators/Indi_ColorCandlesDaily.mqh | 2 +- Indicators/Indi_ColorLine.mqh | 2 +- Indicators/Indi_CustomMovingAverage.mqh | 2 +- Indicators/Indi_DEMA.mqh | 2 +- Indicators/Indi_DeMarker.mqh | 4 ++-- Indicators/Indi_Demo.mqh | 2 +- Indicators/Indi_DetrendedPrice.mqh | 2 +- Indicators/Indi_Drawer.struct.h | 2 +- Indicators/Indi_Envelopes.mqh | 2 +- Indicators/Indi_Force.mqh | 2 +- Indicators/Indi_FractalAdaptiveMA.mqh | 2 +- Indicators/Indi_Fractals.mqh | 2 +- Indicators/Indi_Gator.mqh | 2 +- Indicators/Indi_HeikenAshi.mqh | 2 +- Indicators/Indi_Ichimoku.mqh | 2 +- Indicators/Indi_Killzones.mqh | 2 +- Indicators/Indi_MA.mqh | 2 +- Indicators/Indi_MACD.mqh | 2 +- Indicators/Indi_MFI.mqh | 2 +- Indicators/Indi_MassIndex.mqh | 2 +- Indicators/Indi_Momentum.mqh | 2 +- Indicators/Indi_OBV.mqh | 6 +++--- Indicators/Indi_OsMA.mqh | 2 +- Indicators/Indi_Pattern.mqh | 2 +- Indicators/Indi_Pivot.mqh | 2 +- Indicators/Indi_Price.mqh | 2 +- Indicators/Indi_PriceChannel.mqh | 2 +- Indicators/Indi_PriceFeeder.mqh | 4 ++-- Indicators/Indi_PriceVolumeTrend.mqh | 2 +- Indicators/Indi_RS.mqh | 2 +- Indicators/Indi_RSI.mqh | 2 +- Indicators/Indi_RVI.mqh | 2 +- Indicators/Indi_RateOfChange.mqh | 2 +- Indicators/Indi_SAR.mqh | 2 +- Indicators/Indi_StdDev.mqh | 2 +- Indicators/Indi_Stochastic.mqh | 2 +- Indicators/Indi_TEMA.mqh | 2 +- Indicators/Indi_TRIX.mqh | 2 +- Indicators/Indi_UltimateOscillator.mqh | 2 +- Indicators/Indi_VIDYA.mqh | 2 +- Indicators/Indi_VROC.mqh | 2 +- Indicators/Indi_Volumes.mqh | 2 +- Indicators/Indi_WPR.mqh | 2 +- Indicators/Indi_WilliamsAD.mqh | 2 +- Indicators/Indi_ZigZag.mqh | 2 +- Indicators/Indi_ZigZagColor.mqh | 2 +- Indicators/Special/Indi_Math.mqh | 4 ++-- 65 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index 3daf292a1..515a82bdb 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -33,7 +33,7 @@ struct CandleParams : IndicatorParams { // Struct constructor. void CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - itype = INDI_CANDLE; + itype = itype == INDI_NONE ? INDI_CANDLE : itype; max_modes = 1; SetDataValueType(TYPE_INT); SetDataValueRange(IDATA_RANGE_RANGE); diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 945c49bf4..b366e718c 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -33,7 +33,7 @@ double iAC(string _symbol, int _tf, int _shift) { return Indi_AC::iAC(_symbol, ( struct ACParams : IndicatorParams { // Struct constructor. void ACParams(int _shift = 0) { - itype = INDI_AC; + itype = itype == INDI_NONE ? INDI_AC : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index ecbdd2870..626a16626 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -32,7 +32,7 @@ double iAD(string _symbol, int _tf, int _shift) { return Indi_AD::iAD(_symbol, ( struct ADParams : IndicatorParams { // Struct constructor. ADParams(int _shift = 0) { - itype = INDI_AD; + itype = itype == INDI_NONE ? INDI_AD : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index be7627719..ba0ed3573 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -42,7 +42,7 @@ struct IndiAMAParams : IndicatorParams { slow_period(_slow_period), ama_shift(_ama_shift), applied_price(_ap) { - itype = INDI_AMA; + itype = itype == INDI_NONE ? INDI_AMA : itype; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetMaxModes(1); diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index 335e93aa3..090445be0 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -32,7 +32,7 @@ double iAO(string _symbol, int _tf, int _shift) { return Indi_AO::iAO(_symbol, ( struct AOParams : IndicatorParams { // Struct constructor. void AOParams(int _shift = 0) { - itype = INDI_AO; + itype = itype == INDI_NONE ? INDI_AO : itype; #ifdef __MQL4__ max_modes = 1; #else diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index a0fe033b8..99aadc01a 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -31,7 +31,7 @@ struct ASIParams : IndicatorParams { double mpc; // Struct constructor. void ASIParams(double _mpc = 300.0, int _shift = 0) { - itype = INDI_ASI; + itype = itype == INDI_NONE ? INDI_ASI : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index c55565864..c1335ffc0 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -35,7 +35,7 @@ struct ATRParams : IndicatorParams { unsigned int period; // Struct constructors. void ATRParams(unsigned int _period = 14, int _shift = 0) : period(_period) { - itype = INDI_ATR; + itype = itype == INDI_NONE ? INDI_ATR : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index f4e714d1a..e33f1f81a 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -80,7 +80,7 @@ struct AlligatorParams : IndicatorParams { lips_shift(_ls), ma_method(_mm), applied_price(_ap) { - itype = INDI_ALLIGATOR; + itype = itype == INDI_NONE ? INDI_ALLIGATOR : itype; max_modes = FINAL_ALLIGATOR_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index 14aff825f..ac7291ec0 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -29,7 +29,7 @@ struct AppliedPriceParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. AppliedPriceParams(ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) { - itype = INDI_APPLIED_PRICE; + itype = itype == INDI_NONE ? INDI_APPLIED_PRICE : itype; max_modes = 1; applied_price = _applied_price; SetDataSourceType(IDATA_INDICATOR); diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index b4aecab2c..421399679 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -44,7 +44,7 @@ enum ENUM_MFI_COLOR { struct BWMFIParams : IndicatorParams { // Struct constructors. BWMFIParams(int _shift = 0) { - itype = INDI_BWMFI; + itype = itype == INDI_NONE ? INDI_BWMFI : itype; max_modes = FINAL_BWMFI_BUFFER_ENTRY; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index f599b7ed3..6790f1b75 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -34,7 +34,7 @@ struct BWZTParams : IndicatorParams { unsigned int sum_period; // Struct constructor. void BWZTParams(int _shift = 0) { - itype = INDI_BWZT; + itype = itype == INDI_NONE ? INDI_BWZT : itype; max_modes = 5; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 961af7618..3e46af6c9 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -67,7 +67,7 @@ struct BandsParams : IndicatorParams { void BandsParams(unsigned int _period = 20, double _deviation = 2, int _bshift = 0, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : period(_period), deviation(_deviation), bshift(_bshift), applied_price(_ap) { - itype = INDI_BANDS; + itype = itype == INDI_NONE ? INDI_BANDS : itype; max_modes = FINAL_BANDS_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index 4f97a6a9f..fd0756638 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -37,7 +37,7 @@ struct BearsPowerParams : IndicatorParams { // Struct constructors. void BearsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), applied_price(_ap) { - itype = INDI_BEARS; + itype = itype == INDI_NONE ? INDI_BEARS : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index 904f95f05..9fb6e4319 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -37,7 +37,7 @@ struct BullsPowerParams : IndicatorParams { // Struct constructor. void BullsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), applied_price(_ap) { - itype = INDI_BULLS; + itype = itype == INDI_NONE ? INDI_BULLS : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 58f17030a..a89dd2216 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -43,7 +43,7 @@ struct CCIParams : IndicatorParams { // Struct constructors. void CCIParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) : period(_period), applied_price(_applied_price) { - itype = INDI_CCI; + itype = itype == INDI_NONE ? INDI_CCI : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index f30cf8296..a89af7d5e 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -39,7 +39,7 @@ struct CHOParams : IndicatorParams { ENUM_APPLIED_VOLUME _input_volume = VOLUME_TICK, int _shift = 0) { fast_ma = _fast_ma; input_volume = _input_volume; - itype = INDI_CHAIKIN; + itype = itype == INDI_NONE ? INDI_CHAIKIN : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 91da4a00e..8f570c3f6 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -40,7 +40,7 @@ struct CHVParams : IndicatorParams { void CHVParams(int _smooth_period = 10, int _chv_period = 10, ENUM_CHV_SMOOTH_METHOD _smooth_method = CHV_SMOOTH_METHOD_EMA, int _shift = 0) { chv_period = _chv_period; - itype = INDI_CHAIKIN_V; + itype = itype == INDI_NONE ? INDI_CHAIKIN_V : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 7211754a3..1771b8259 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -29,7 +29,7 @@ struct ColorBarsParams : IndicatorParams { // Struct constructor. void ColorBarsParams(int _shift = 0) { - itype = INDI_COLOR_BARS; + itype = itype == INDI_NONE ? INDI_COLOR_BARS : itype; max_modes = 5; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index ab64e7412..89765f329 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -29,7 +29,7 @@ struct ColorCandlesDailyParams : IndicatorParams { // Struct constructor. void ColorCandlesDailyParams(int _shift = 0) { - itype = INDI_COLOR_CANDLES_DAILY; + itype = itype == INDI_NONE ? INDI_COLOR_CANDLES_DAILY : itype; max_modes = 5; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index e416facb2..772c617a3 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -30,7 +30,7 @@ struct ColorLineParams : IndicatorParams { // Struct constructor. void ColorLineParams(int _shift = 0) { - itype = INDI_COLOR_LINE; + itype = itype == INDI_NONE ? INDI_COLOR_LINE : itype; max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index 196870871..56215379b 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -32,7 +32,7 @@ struct CustomMovingAverageParams : IndicatorParams { // Struct constructor. void CustomMovingAverageParams(int _smooth_period = 13, int _smooth_shift = 0, ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0) { - itype = INDI_CUSTOM_MOVING_AVG; + itype = itype == INDI_NONE ? INDI_CUSTOM_MOVING_AVG : itype; max_modes = 3; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index a03870201..cdf76c935 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -43,7 +43,7 @@ struct DEMAParams : IndicatorParams { // Struct constructors. void DEMAParams(unsigned int _period = 14, int _ma_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), ma_shift(_ma_shift), applied_price(_ap) { - itype = INDI_DEMA; + itype = itype == INDI_NONE ? INDI_DEMA : itype; SetCustomIndicatorName("Examples\\DEMA"); SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index a08f6d7e9..584e0df4f 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -35,10 +35,10 @@ struct DeMarkerParams : IndicatorParams { unsigned int period; // Struct constructors. void DeMarkerParams(unsigned int _period = 14, int _shift = 0) : period(_period) { - itype = INDI_DEMARKER; + itype = itype == INDI_NONE ? INDI_DEMARKER : itype; max_modes = 1; shift = _shift; - itype = INDI_DEMARKER; + itype = itype == INDI_NONE ? INDI_DEMARKER : itype; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\DeMarker"); diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index 7ad4bdcfc..f7c448e82 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -34,7 +34,7 @@ struct DemoIndiParams : IndicatorParams { // Struct constructors. void DemoIndiParams(int _shift = 0) { - itype = INDI_DEMO; + itype = itype == INDI_NONE ? INDI_DEMO : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 4899163a6..65617b7dc 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -33,7 +33,7 @@ struct DetrendedPriceParams : IndicatorParams { // Struct constructor. void DetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; - itype = INDI_DETRENDED_PRICE; + itype = itype == INDI_NONE ? INDI_DETRENDED_PRICE : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index 989de8f63..6d037bc6b 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -36,7 +36,7 @@ struct DrawerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap) { - itype = INDI_DRAWER; + itype = itype == INDI_NONE ? INDI_DRAWER : itype; // Fetching history data is not yet implemented. max_modes = 0; SetCustomIndicatorName("Examples\\Drawer"); diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 59fc06e62..29590ff35 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -58,7 +58,7 @@ struct EnvelopesParams : IndicatorParams { #else max_modes = 3; #endif - itype = INDI_ENVELOPES; + itype = itype == INDI_NONE ? INDI_ENVELOPES : itype; shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index f1b12bbc9..e3ad407ca 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -51,7 +51,7 @@ struct ForceParams : IndicatorParams { void ForceParams(unsigned int _period = 13, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), ma_method(_ma_method), applied_price(_ap) { - itype = INDI_FORCE; + itype = itype == INDI_NONE ? INDI_FORCE : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 417f1c42c..39482d0fa 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -34,7 +34,7 @@ struct IndiFrAMAParams : IndicatorParams { // Struct constructor. void IndiFrAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { frama_shift = _frama_shift; - itype = INDI_FRAMA; + itype = itype == INDI_NONE ? INDI_FRAMA : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index c69493d8c..3fd47a7ac 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -34,7 +34,7 @@ double iFractals(string _symbol, int _tf, int _mode, int _shift) { struct FractalsParams : IndicatorParams { // Struct constructors. void FractalsParams(int _shift = 0) { - itype = INDI_FRACTALS; + itype = itype == INDI_NONE ? INDI_FRACTALS : itype; max_modes = FINAL_LO_UP_LINE_ENTRY; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_ARROW); diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index 89ae2612b..f9fcbc4e4 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -88,7 +88,7 @@ struct GatorParams : IndicatorParams { lips_shift(_ls), ma_method(_mm), applied_price(_ap) { - itype = INDI_GATOR; + itype = itype == INDI_NONE ? INDI_GATOR : itype; max_modes = FINAL_GATOR_LINE_HISTOGRAM_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index 2ede4b3e2..6fa390bfc 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -51,7 +51,7 @@ enum ENUM_HA_MODE { struct HeikenAshiParams : IndicatorParams { // Struct constructors. void HeikenAshiParams(int _shift = 0) { - itype = INDI_HEIKENASHI; + itype = itype == INDI_NONE ? INDI_HEIKENASHI : itype; max_modes = FINAL_HA_MODE_ENTRY; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); // @fixit It draws candles! diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index 7eb98bb85..3e793cb7b 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -69,7 +69,7 @@ struct IchimokuParams : IndicatorParams { // Struct constructors. void IchimokuParams(unsigned int _ts = 9, unsigned int _ks = 26, unsigned int _ss_b = 52, int _shift = 0) : tenkan_sen(_ts), kijun_sen(_ks), senkou_span_b(_ss_b) { - itype = INDI_ICHIMOKU; + itype = itype == INDI_NONE ? INDI_ICHIMOKU : itype; max_modes = FINAL_ICHIMOKU_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index 697b9dbda..f3f962ecb 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -50,7 +50,7 @@ struct IndiKillzonesParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. void IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - itype = INDI_PIVOT; + itype = itype == INDI_NONE ? INDI_PIVOT : itype; max_modes = FINAL_INDI_KILLZONES_MODE_ENTRY; SetDataValueType(TYPE_FLOAT); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index ac3168c21..76c8a3562 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -55,7 +55,7 @@ struct MAParams : IndicatorParams { void MAParams(unsigned int _period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : period(_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_array(_ap) { - itype = INDI_MA; + itype = itype == INDI_NONE ? INDI_MA : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index 74caa4ce1..e114df811 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -41,7 +41,7 @@ struct MACDParams : IndicatorParams { void MACDParams(unsigned int _efp = 12, unsigned int _esp = 26, unsigned int _sp = 9, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : ema_fast_period(_efp), ema_slow_period(_esp), signal_period(_sp), applied_price(_ap) { - itype = INDI_MACD; + itype = itype == INDI_NONE ? INDI_MACD : itype; max_modes = FINAL_SIGNAL_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index ee77aac06..9dd780c80 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -37,7 +37,7 @@ struct MFIParams : IndicatorParams { // Struct constructors. void MFIParams(unsigned int _ma_period = 14, ENUM_APPLIED_VOLUME _av = VOLUME_TICK, int _shift = 0) : ma_period(_ma_period), applied_volume(_av) { - itype = INDI_MFI; + itype = itype == INDI_NONE ? INDI_MFI : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index 045702419..e9c3ac63a 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -33,7 +33,7 @@ struct MassIndexParams : IndicatorParams { int sum_period; // Struct constructor. void MassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0) { - itype = INDI_MASS_INDEX; + itype = itype == INDI_NONE ? INDI_MASS_INDEX : itype; max_modes = 1; period = _period; second_period = _second_period; diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 99396448c..37295ece6 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -47,7 +47,7 @@ struct MomentumParams : IndicatorParams { // Struct constructors. void MomentumParams(unsigned int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : period(_period), applied_price(_ap) { - itype = INDI_MOMENTUM; + itype = itype == INDI_NONE ? INDI_MOMENTUM : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index ea512882b..af0eb9a31 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -36,7 +36,7 @@ struct OBVParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // MT5 only. // Struct constructors. void OBVParams(int _shift = 0) { - itype = INDI_OBV; + itype = itype == INDI_NONE ? INDI_OBV : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); @@ -46,13 +46,13 @@ struct OBVParams : IndicatorParams { applied_volume = VOLUME_TICK; } void OBVParams(ENUM_APPLIED_VOLUME _av, int _shift = 0) : applied_volume(_av) { - itype = INDI_OBV; + itype = itype == INDI_NONE ? INDI_OBV : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); }; void OBVParams(ENUM_APPLIED_PRICE _ap, int _shift = 0) : applied_price(_ap) { - itype = INDI_OBV; + itype = itype == INDI_NONE ? INDI_OBV : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index f05170ec3..c54bd2c9b 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -40,7 +40,7 @@ struct OsMAParams : IndicatorParams { // Struct constructors. void OsMAParams(int _efp = 12, int _esp = 26, int _sp = 9, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : ema_fast_period(_efp), ema_slow_period(_esp), signal_period(_sp), applied_price(_ap) { - itype = INDI_OSMA; + itype = itype == INDI_NONE ? INDI_OSMA : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index aea4946c0..024e3d3ee 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -33,7 +33,7 @@ struct IndiPatternParams : IndicatorParams { // Struct constructor. void IndiPatternParams(int _shift = 0) { - itype = INDI_PATTERN; + itype = itype == INDI_NONE ? INDI_PATTERN : itype; max_modes = 5; SetDataValueType(TYPE_INT); SetDataValueRange(IDATA_RANGE_BITWISE); diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index 387e0f03e..0fb51b05c 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -31,7 +31,7 @@ struct IndiPivotParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) { - itype = INDI_PIVOT; + itype = itype == INDI_NONE ? INDI_PIVOT : itype; max_modes = 9; method = _method; SetDataValueType(TYPE_FLOAT); diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index 38c8b65f7..988fef71f 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -40,7 +40,7 @@ enum ENUM_INDI_PRICE_MODE { struct PriceIndiParams : IndicatorParams { // Struct constructor. void PriceIndiParams(int _shift = 0) { - itype = INDI_PRICE; + itype = itype == INDI_NONE ? INDI_PRICE : itype; max_modes = FINAL_INDI_PRICE_MODE; SetDataValueType(TYPE_DOUBLE); SetShift(_shift); diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index 92897aef0..0b83251f2 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -29,7 +29,7 @@ struct PriceChannelParams : IndicatorParams { unsigned int period; // Struct constructor. void PriceChannelParams(unsigned int _period = 22, int _shift = 0) { - itype = INDI_PRICE_CHANNEL; + itype = itype == INDI_NONE ? INDI_PRICE_CHANNEL : itype; max_modes = 3; period = _period; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index 1db57347f..9ff60da00 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -33,7 +33,7 @@ struct PriceFeederIndiParams : IndicatorParams { * Struct constructor. */ void PriceFeederIndiParams(int _shift = 0) { - itype = INDI_PRICE_FEEDER; + itype = itype == INDI_NONE ? INDI_PRICE_FEEDER : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); shift = _shift; @@ -45,7 +45,7 @@ struct PriceFeederIndiParams : IndicatorParams { * @todo Use more modes (full OHCL). */ void PriceFeederIndiParams(const double& _price_data[], int _total = 0) { - itype = INDI_PRICE_FEEDER; + itype = itype == INDI_NONE ? INDI_PRICE_FEEDER : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); tf = PERIOD_CURRENT; diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index 26628660b..b138483b1 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -31,7 +31,7 @@ struct PriceVolumeTrendParams : IndicatorParams { // Struct constructor. void PriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { applied_volume = _applied_volume; - itype = INDI_PRICE_VOLUME_TREND; + itype = itype == INDI_NONE ? INDI_PRICE_VOLUME_TREND : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index 220ebdf2e..281a02042 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -32,7 +32,7 @@ struct RSParams : IndicatorParams { // Struct constructor. void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { applied_volume = _applied_volume; - itype = INDI_RS; + itype = itype == INDI_NONE ? INDI_RS : itype; max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index d970edf44..29fe9d7c9 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -49,7 +49,7 @@ struct RSIParams : IndicatorParams { public: void RSIParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : applied_price(_ap) { - itype = INDI_RSI; + itype = itype == INDI_NONE ? INDI_RSI : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index c96116eed..ab51a9c16 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -35,7 +35,7 @@ struct RVIParams : IndicatorParams { unsigned int period; // Struct constructors. void RVIParams(unsigned int _period = 10, int _shift = 0) : period(_period) { - itype = INDI_RVI; + itype = itype == INDI_NONE ? INDI_RVI : itype; max_modes = FINAL_SIGNAL_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index bdfc9e4fc..fddfea88b 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -32,7 +32,7 @@ struct RateOfChangeParams : IndicatorParams { // Struct constructor. void RateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; - itype = INDI_RATE_OF_CHANGE; + itype = itype == INDI_NONE ? INDI_RATE_OF_CHANGE : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 31e1dcf6c..eaf652a70 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -36,7 +36,7 @@ struct SARParams : IndicatorParams { double max; // Struct constructors. void SARParams(double _step = 0.02, double _max = 0.2, int _shift = 0) : step(_step), max(_max) { - itype = INDI_SAR; + itype = itype == INDI_NONE ? INDI_SAR : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index 2d377a54f..504d7262d 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -53,7 +53,7 @@ struct StdDevParams : IndicatorParams { void StdDevParams(int _ma_period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : ma_period(_ma_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_price(_ap) { - itype = INDI_STDDEV; + itype = itype == INDI_NONE ? INDI_STDDEV : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 162097043..29cdd6d8b 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -43,7 +43,7 @@ struct StochParams : IndicatorParams { void StochParams(int _kperiod = 5, int _dperiod = 3, int _slowing = 3, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_STO_PRICE _pf = STO_LOWHIGH, int _shift = 0) : kperiod(_kperiod), dperiod(_dperiod), slowing(_slowing), ma_method(_ma_method), price_field(_pf) { - itype = INDI_STOCHASTIC; + itype = itype == INDI_NONE ? INDI_STOCHASTIC : itype; max_modes = FINAL_SIGNAL_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index 35007603b..e3eacace3 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -34,7 +34,7 @@ struct TEMAParams : IndicatorParams { // Struct constructor. void TEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; - itype = INDI_TEMA; + itype = itype == INDI_NONE ? INDI_TEMA : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index e00e299de..69aab3c0e 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -34,7 +34,7 @@ struct TRIXParams : IndicatorParams { // Struct constructor. void TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; - itype = INDI_TRIX; + itype = itype == INDI_NONE ? INDI_TRIX : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 442ae9da5..575ca3807 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -41,7 +41,7 @@ struct UltimateOscillatorParams : IndicatorParams { int _middle_k = 2, int _slow_k = 1, int _shift = 0) { fast_k = _fast_k; fast_period = _fast_period; - itype = INDI_ULTIMATE_OSCILLATOR; + itype = itype == INDI_NONE ? INDI_ULTIMATE_OSCILLATOR : itype; max_modes = 1; middle_k = _middle_k; middle_period = _middle_period; diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index a27330737..baf7804e3 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -37,7 +37,7 @@ struct VIDYAParams : IndicatorParams { ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { applied_price = _ap; cmo_period = _cmo_period; - itype = INDI_VIDYA; + itype = itype == INDI_NONE ? INDI_VIDYA : itype; ma_period = _ma_period; max_modes = 1; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index dc6a6ee3e..d671fc7c6 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -32,7 +32,7 @@ struct VROCParams : IndicatorParams { // Struct constructor. void VROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { applied_volume = _applied_volume; - itype = INDI_VROC; + itype = itype == INDI_NONE ? INDI_VROC : itype; max_modes = 1; period = _period; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 5c0c00a23..ed6ac1265 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -31,7 +31,7 @@ struct VolumesParams : IndicatorParams { // Struct constructor. void VolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { applied_volume = _applied_volume; - itype = INDI_VOLUMES; + itype = itype == INDI_NONE ? INDI_VOLUMES : itype; max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index 928b1b420..b87b3ceb0 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -35,7 +35,7 @@ struct WPRParams : IndicatorParams { unsigned int period; // Struct constructors. void WPRParams(unsigned int _period = 14, int _shift = 0) : period(_period) { - itype = INDI_WPR; + itype = itype == INDI_NONE ? INDI_WPR : itype; max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index 258719a2c..788f80e60 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -29,7 +29,7 @@ struct WilliamsADParams : IndicatorParams { // Struct constructor. void WilliamsADParams(int _shift = 0) { - itype = INDI_WILLIAMS_AD; + itype = itype == INDI_NONE ? INDI_WILLIAMS_AD : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index 6f4429bb1..128cc6941 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -36,7 +36,7 @@ struct ZigZagParams : IndicatorParams { // Struct constructors. void ZigZagParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) : depth(_depth), deviation(_deviation), backstep(_backstep) { - itype = INDI_ZIGZAG; + itype = itype == INDI_NONE ? INDI_ZIGZAG : itype; max_modes = FINAL_ZIGZAG_LINE_ENTRY; shift = _shift; SetCustomIndicatorName("Examples\\ZigZag"); diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 556fef64c..5bacb454c 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -33,7 +33,7 @@ struct ZigZagColorParams : IndicatorParams { // Struct constructor. void ZigZagColorParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) { - itype = INDI_ZIGZAG_COLOR; + itype = itype == INDI_NONE ? INDI_ZIGZAG_COLOR : itype; backstep = _backstep; depth = _depth; deviation = _deviation; diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 220678cf6..27fb28868 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -43,7 +43,7 @@ struct MathParams : IndicatorParams { void MathParams(ENUM_MATH_OP _op = MATH_OP_SUB, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - itype = INDI_SPECIAL_MATH; + itype = itype == INDI_NONE ? INDI_SPECIAL_MATH : itype; max_modes = 1; mode_1 = _mode_1; mode_2 = _mode_2; @@ -62,7 +62,7 @@ struct MathParams : IndicatorParams { void MathParams(MathCustomOpFunction _op, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - itype = INDI_SPECIAL_MATH; + itype = itype == INDI_NONE ? INDI_SPECIAL_MATH : itype; max_modes = 1; mode_1 = _mode_1; mode_2 = _mode_2; From bf33d11a542b042bf26906266b3a1025bdfe4fc7 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 10 Oct 2021 22:21:15 +0100 Subject: [PATCH 59/78] Indicators: Removes duplicated include --- Indicators/Indi_CHO.mqh | 3 +-- Indicators/Indi_CHV.mqh | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index a89af7d5e..4359ed0d9 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -24,9 +24,8 @@ #include "../BufferStruct.mqh" #include "../Indicator.mqh" #include "../Storage/ValueStorage.all.h" -#include "Indi_MA.mqh" -#include "../Storage/ValueStorage.all.h" #include "../Util.h" +#include "Indi_MA.mqh" // Structs. struct CHOParams : IndicatorParams { diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 8f570c3f6..ae588f7d1 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -24,9 +24,8 @@ #include "../BufferStruct.mqh" #include "../Indicator.mqh" #include "../Storage/ValueStorage.all.h" -#include "Indi_MA.mqh" -#include "../Storage/ValueStorage.all.h" #include "../Util.h" +#include "Indi_MA.mqh" // Enums. enum ENUM_CHV_SMOOTH_METHOD { CHV_SMOOTH_METHOD_SMA = 0, CHV_SMOOTH_METHOD_EMA = 1 }; From f759b43564d4fd63d40923eec63556a2bd83028f Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 10 Oct 2021 22:45:36 +0100 Subject: [PATCH 60/78] Indicators: Moves itype to parent constructor argument --- Indicators/Bitwise/Indi_Candle.mqh | 5 ++--- Indicators/Indi_AC.mqh | 3 +-- Indicators/Indi_AD.mqh | 3 +-- Indicators/Indi_ADX.mqh | 5 ++--- Indicators/Indi_AMA.mqh | 4 ++-- Indicators/Indi_AO.mqh | 3 +-- Indicators/Indi_ASI.mqh | 3 +-- Indicators/Indi_ATR.mqh | 3 +-- Indicators/Indi_Alligator.mqh | 4 ++-- Indicators/Indi_AppliedPrice.mqh | 4 ++-- Indicators/Indi_BWMFI.mqh | 3 +-- Indicators/Indi_BWZT.mqh | 3 +-- Indicators/Indi_Bands.mqh | 3 +-- Indicators/Indi_BearsPower.mqh | 3 +-- Indicators/Indi_BullsPower.mqh | 3 +-- Indicators/Indi_CCI.mqh | 3 +-- Indicators/Indi_CHO.mqh | 4 ++-- Indicators/Indi_CHV.mqh | 4 ++-- Indicators/Indi_ColorBars.mqh | 3 +-- Indicators/Indi_ColorCandlesDaily.mqh | 3 +-- Indicators/Indi_ColorLine.mqh | 3 +-- Indicators/Indi_CustomMovingAverage.mqh | 4 ++-- Indicators/Indi_DEMA.mqh | 3 +-- Indicators/Indi_DeMarker.mqh | 4 +--- Indicators/Indi_Demo.mqh | 3 +-- Indicators/Indi_DetrendedPrice.mqh | 4 ++-- Indicators/Indi_Drawer.struct.h | 3 +-- Indicators/Indi_Envelopes.mqh | 8 ++++++-- Indicators/Indi_Force.mqh | 3 +-- Indicators/Indi_FractalAdaptiveMA.mqh | 4 ++-- Indicators/Indi_Fractals.mqh | 3 +-- Indicators/Indi_Gator.mqh | 4 ++-- Indicators/Indi_HeikenAshi.mqh | 3 +-- Indicators/Indi_Ichimoku.mqh | 3 +-- Indicators/Indi_Killzones.mqh | 6 +++--- Indicators/Indi_MA.mqh | 3 +-- Indicators/Indi_MACD.mqh | 7 +++++-- Indicators/Indi_MFI.mqh | 3 +-- Indicators/Indi_MassIndex.mqh | 4 ++-- Indicators/Indi_Momentum.mqh | 3 +-- Indicators/Indi_OBV.mqh | 9 +++------ Indicators/Indi_OsMA.mqh | 7 +++++-- Indicators/Indi_Pattern.mqh | 3 +-- Indicators/Indi_Pivot.mqh | 3 +-- Indicators/Indi_Price.mqh | 3 +-- Indicators/Indi_PriceChannel.mqh | 3 +-- Indicators/Indi_PriceFeeder.mqh | 6 ++---- Indicators/Indi_PriceVolumeTrend.mqh | 4 ++-- Indicators/Indi_RS.mqh | 3 +-- Indicators/Indi_RSI.mqh | 4 ++-- Indicators/Indi_RVI.mqh | 3 +-- Indicators/Indi_RateOfChange.mqh | 4 ++-- Indicators/Indi_SAR.mqh | 4 ++-- Indicators/Indi_StdDev.mqh | 7 +++++-- Indicators/Indi_Stochastic.mqh | 8 ++++++-- Indicators/Indi_TEMA.mqh | 4 ++-- Indicators/Indi_TRIX.mqh | 3 +-- Indicators/Indi_UltimateOscillator.mqh | 4 ++-- Indicators/Indi_VIDYA.mqh | 4 ++-- Indicators/Indi_VROC.mqh | 4 ++-- Indicators/Indi_Volumes.mqh | 4 ++-- Indicators/Indi_WPR.mqh | 3 +-- Indicators/Indi_WilliamsAD.mqh | 3 +-- Indicators/Indi_ZigZag.mqh | 3 +-- Indicators/Indi_ZigZagColor.mqh | 4 ++-- Indicators/Special/Indi_Math.mqh | 8 ++++---- 66 files changed, 118 insertions(+), 144 deletions(-) diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index 515a82bdb..5129e2f5a 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -32,8 +32,7 @@ // Structs. struct CandleParams : IndicatorParams { // Struct constructor. - void CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - itype = itype == INDI_NONE ? INDI_CANDLE : itype; + void CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE) { max_modes = 1; SetDataValueType(TYPE_INT); SetDataValueRange(IDATA_RANGE_RANGE); @@ -41,7 +40,7 @@ struct CandleParams : IndicatorParams { shift = _shift; tf = _tf; }; - void CandleParams(CandleParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void CandleParams(CandleParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE) { this = _p; tf = _tf; }; diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index b366e718c..20ae48d34 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -32,8 +32,7 @@ double iAC(string _symbol, int _tf, int _shift) { return Indi_AC::iAC(_symbol, ( // Structs. struct ACParams : IndicatorParams { // Struct constructor. - void ACParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_AC : itype; + void ACParams(int _shift = 0) : IndicatorParams(INDI_AC) { max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index 626a16626..d3fa378fd 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -31,8 +31,7 @@ double iAD(string _symbol, int _tf, int _shift) { return Indi_AD::iAD(_symbol, ( // Structs. struct ADParams : IndicatorParams { // Struct constructor. - ADParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_AD : itype; + ADParams(int _shift = 0) : IndicatorParams(INDI_AD) { max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index b0559ebb0..d3c63ed43 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -39,8 +39,7 @@ struct ADXParams : IndicatorParams { // Struct constructors. void ADXParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) - : period(_period), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_ADX : itype; + : period(_period), applied_price(_ap), IndicatorParams(INDI_ADX) { SetDataSourceType(_idstype); SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); @@ -61,7 +60,7 @@ struct ADXParams : IndicatorParams { break; } }; - void ADXParams(ADXParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void ADXParams(ADXParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_ADX) { this = _p; tf = _tf; }; diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index ba0ed3573..8f2a6905e 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -41,8 +41,8 @@ struct IndiAMAParams : IndicatorParams { fast_period(_fast_period), slow_period(_slow_period), ama_shift(_ama_shift), - applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_AMA : itype; + applied_price(_ap), + IndicatorParams(INDI_AMA) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetMaxModes(1); diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index 090445be0..58b1610aa 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -31,8 +31,7 @@ double iAO(string _symbol, int _tf, int _shift) { return Indi_AO::iAO(_symbol, ( // Structs. struct AOParams : IndicatorParams { // Struct constructor. - void AOParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_AO : itype; + void AOParams(int _shift = 0) : IndicatorParams(INDI_AO) { #ifdef __MQL4__ max_modes = 1; #else diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index 99aadc01a..8baadbee6 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -30,8 +30,7 @@ struct ASIParams : IndicatorParams { unsigned int period; double mpc; // Struct constructor. - void ASIParams(double _mpc = 300.0, int _shift = 0) { - itype = itype == INDI_NONE ? INDI_ASI : itype; + void ASIParams(double _mpc = 300.0, int _shift = 0) : IndicatorParams(INDI_ASI) { max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index c1335ffc0..709e3b96f 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -34,8 +34,7 @@ double iATR(string _symbol, int _tf, int _period, int _shift) { struct ATRParams : IndicatorParams { unsigned int period; // Struct constructors. - void ATRParams(unsigned int _period = 14, int _shift = 0) : period(_period) { - itype = itype == INDI_NONE ? INDI_ATR : itype; + void ATRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_ATR) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index e33f1f81a..643f69e8b 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -79,8 +79,8 @@ struct AlligatorParams : IndicatorParams { lips_period(_lp), lips_shift(_ls), ma_method(_mm), - applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_ALLIGATOR : itype; + applied_price(_ap), + IndicatorParams(INDI_ALLIGATOR) { max_modes = FINAL_ALLIGATOR_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index ac7291ec0..3c4144561 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -28,8 +28,8 @@ struct AppliedPriceParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. - AppliedPriceParams(ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) { - itype = itype == INDI_NONE ? INDI_APPLIED_PRICE : itype; + AppliedPriceParams(ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) + : IndicatorParams(INDI_APPLIED_PRICE) { max_modes = 1; applied_price = _applied_price; SetDataSourceType(IDATA_INDICATOR); diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index 421399679..d6a910de6 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -43,8 +43,7 @@ enum ENUM_MFI_COLOR { // Structs. struct BWMFIParams : IndicatorParams { // Struct constructors. - BWMFIParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_BWMFI : itype; + BWMFIParams(int _shift = 0) : IndicatorParams(INDI_BWMFI) { max_modes = FINAL_BWMFI_BUFFER_ENTRY; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 6790f1b75..553bae198 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -33,8 +33,7 @@ struct BWZTParams : IndicatorParams { unsigned int second_period; unsigned int sum_period; // Struct constructor. - void BWZTParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_BWZT : itype; + void BWZTParams(int _shift = 0) : IndicatorParams(INDI_BWZT) { max_modes = 5; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 3e46af6c9..732130d0b 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -66,8 +66,7 @@ struct BandsParams : IndicatorParams { // Struct constructors. void BandsParams(unsigned int _period = 20, double _deviation = 2, int _bshift = 0, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), deviation(_deviation), bshift(_bshift), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_BANDS : itype; + : period(_period), deviation(_deviation), bshift(_bshift), applied_price(_ap), IndicatorParams(INDI_BANDS) { max_modes = FINAL_BANDS_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index fd0756638..120d8a5ee 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -36,8 +36,7 @@ struct BearsPowerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void BearsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_BEARS : itype; + : period(_period), applied_price(_ap), IndicatorParams(INDI_BEARS) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index 9fb6e4319..c38618891 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -36,8 +36,7 @@ struct BullsPowerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // (MT5): not used // Struct constructor. void BullsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_BULLS : itype; + : period(_period), applied_price(_ap), IndicatorParams(INDI_BULLS) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index a89dd2216..275407b93 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -42,8 +42,7 @@ struct CCIParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void CCIParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) - : period(_period), applied_price(_applied_price) { - itype = itype == INDI_NONE ? INDI_CCI : itype; + : period(_period), applied_price(_applied_price), IndicatorParams(INDI_CCI) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 4359ed0d9..021ff8a9e 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -35,10 +35,10 @@ struct CHOParams : IndicatorParams { ENUM_APPLIED_VOLUME input_volume; // Struct constructor. void CHOParams(int _fast_ma = 3, int _slow_ma = 10, ENUM_MA_METHOD _smooth_method = MODE_EMA, - ENUM_APPLIED_VOLUME _input_volume = VOLUME_TICK, int _shift = 0) { + ENUM_APPLIED_VOLUME _input_volume = VOLUME_TICK, int _shift = 0) + : IndicatorParams(INDI_CHAIKIN) { fast_ma = _fast_ma; input_volume = _input_volume; - itype = itype == INDI_NONE ? INDI_CHAIKIN : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index ae588f7d1..7a65883f5 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -37,9 +37,9 @@ struct CHVParams : IndicatorParams { ENUM_CHV_SMOOTH_METHOD smooth_method; // Struct constructor. void CHVParams(int _smooth_period = 10, int _chv_period = 10, - ENUM_CHV_SMOOTH_METHOD _smooth_method = CHV_SMOOTH_METHOD_EMA, int _shift = 0) { + ENUM_CHV_SMOOTH_METHOD _smooth_method = CHV_SMOOTH_METHOD_EMA, int _shift = 0) + : IndicatorParams(INDI_CHAIKIN_V) { chv_period = _chv_period; - itype = itype == INDI_NONE ? INDI_CHAIKIN_V : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 1771b8259..7f1bfd85a 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -28,8 +28,7 @@ // Structs. struct ColorBarsParams : IndicatorParams { // Struct constructor. - void ColorBarsParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_COLOR_BARS : itype; + void ColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS) { max_modes = 5; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index 89765f329..d411014ad 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -28,8 +28,7 @@ // Structs. struct ColorCandlesDailyParams : IndicatorParams { // Struct constructor. - void ColorCandlesDailyParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_COLOR_CANDLES_DAILY : itype; + void ColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY) { max_modes = 5; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 772c617a3..5afe6a8ab 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -29,8 +29,7 @@ // Structs. struct ColorLineParams : IndicatorParams { // Struct constructor. - void ColorLineParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_COLOR_LINE : itype; + void ColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE) { max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index 56215379b..d8f6178f3 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -31,8 +31,8 @@ struct CustomMovingAverageParams : IndicatorParams { ENUM_MA_METHOD smooth_method; // Struct constructor. void CustomMovingAverageParams(int _smooth_period = 13, int _smooth_shift = 0, - ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0) { - itype = itype == INDI_NONE ? INDI_CUSTOM_MOVING_AVG : itype; + ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0) + : IndicatorParams(INDI_CUSTOM_MOVING_AVG) { max_modes = 3; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index cdf76c935..ccc7bae14 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -42,8 +42,7 @@ struct DEMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void DEMAParams(unsigned int _period = 14, int _ma_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), ma_shift(_ma_shift), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_DEMA : itype; + : period(_period), ma_shift(_ma_shift), applied_price(_ap), IndicatorParams(INDI_DEMA) { SetCustomIndicatorName("Examples\\DEMA"); SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index 584e0df4f..ee93d9c34 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -34,11 +34,9 @@ double iDeMarker(string _symbol, int _tf, int _period, int _shift) { struct DeMarkerParams : IndicatorParams { unsigned int period; // Struct constructors. - void DeMarkerParams(unsigned int _period = 14, int _shift = 0) : period(_period) { - itype = itype == INDI_NONE ? INDI_DEMARKER : itype; + void DeMarkerParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_DEMARKER) { max_modes = 1; shift = _shift; - itype = itype == INDI_NONE ? INDI_DEMARKER : itype; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\DeMarker"); diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index f7c448e82..f9b8be1eb 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -33,8 +33,7 @@ // Structs. struct DemoIndiParams : IndicatorParams { // Struct constructors. - void DemoIndiParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_DEMO : itype; + void DemoIndiParams(int _shift = 0) : IndicatorParams(INDI_DEMO) { max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 65617b7dc..962b94c0a 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -31,9 +31,9 @@ struct DetrendedPriceParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void DetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { + void DetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + : IndicatorParams(INDI_DETRENDED_PRICE) { applied_price = _ap; - itype = itype == INDI_NONE ? INDI_DETRENDED_PRICE : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index 6d037bc6b..0ae3a29bc 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -35,8 +35,7 @@ struct DrawerParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; - DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_DRAWER : itype; + DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap), IndicatorParams(INDI_DRAWER) { // Fetching history data is not yet implemented. max_modes = 0; SetCustomIndicatorName("Examples\\Drawer"); diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 29590ff35..af1a938b8 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -51,14 +51,18 @@ struct EnvelopesParams : IndicatorParams { // Struct constructors. void EnvelopesParams(int _ma_period = 13, int _ma_shift = 0, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, double _deviation = 2, int _shift = 0) - : ma_period(_ma_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_price(_ap), deviation(_deviation) { + : ma_period(_ma_period), + ma_shift(_ma_shift), + ma_method(_ma_method), + applied_price(_ap), + deviation(_deviation), + IndicatorParams(INDI_ENVELOPES) { #ifdef __MQL5__ // There is no LINE_MAIN in MQL5 for Envelopes. max_modes = 2; #else max_modes = 3; #endif - itype = itype == INDI_NONE ? INDI_ENVELOPES : itype; shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index e3ad407ca..6ac1a2da4 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -50,8 +50,7 @@ struct ForceParams : IndicatorParams { // Struct constructors. void ForceParams(unsigned int _period = 13, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), ma_method(_ma_method), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_FORCE : itype; + : period(_period), ma_method(_ma_method), applied_price(_ap), IndicatorParams(INDI_FORCE) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 39482d0fa..550af4a2d 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -32,9 +32,9 @@ struct IndiFrAMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void IndiFrAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { + void IndiFrAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + : IndicatorParams(INDI_FRAMA) { frama_shift = _frama_shift; - itype = itype == INDI_NONE ? INDI_FRAMA : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index 3fd47a7ac..e12059d16 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -33,8 +33,7 @@ double iFractals(string _symbol, int _tf, int _mode, int _shift) { // Structs. struct FractalsParams : IndicatorParams { // Struct constructors. - void FractalsParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_FRACTALS : itype; + void FractalsParams(int _shift = 0) : IndicatorParams(INDI_FRACTALS) { max_modes = FINAL_LO_UP_LINE_ENTRY; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_ARROW); diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index f9fcbc4e4..337a6974d 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -87,8 +87,8 @@ struct GatorParams : IndicatorParams { lips_period(_lp), lips_shift(_ls), ma_method(_mm), - applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_GATOR : itype; + applied_price(_ap), + IndicatorParams(INDI_GATOR) { max_modes = FINAL_GATOR_LINE_HISTOGRAM_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index 6fa390bfc..4017adc91 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -50,8 +50,7 @@ enum ENUM_HA_MODE { // Structs. struct HeikenAshiParams : IndicatorParams { // Struct constructors. - void HeikenAshiParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_HEIKENASHI : itype; + void HeikenAshiParams(int _shift = 0) : IndicatorParams(INDI_HEIKENASHI) { max_modes = FINAL_HA_MODE_ENTRY; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); // @fixit It draws candles! diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index 3e793cb7b..a77e3a6b3 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -68,8 +68,7 @@ struct IchimokuParams : IndicatorParams { unsigned int senkou_span_b; // Struct constructors. void IchimokuParams(unsigned int _ts = 9, unsigned int _ks = 26, unsigned int _ss_b = 52, int _shift = 0) - : tenkan_sen(_ts), kijun_sen(_ks), senkou_span_b(_ss_b) { - itype = itype == INDI_NONE ? INDI_ICHIMOKU : itype; + : tenkan_sen(_ts), kijun_sen(_ks), senkou_span_b(_ss_b), IndicatorParams(INDI_ICHIMOKU) { max_modes = FINAL_ICHIMOKU_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index f3f962ecb..20feb0c65 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -49,8 +49,7 @@ enum ENUM_INDI_KILLZONES_MODE { struct IndiKillzonesParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - void IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - itype = itype == INDI_NONE ? INDI_PIVOT : itype; + void IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_PIVOT) { max_modes = FINAL_INDI_KILLZONES_MODE_ENTRY; SetDataValueType(TYPE_FLOAT); SetDataValueRange(IDATA_RANGE_MIXED); @@ -58,7 +57,8 @@ struct IndiKillzonesParams : IndicatorParams { SetShift(_shift); tf = _tf; }; - void IndiKillzonesParams(IndiKillzonesParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void IndiKillzonesParams(IndiKillzonesParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : IndicatorParams(INDI_PIVOT) { this = _p; tf = _tf; }; diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index 76c8a3562..ae735702a 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -54,8 +54,7 @@ struct MAParams : IndicatorParams { // Struct constructors. void MAParams(unsigned int _period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_array(_ap) { - itype = itype == INDI_NONE ? INDI_MA : itype; + : period(_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_array(_ap), IndicatorParams(INDI_MA) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index e114df811..d9fd2898c 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -40,8 +40,11 @@ struct MACDParams : IndicatorParams { // Struct constructors. void MACDParams(unsigned int _efp = 12, unsigned int _esp = 26, unsigned int _sp = 9, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : ema_fast_period(_efp), ema_slow_period(_esp), signal_period(_sp), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_MACD : itype; + : ema_fast_period(_efp), + ema_slow_period(_esp), + signal_period(_sp), + applied_price(_ap), + IndicatorParams(INDI_MACD) { max_modes = FINAL_SIGNAL_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index 9dd780c80..a00a9ddb6 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -36,8 +36,7 @@ struct MFIParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Ignored in MT4. // Struct constructors. void MFIParams(unsigned int _ma_period = 14, ENUM_APPLIED_VOLUME _av = VOLUME_TICK, int _shift = 0) - : ma_period(_ma_period), applied_volume(_av) { - itype = itype == INDI_NONE ? INDI_MFI : itype; + : ma_period(_ma_period), applied_volume(_av), IndicatorParams(INDI_MFI) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index e9c3ac63a..0f224986f 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -32,8 +32,8 @@ struct MassIndexParams : IndicatorParams { int second_period; int sum_period; // Struct constructor. - void MassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0) { - itype = itype == INDI_NONE ? INDI_MASS_INDEX : itype; + void MassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0) + : IndicatorParams(INDI_MASS_INDEX) { max_modes = 1; period = _period; second_period = _second_period; diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 37295ece6..ae929ebd5 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -46,8 +46,7 @@ struct MomentumParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void MomentumParams(unsigned int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_MOMENTUM : itype; + : period(_period), applied_price(_ap), IndicatorParams(INDI_MOMENTUM) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index af0eb9a31..433e05ab7 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -35,8 +35,7 @@ struct OBVParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // MT4 only. ENUM_APPLIED_VOLUME applied_volume; // MT5 only. // Struct constructors. - void OBVParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_OBV : itype; + void OBVParams(int _shift = 0) : IndicatorParams(INDI_OBV) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); @@ -45,14 +44,12 @@ struct OBVParams : IndicatorParams { applied_price = PRICE_CLOSE; applied_volume = VOLUME_TICK; } - void OBVParams(ENUM_APPLIED_VOLUME _av, int _shift = 0) : applied_volume(_av) { - itype = itype == INDI_NONE ? INDI_OBV : itype; + void OBVParams(ENUM_APPLIED_VOLUME _av, int _shift = 0) : applied_volume(_av), IndicatorParams(INDI_OBV) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); }; - void OBVParams(ENUM_APPLIED_PRICE _ap, int _shift = 0) : applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_OBV : itype; + void OBVParams(ENUM_APPLIED_PRICE _ap, int _shift = 0) : applied_price(_ap), IndicatorParams(INDI_OBV) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index c54bd2c9b..743e20032 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -39,8 +39,11 @@ struct OsMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void OsMAParams(int _efp = 12, int _esp = 26, int _sp = 9, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : ema_fast_period(_efp), ema_slow_period(_esp), signal_period(_sp), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_OSMA : itype; + : ema_fast_period(_efp), + ema_slow_period(_esp), + signal_period(_sp), + applied_price(_ap), + IndicatorParams(INDI_OSMA) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index 024e3d3ee..d64916ad8 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -32,8 +32,7 @@ // Structs. struct IndiPatternParams : IndicatorParams { // Struct constructor. - void IndiPatternParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_PATTERN : itype; + void IndiPatternParams(int _shift = 0) : IndicatorParams(INDI_PATTERN) { max_modes = 5; SetDataValueType(TYPE_INT); SetDataValueRange(IDATA_RANGE_BITWISE); diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index 0fb51b05c..8db072aec 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -30,8 +30,7 @@ struct IndiPivotParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) { - itype = itype == INDI_NONE ? INDI_PIVOT : itype; + void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) : IndicatorParams(INDI_PIVOT) { max_modes = 9; method = _method; SetDataValueType(TYPE_FLOAT); diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index 988fef71f..835d1b5d8 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -39,8 +39,7 @@ enum ENUM_INDI_PRICE_MODE { // Structs. struct PriceIndiParams : IndicatorParams { // Struct constructor. - void PriceIndiParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_PRICE : itype; + void PriceIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE) { max_modes = FINAL_INDI_PRICE_MODE; SetDataValueType(TYPE_DOUBLE); SetShift(_shift); diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index 0b83251f2..6f76d9e36 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -28,8 +28,7 @@ struct PriceChannelParams : IndicatorParams { unsigned int period; // Struct constructor. - void PriceChannelParams(unsigned int _period = 22, int _shift = 0) { - itype = itype == INDI_NONE ? INDI_PRICE_CHANNEL : itype; + void PriceChannelParams(unsigned int _period = 22, int _shift = 0) : IndicatorParams(INDI_PRICE_CHANNEL) { max_modes = 3; period = _period; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index 9ff60da00..a89654df0 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -32,8 +32,7 @@ struct PriceFeederIndiParams : IndicatorParams { /** * Struct constructor. */ - void PriceFeederIndiParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_PRICE_FEEDER : itype; + void PriceFeederIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE_FEEDER) { max_modes = 1; SetDataValueType(TYPE_DOUBLE); shift = _shift; @@ -44,8 +43,7 @@ struct PriceFeederIndiParams : IndicatorParams { * * @todo Use more modes (full OHCL). */ - void PriceFeederIndiParams(const double& _price_data[], int _total = 0) { - itype = itype == INDI_NONE ? INDI_PRICE_FEEDER : itype; + void PriceFeederIndiParams(const double& _price_data[], int _total = 0) : IndicatorParams(INDI_PRICE_FEEDER) { max_modes = 1; SetDataValueType(TYPE_DOUBLE); tf = PERIOD_CURRENT; diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index b138483b1..39b2f5753 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -29,9 +29,9 @@ struct PriceVolumeTrendParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void PriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { + void PriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) + : IndicatorParams(INDI_PRICE_VOLUME_TREND) { applied_volume = _applied_volume; - itype = itype == INDI_NONE ? INDI_PRICE_VOLUME_TREND : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index 281a02042..ec5d04f5e 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -30,9 +30,8 @@ struct RSParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { + void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_RS) { applied_volume = _applied_volume; - itype = itype == INDI_NONE ? INDI_RS : itype; max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index 29fe9d7c9..bba2d3cfe 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -48,8 +48,8 @@ struct RSIParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; public: - void RSIParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_RSI : itype; + void RSIParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) + : applied_price(_ap), IndicatorParams(INDI_RSI) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index ab51a9c16..07aafb0b5 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -34,8 +34,7 @@ double iRVI(string _symbol, int _tf, int _period, int _mode, int _shift) { struct RVIParams : IndicatorParams { unsigned int period; // Struct constructors. - void RVIParams(unsigned int _period = 10, int _shift = 0) : period(_period) { - itype = itype == INDI_NONE ? INDI_RVI : itype; + void RVIParams(unsigned int _period = 10, int _shift = 0) : period(_period), IndicatorParams(INDI_RVI) { max_modes = FINAL_SIGNAL_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index fddfea88b..a0da8f3c0 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -30,9 +30,9 @@ struct RateOfChangeParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void RateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { + void RateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + : IndicatorParams(INDI_RATE_OF_CHANGE) { applied_price = _ap; - itype = itype == INDI_NONE ? INDI_RATE_OF_CHANGE : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index eaf652a70..943cce929 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -35,8 +35,8 @@ struct SARParams : IndicatorParams { double step; double max; // Struct constructors. - void SARParams(double _step = 0.02, double _max = 0.2, int _shift = 0) : step(_step), max(_max) { - itype = itype == INDI_NONE ? INDI_SAR : itype; + void SARParams(double _step = 0.02, double _max = 0.2, int _shift = 0) + : step(_step), max(_max), IndicatorParams(INDI_SAR) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index 504d7262d..2b27032de 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -52,8 +52,11 @@ struct StdDevParams : IndicatorParams { // Struct constructors. void StdDevParams(int _ma_period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : ma_period(_ma_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_price(_ap) { - itype = itype == INDI_NONE ? INDI_STDDEV : itype; + : ma_period(_ma_period), + ma_shift(_ma_shift), + ma_method(_ma_method), + applied_price(_ap), + IndicatorParams(INDI_STDDEV) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 29cdd6d8b..227b2944b 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -42,8 +42,12 @@ struct StochParams : IndicatorParams { // Struct constructors. void StochParams(int _kperiod = 5, int _dperiod = 3, int _slowing = 3, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_STO_PRICE _pf = STO_LOWHIGH, int _shift = 0) - : kperiod(_kperiod), dperiod(_dperiod), slowing(_slowing), ma_method(_ma_method), price_field(_pf) { - itype = itype == INDI_NONE ? INDI_STOCHASTIC : itype; + : kperiod(_kperiod), + dperiod(_dperiod), + slowing(_slowing), + ma_method(_ma_method), + price_field(_pf), + IndicatorParams(INDI_STOCHASTIC) { max_modes = FINAL_SIGNAL_LINE_ENTRY; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index e3eacace3..1ca73aade 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -32,9 +32,9 @@ struct TEMAParams : IndicatorParams { unsigned int tema_shift; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void TEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { + void TEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + : IndicatorParams(INDI_TEMA) { applied_price = _ap; - itype = itype == INDI_NONE ? INDI_TEMA : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index 69aab3c0e..6c4300c08 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -32,9 +32,8 @@ struct TRIXParams : IndicatorParams { unsigned int tema_shift; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { + void TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : IndicatorParams(INDI_TRIX) { applied_price = _ap; - itype = itype == INDI_NONE ? INDI_TRIX : itype; max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 575ca3807..5bd4ddba9 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -38,10 +38,10 @@ struct UltimateOscillatorParams : IndicatorParams { // Struct constructor. void UltimateOscillatorParams(int _fast_period = 7, int _middle_period = 14, int _slow_period = 28, int _fast_k = 4, - int _middle_k = 2, int _slow_k = 1, int _shift = 0) { + int _middle_k = 2, int _slow_k = 1, int _shift = 0) + : IndicatorParams(INDI_ULTIMATE_OSCILLATOR) { fast_k = _fast_k; fast_period = _fast_period; - itype = itype == INDI_NONE ? INDI_ULTIMATE_OSCILLATOR : itype; max_modes = 1; middle_k = _middle_k; middle_period = _middle_period; diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index baf7804e3..c1c702523 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -34,10 +34,10 @@ struct VIDYAParams : IndicatorParams { // Struct constructor. void VIDYAParams(unsigned int _cmo_period = 9, unsigned int _ma_period = 14, unsigned int _vidya_shift = 0, - ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { + ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + : IndicatorParams(INDI_VIDYA) { applied_price = _ap; cmo_period = _cmo_period; - itype = itype == INDI_NONE ? INDI_VIDYA : itype; ma_period = _ma_period; max_modes = 1; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index d671fc7c6..e9658344d 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -30,9 +30,9 @@ struct VROCParams : IndicatorParams { unsigned int period; ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void VROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { + void VROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) + : IndicatorParams(INDI_VROC) { applied_volume = _applied_volume; - itype = itype == INDI_NONE ? INDI_VROC : itype; max_modes = 1; period = _period; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index ed6ac1265..5bf1e1337 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -29,9 +29,9 @@ struct VolumesParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void VolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) { + void VolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) + : IndicatorParams(INDI_VOLUMES) { applied_volume = _applied_volume; - itype = itype == INDI_NONE ? INDI_VOLUMES : itype; max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index b87b3ceb0..2d1b99dd4 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -34,8 +34,7 @@ double iWPR(string _symbol, int _tf, int _period, int _shift) { struct WPRParams : IndicatorParams { unsigned int period; // Struct constructors. - void WPRParams(unsigned int _period = 14, int _shift = 0) : period(_period) { - itype = itype == INDI_NONE ? INDI_WPR : itype; + void WPRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_WPR) { max_modes = 1; shift = _shift; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index 788f80e60..3276ad3ac 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -28,8 +28,7 @@ // Structs. struct WilliamsADParams : IndicatorParams { // Struct constructor. - void WilliamsADParams(int _shift = 0) { - itype = itype == INDI_NONE ? INDI_WILLIAMS_AD : itype; + void WilliamsADParams(int _shift = 0) : IndicatorParams(INDI_WILLIAMS_AD) { max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index 128cc6941..ddb97c72b 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -35,8 +35,7 @@ struct ZigZagParams : IndicatorParams { unsigned int backstep; // Struct constructors. void ZigZagParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) - : depth(_depth), deviation(_deviation), backstep(_backstep) { - itype = itype == INDI_NONE ? INDI_ZIGZAG : itype; + : depth(_depth), deviation(_deviation), backstep(_backstep), IndicatorParams(INDI_ZIGZAG) { max_modes = FINAL_ZIGZAG_LINE_ENTRY; shift = _shift; SetCustomIndicatorName("Examples\\ZigZag"); diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 5bacb454c..18342711d 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -32,8 +32,8 @@ struct ZigZagColorParams : IndicatorParams { // Struct constructor. void ZigZagColorParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, - int _shift = 0) { - itype = itype == INDI_NONE ? INDI_ZIGZAG_COLOR : itype; + int _shift = 0) + : IndicatorParams(INDI_ZIGZAG_COLOR) { backstep = _backstep; depth = _depth; deviation = _deviation; diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 27fb28868..b21aace2a 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -42,8 +42,8 @@ struct MathParams : IndicatorParams { // Struct constructor. void MathParams(ENUM_MATH_OP _op = MATH_OP_SUB, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - itype = itype == INDI_NONE ? INDI_SPECIAL_MATH : itype; + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : IndicatorParams(INDI_SPECIAL_MATH) { max_modes = 1; mode_1 = _mode_1; mode_2 = _mode_2; @@ -61,8 +61,8 @@ struct MathParams : IndicatorParams { // Struct constructor. void MathParams(MathCustomOpFunction _op, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - itype = itype == INDI_NONE ? INDI_SPECIAL_MATH : itype; + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : IndicatorParams(INDI_SPECIAL_MATH) { max_modes = 1; mode_1 = _mode_1; mode_2 = _mode_2; From 1de15b302eba5f9e0339d2e63aa0fbeef3f34f80 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 10 Oct 2021 22:59:47 +0100 Subject: [PATCH 61/78] Indicators: Moves max_modes to initializer list --- Indicator.struct.h | 6 +++--- Indicators/Bitwise/Indi_Candle.mqh | 5 ++--- Indicators/Indi_AC.mqh | 3 +-- Indicators/Indi_AD.mqh | 3 +-- Indicators/Indi_ADX.mqh | 3 +-- Indicators/Indi_AMA.mqh | 5 ++--- Indicators/Indi_AO.mqh | 4 +--- Indicators/Indi_ASI.mqh | 3 +-- Indicators/Indi_ATR.mqh | 3 +-- Indicators/Indi_Alligator.mqh | 3 +-- Indicators/Indi_AppliedPrice.mqh | 3 +-- Indicators/Indi_BWMFI.mqh | 3 +-- Indicators/Indi_BWZT.mqh | 3 +-- Indicators/Indi_Bands.mqh | 7 +++++-- Indicators/Indi_BearsPower.mqh | 3 +-- Indicators/Indi_BullsPower.mqh | 3 +-- Indicators/Indi_CCI.mqh | 3 +-- Indicators/Indi_CHO.mqh | 3 +-- Indicators/Indi_CHV.mqh | 3 +-- Indicators/Indi_ColorBars.mqh | 3 +-- Indicators/Indi_ColorCandlesDaily.mqh | 3 +-- Indicators/Indi_ColorLine.mqh | 3 +-- Indicators/Indi_CustomMovingAverage.mqh | 3 +-- Indicators/Indi_DEMA.mqh | 3 +-- Indicators/Indi_DeMarker.mqh | 3 +-- Indicators/Indi_Demo.mqh | 6 ++---- Indicators/Indi_DetrendedPrice.mqh | 3 +-- Indicators/Indi_Drawer.struct.h | 3 +-- Indicators/Indi_Envelopes.mqh | 8 +++----- Indicators/Indi_Force.mqh | 3 +-- Indicators/Indi_FractalAdaptiveMA.mqh | 3 +-- Indicators/Indi_Fractals.mqh | 3 +-- Indicators/Indi_Gator.mqh | 3 +-- Indicators/Indi_HeikenAshi.mqh | 3 +-- Indicators/Indi_Ichimoku.mqh | 6 ++++-- Indicators/Indi_Killzones.mqh | 4 ++-- Indicators/Indi_MA.mqh | 3 +-- Indicators/Indi_MACD.mqh | 3 +-- Indicators/Indi_MFI.mqh | 3 +-- Indicators/Indi_MassIndex.mqh | 3 +-- Indicators/Indi_Momentum.mqh | 3 +-- Indicators/Indi_OBV.mqh | 3 +-- Indicators/Indi_OsMA.mqh | 3 +-- Indicators/Indi_Pattern.mqh | 3 +-- Indicators/Indi_Pivot.mqh | 3 +-- Indicators/Indi_Price.mqh | 3 +-- Indicators/Indi_PriceChannel.mqh | 3 +-- Indicators/Indi_PriceFeeder.mqh | 6 ++---- Indicators/Indi_PriceVolumeTrend.mqh | 3 +-- Indicators/Indi_RS.mqh | 3 +-- Indicators/Indi_RSI.mqh | 3 +-- Indicators/Indi_RVI.mqh | 4 ++-- Indicators/Indi_RateOfChange.mqh | 3 +-- Indicators/Indi_SAR.mqh | 3 +-- Indicators/Indi_StdDev.mqh | 3 +-- Indicators/Indi_Stochastic.mqh | 3 +-- Indicators/Indi_TEMA.mqh | 3 +-- Indicators/Indi_TRIX.mqh | 4 ++-- Indicators/Indi_UltimateOscillator.mqh | 3 +-- Indicators/Indi_VIDYA.mqh | 3 +-- Indicators/Indi_VROC.mqh | 3 +-- Indicators/Indi_Volumes.mqh | 3 +-- Indicators/Indi_WPR.mqh | 3 +-- Indicators/Indi_WilliamsAD.mqh | 3 +-- Indicators/Indi_ZigZag.mqh | 6 ++++-- Indicators/Indi_ZigZagColor.mqh | 3 +-- Indicators/Special/Indi_Math.mqh | 3 +-- 67 files changed, 88 insertions(+), 145 deletions(-) diff --git a/Indicator.struct.h b/Indicator.struct.h index 2fa6be1ff..39c79bff5 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -375,12 +375,12 @@ struct IndicatorParams { string custom_indi_name; // Name of the indicator passed to iCustom() method. /* Special methods */ // Constructor. - IndicatorParams(ENUM_INDICATOR_TYPE _itype = INDI_NONE, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, - string _name = "") + IndicatorParams(ENUM_INDICATOR_TYPE _itype = INDI_NONE, unsigned int _max_modes = 1, + ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, string _name = "") : custom_indi_name(""), name(_name), shift(0), - max_modes(1), + max_modes(_max_modes), max_buffers(10), idstype(_idstype), idvrange(IDATA_RANGE_UNKNOWN), diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index 5129e2f5a..6c10a7a11 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -32,15 +32,14 @@ // Structs. struct CandleParams : IndicatorParams { // Struct constructor. - void CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE) { - max_modes = 1; + void CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE, 1) { SetDataValueType(TYPE_INT); SetDataValueRange(IDATA_RANGE_RANGE); SetDataSourceType(IDATA_BUILTIN); shift = _shift; tf = _tf; }; - void CandleParams(CandleParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE) { + void CandleParams(CandleParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE, 1) { this = _p; tf = _tf; }; diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 20ae48d34..6b35a0c29 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -32,8 +32,7 @@ double iAC(string _symbol, int _tf, int _shift) { return Indi_AC::iAC(_symbol, ( // Structs. struct ACParams : IndicatorParams { // Struct constructor. - void ACParams(int _shift = 0) : IndicatorParams(INDI_AC) { - max_modes = 1; + void ACParams(int _shift = 0) : IndicatorParams(INDI_AC, 1) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Accelerator"); diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index d3fa378fd..0f75deb35 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -31,8 +31,7 @@ double iAD(string _symbol, int _tf, int _shift) { return Indi_AD::iAD(_symbol, ( // Structs. struct ADParams : IndicatorParams { // Struct constructor. - ADParams(int _shift = 0) : IndicatorParams(INDI_AD) { - max_modes = 1; + ADParams(int _shift = 0) : IndicatorParams(INDI_AD, 1) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\AD"); diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index d3c63ed43..09eb3b05d 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -39,11 +39,10 @@ struct ADXParams : IndicatorParams { // Struct constructors. void ADXParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) - : period(_period), applied_price(_ap), IndicatorParams(INDI_ADX) { + : period(_period), applied_price(_ap), IndicatorParams(INDI_ADX, FINAL_INDI_ADX_LINE_ENTRY) { SetDataSourceType(_idstype); SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); - SetMaxModes(FINAL_INDI_ADX_LINE_ENTRY); SetShift(_shift); switch (idstype) { case IDATA_ICUSTOM: diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index 8f2a6905e..4a4b6d10b 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -42,10 +42,9 @@ struct IndiAMAParams : IndicatorParams { slow_period(_slow_period), ama_shift(_ama_shift), applied_price(_ap), - IndicatorParams(INDI_AMA) { + IndicatorParams(INDI_AMA, 1) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); - SetMaxModes(1); SetShift(_shift); switch (idstype) { case IDATA_ICUSTOM: @@ -63,7 +62,7 @@ struct IndiAMAParams : IndicatorParams { break; } }; - void IndiAMAParams(IndiAMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void IndiAMAParams(IndiAMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_AMA, 1) { this = _p; tf = _tf; }; diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index 58b1610aa..d69492c2e 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -31,11 +31,9 @@ double iAO(string _symbol, int _tf, int _shift) { return Indi_AO::iAO(_symbol, ( // Structs. struct AOParams : IndicatorParams { // Struct constructor. - void AOParams(int _shift = 0) : IndicatorParams(INDI_AO) { + void AOParams(int _shift = 0) : IndicatorParams(INDI_AO, 2) { #ifdef __MQL4__ max_modes = 1; -#else - max_modes = 2; #endif SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index 8baadbee6..b26ced65a 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -30,8 +30,7 @@ struct ASIParams : IndicatorParams { unsigned int period; double mpc; // Struct constructor. - void ASIParams(double _mpc = 300.0, int _shift = 0) : IndicatorParams(INDI_ASI) { - max_modes = 1; + void ASIParams(double _mpc = 300.0, int _shift = 0) : IndicatorParams(INDI_ASI, 1) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ASI"); diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index 709e3b96f..cce835877 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -34,8 +34,7 @@ double iATR(string _symbol, int _tf, int _period, int _shift) { struct ATRParams : IndicatorParams { unsigned int period; // Struct constructors. - void ATRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_ATR) { - max_modes = 1; + void ATRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_ATR, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index 643f69e8b..80f115a76 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -80,8 +80,7 @@ struct AlligatorParams : IndicatorParams { lips_shift(_ls), ma_method(_mm), applied_price(_ap), - IndicatorParams(INDI_ALLIGATOR) { - max_modes = FINAL_ALLIGATOR_LINE_ENTRY; + IndicatorParams(INDI_ALLIGATOR, FINAL_ALLIGATOR_LINE_ENTRY) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index 3c4144561..1c0b0d2cf 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -29,8 +29,7 @@ struct AppliedPriceParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. AppliedPriceParams(ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) - : IndicatorParams(INDI_APPLIED_PRICE) { - max_modes = 1; + : IndicatorParams(INDI_APPLIED_PRICE, 1) { applied_price = _applied_price; SetDataSourceType(IDATA_INDICATOR); SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index d6a910de6..c24637576 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -43,8 +43,7 @@ enum ENUM_MFI_COLOR { // Structs. struct BWMFIParams : IndicatorParams { // Struct constructors. - BWMFIParams(int _shift = 0) : IndicatorParams(INDI_BWMFI) { - max_modes = FINAL_BWMFI_BUFFER_ENTRY; + BWMFIParams(int _shift = 0) : IndicatorParams(INDI_BWMFI, FINAL_BWMFI_BUFFER_ENTRY) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\MarketFacilitationIndex"); diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 553bae198..5db079988 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -33,8 +33,7 @@ struct BWZTParams : IndicatorParams { unsigned int second_period; unsigned int sum_period; // Struct constructor. - void BWZTParams(int _shift = 0) : IndicatorParams(INDI_BWZT) { - max_modes = 5; + void BWZTParams(int _shift = 0) : IndicatorParams(INDI_BWZT, 5) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\BW-ZoneTrade"); diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 732130d0b..00be01ee1 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -66,8 +66,11 @@ struct BandsParams : IndicatorParams { // Struct constructors. void BandsParams(unsigned int _period = 20, double _deviation = 2, int _bshift = 0, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), deviation(_deviation), bshift(_bshift), applied_price(_ap), IndicatorParams(INDI_BANDS) { - max_modes = FINAL_BANDS_LINE_ENTRY; + : period(_period), + deviation(_deviation), + bshift(_bshift), + applied_price(_ap), + IndicatorParams(INDI_BANDS, FINAL_BANDS_LINE_ENTRY) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index 120d8a5ee..5c7067b50 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -36,8 +36,7 @@ struct BearsPowerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void BearsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), applied_price(_ap), IndicatorParams(INDI_BEARS) { - max_modes = 1; + : period(_period), applied_price(_ap), IndicatorParams(INDI_BEARS, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index c38618891..2dfeb69ae 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -36,8 +36,7 @@ struct BullsPowerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // (MT5): not used // Struct constructor. void BullsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), applied_price(_ap), IndicatorParams(INDI_BULLS) { - max_modes = 1; + : period(_period), applied_price(_ap), IndicatorParams(INDI_BULLS, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 275407b93..5329c0735 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -42,8 +42,7 @@ struct CCIParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void CCIParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) - : period(_period), applied_price(_applied_price), IndicatorParams(INDI_CCI) { - max_modes = 1; + : period(_period), applied_price(_applied_price), IndicatorParams(INDI_CCI, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 021ff8a9e..85fbf0b21 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -36,10 +36,9 @@ struct CHOParams : IndicatorParams { // Struct constructor. void CHOParams(int _fast_ma = 3, int _slow_ma = 10, ENUM_MA_METHOD _smooth_method = MODE_EMA, ENUM_APPLIED_VOLUME _input_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_CHAIKIN) { + : IndicatorParams(INDI_CHAIKIN, 1) { fast_ma = _fast_ma; input_volume = _input_volume; - max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CHO"); diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 7a65883f5..fa1f39e7a 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -38,9 +38,8 @@ struct CHVParams : IndicatorParams { // Struct constructor. void CHVParams(int _smooth_period = 10, int _chv_period = 10, ENUM_CHV_SMOOTH_METHOD _smooth_method = CHV_SMOOTH_METHOD_EMA, int _shift = 0) - : IndicatorParams(INDI_CHAIKIN_V) { + : IndicatorParams(INDI_CHAIKIN_V, 1) { chv_period = _chv_period; - max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CHV"); diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 7f1bfd85a..cb037cae9 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -28,8 +28,7 @@ // Structs. struct ColorBarsParams : IndicatorParams { // Struct constructor. - void ColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS) { - max_modes = 5; + void ColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS, 5) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorBars"); diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index d411014ad..755bcc4c1 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -28,8 +28,7 @@ // Structs. struct ColorCandlesDailyParams : IndicatorParams { // Struct constructor. - void ColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY) { - max_modes = 5; + void ColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY, 5) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorCandlesDaily"); diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 5afe6a8ab..fc93abc47 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -29,8 +29,7 @@ // Structs. struct ColorLineParams : IndicatorParams { // Struct constructor. - void ColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE) { - max_modes = 2; + void ColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE, 2) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorLine"); diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index d8f6178f3..20bd1a2c0 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -32,8 +32,7 @@ struct CustomMovingAverageParams : IndicatorParams { // Struct constructor. void CustomMovingAverageParams(int _smooth_period = 13, int _smooth_shift = 0, ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0) - : IndicatorParams(INDI_CUSTOM_MOVING_AVG) { - max_modes = 3; + : IndicatorParams(INDI_CUSTOM_MOVING_AVG, 3) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_ICUSTOM); diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index ccc7bae14..ac20fb0e8 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -42,11 +42,10 @@ struct DEMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void DEMAParams(unsigned int _period = 14, int _ma_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), ma_shift(_ma_shift), applied_price(_ap), IndicatorParams(INDI_DEMA) { + : period(_period), ma_shift(_ma_shift), applied_price(_ap), IndicatorParams(INDI_DEMA, 1) { SetCustomIndicatorName("Examples\\DEMA"); SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); - SetMaxModes(1); SetShift(_shift); switch (idstype) { case IDATA_ICUSTOM: diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index ee93d9c34..847e79c2d 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -34,8 +34,7 @@ double iDeMarker(string _symbol, int _tf, int _period, int _shift) { struct DeMarkerParams : IndicatorParams { unsigned int period; // Struct constructors. - void DeMarkerParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_DEMARKER) { - max_modes = 1; + void DeMarkerParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_DEMARKER, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index f9b8be1eb..3c411836c 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -33,11 +33,9 @@ // Structs. struct DemoIndiParams : IndicatorParams { // Struct constructors. - void DemoIndiParams(int _shift = 0) : IndicatorParams(INDI_DEMO) { - max_modes = 1; + void DemoIndiParams(int _shift = 0) : IndicatorParams(INDI_DEMO, 1) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); - SetMaxModes(1); SetShift(_shift); switch (idstype) { case IDATA_ICUSTOM: @@ -55,7 +53,7 @@ struct DemoIndiParams : IndicatorParams { break; } }; - void DemoIndiParams(DemoIndiParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void DemoIndiParams(DemoIndiParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_DEMO, 1) { this = _p; tf = _tf; }; diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 962b94c0a..428a23334 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -32,9 +32,8 @@ struct DetrendedPriceParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. void DetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_DETRENDED_PRICE) { + : IndicatorParams(INDI_DETRENDED_PRICE, 1) { applied_price = _ap; - max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\DPO"); diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index 0ae3a29bc..9b03d482e 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -35,9 +35,8 @@ struct DrawerParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; - DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap), IndicatorParams(INDI_DRAWER) { + DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap), IndicatorParams(INDI_DRAWER, 0) { // Fetching history data is not yet implemented. - max_modes = 0; SetCustomIndicatorName("Examples\\Drawer"); SetDataValueType(TYPE_DOUBLE); }; diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index af1a938b8..5feaf5f61 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -56,11 +56,9 @@ struct EnvelopesParams : IndicatorParams { ma_method(_ma_method), applied_price(_ap), deviation(_deviation), - IndicatorParams(INDI_ENVELOPES) { -#ifdef __MQL5__ - // There is no LINE_MAIN in MQL5 for Envelopes. - max_modes = 2; -#else + IndicatorParams(INDI_ENVELOPES, 2) { +#ifdef __MQL4__ + // There is extra LINE_MAIN in MQL4 for Envelopes. max_modes = 3; #endif shift = _shift; diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index 6ac1a2da4..3835fd19e 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -50,8 +50,7 @@ struct ForceParams : IndicatorParams { // Struct constructors. void ForceParams(unsigned int _period = 13, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), ma_method(_ma_method), applied_price(_ap), IndicatorParams(INDI_FORCE) { - max_modes = 1; + : period(_period), ma_method(_ma_method), applied_price(_ap), IndicatorParams(INDI_FORCE, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 550af4a2d..7bab86786 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -33,9 +33,8 @@ struct IndiFrAMAParams : IndicatorParams { // Struct constructor. void IndiFrAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_FRAMA) { + : IndicatorParams(INDI_FRAMA, 1) { frama_shift = _frama_shift; - max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\FrAMA"); diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index e12059d16..182bf1246 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -33,8 +33,7 @@ double iFractals(string _symbol, int _tf, int _mode, int _shift) { // Structs. struct FractalsParams : IndicatorParams { // Struct constructors. - void FractalsParams(int _shift = 0) : IndicatorParams(INDI_FRACTALS) { - max_modes = FINAL_LO_UP_LINE_ENTRY; + void FractalsParams(int _shift = 0) : IndicatorParams(INDI_FRACTALS, FINAL_LO_UP_LINE_ENTRY) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_ARROW); SetCustomIndicatorName("Examples\\Fractals"); diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index 337a6974d..30ede3e80 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -88,8 +88,7 @@ struct GatorParams : IndicatorParams { lips_shift(_ls), ma_method(_mm), applied_price(_ap), - IndicatorParams(INDI_GATOR) { - max_modes = FINAL_GATOR_LINE_HISTOGRAM_ENTRY; + IndicatorParams(INDI_GATOR, FINAL_GATOR_LINE_HISTOGRAM_ENTRY) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index 4017adc91..00a1f9223 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -50,8 +50,7 @@ enum ENUM_HA_MODE { // Structs. struct HeikenAshiParams : IndicatorParams { // Struct constructors. - void HeikenAshiParams(int _shift = 0) : IndicatorParams(INDI_HEIKENASHI) { - max_modes = FINAL_HA_MODE_ENTRY; + void HeikenAshiParams(int _shift = 0) : IndicatorParams(INDI_HEIKENASHI, FINAL_HA_MODE_ENTRY) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); // @fixit It draws candles! #ifdef __MQL4__ diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index a77e3a6b3..7c464014e 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -68,8 +68,10 @@ struct IchimokuParams : IndicatorParams { unsigned int senkou_span_b; // Struct constructors. void IchimokuParams(unsigned int _ts = 9, unsigned int _ks = 26, unsigned int _ss_b = 52, int _shift = 0) - : tenkan_sen(_ts), kijun_sen(_ks), senkou_span_b(_ss_b), IndicatorParams(INDI_ICHIMOKU) { - max_modes = FINAL_ICHIMOKU_LINE_ENTRY; + : tenkan_sen(_ts), + kijun_sen(_ks), + senkou_span_b(_ss_b), + IndicatorParams(INDI_ICHIMOKU, FINAL_ICHIMOKU_LINE_ENTRY) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Not sure if not mixed. diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index 20feb0c65..bd13de665 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -49,8 +49,8 @@ enum ENUM_INDI_KILLZONES_MODE { struct IndiKillzonesParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - void IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_PIVOT) { - max_modes = FINAL_INDI_KILLZONES_MODE_ENTRY; + void IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : IndicatorParams(INDI_PIVOT, FINAL_INDI_KILLZONES_MODE_ENTRY) { SetDataValueType(TYPE_FLOAT); SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_CHART); diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index ae735702a..1f2cb9500 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -54,8 +54,7 @@ struct MAParams : IndicatorParams { // Struct constructors. void MAParams(unsigned int _period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_array(_ap), IndicatorParams(INDI_MA) { - max_modes = 1; + : period(_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_array(_ap), IndicatorParams(INDI_MA, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index d9fd2898c..a542f98b0 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -44,8 +44,7 @@ struct MACDParams : IndicatorParams { ema_slow_period(_esp), signal_period(_sp), applied_price(_ap), - IndicatorParams(INDI_MACD) { - max_modes = FINAL_SIGNAL_LINE_ENTRY; + IndicatorParams(INDI_MACD, FINAL_SIGNAL_LINE_ENTRY) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index a00a9ddb6..785f42c8d 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -36,8 +36,7 @@ struct MFIParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Ignored in MT4. // Struct constructors. void MFIParams(unsigned int _ma_period = 14, ENUM_APPLIED_VOLUME _av = VOLUME_TICK, int _shift = 0) - : ma_period(_ma_period), applied_volume(_av), IndicatorParams(INDI_MFI) { - max_modes = 1; + : ma_period(_ma_period), applied_volume(_av), IndicatorParams(INDI_MFI, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index 0f224986f..e7807e8a5 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -33,8 +33,7 @@ struct MassIndexParams : IndicatorParams { int sum_period; // Struct constructor. void MassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0) - : IndicatorParams(INDI_MASS_INDEX) { - max_modes = 1; + : IndicatorParams(INDI_MASS_INDEX, 1) { period = _period; second_period = _second_period; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index ae929ebd5..0a04da3d8 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -46,8 +46,7 @@ struct MomentumParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void MomentumParams(unsigned int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), applied_price(_ap), IndicatorParams(INDI_MOMENTUM) { - max_modes = 1; + : period(_period), applied_price(_ap), IndicatorParams(INDI_MOMENTUM, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 433e05ab7..6d3b9f7be 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -35,8 +35,7 @@ struct OBVParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // MT4 only. ENUM_APPLIED_VOLUME applied_volume; // MT5 only. // Struct constructors. - void OBVParams(int _shift = 0) : IndicatorParams(INDI_OBV) { - max_modes = 1; + void OBVParams(int _shift = 0) : IndicatorParams(INDI_OBV, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 743e20032..06ecd1585 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -43,8 +43,7 @@ struct OsMAParams : IndicatorParams { ema_slow_period(_esp), signal_period(_sp), applied_price(_ap), - IndicatorParams(INDI_OSMA) { - max_modes = 1; + IndicatorParams(INDI_OSMA, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index d64916ad8..157a5021c 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -32,8 +32,7 @@ // Structs. struct IndiPatternParams : IndicatorParams { // Struct constructor. - void IndiPatternParams(int _shift = 0) : IndicatorParams(INDI_PATTERN) { - max_modes = 5; + void IndiPatternParams(int _shift = 0) : IndicatorParams(INDI_PATTERN, 5) { SetDataValueType(TYPE_INT); SetDataValueRange(IDATA_RANGE_BITWISE); shift = _shift; diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index 8db072aec..5e0bc36f8 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -30,8 +30,7 @@ struct IndiPivotParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) : IndicatorParams(INDI_PIVOT) { - max_modes = 9; + void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) : IndicatorParams(INDI_PIVOT, 9) { method = _method; SetDataValueType(TYPE_FLOAT); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index 835d1b5d8..d0639c0e5 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -39,8 +39,7 @@ enum ENUM_INDI_PRICE_MODE { // Structs. struct PriceIndiParams : IndicatorParams { // Struct constructor. - void PriceIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE) { - max_modes = FINAL_INDI_PRICE_MODE; + void PriceIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE, FINAL_INDI_PRICE_MODE) { SetDataValueType(TYPE_DOUBLE); SetShift(_shift); }; diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index 6f76d9e36..813f68eed 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -28,8 +28,7 @@ struct PriceChannelParams : IndicatorParams { unsigned int period; // Struct constructor. - void PriceChannelParams(unsigned int _period = 22, int _shift = 0) : IndicatorParams(INDI_PRICE_CHANNEL) { - max_modes = 3; + void PriceChannelParams(unsigned int _period = 22, int _shift = 0) : IndicatorParams(INDI_PRICE_CHANNEL, 3) { period = _period; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index a89654df0..aab2c5f58 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -32,8 +32,7 @@ struct PriceFeederIndiParams : IndicatorParams { /** * Struct constructor. */ - void PriceFeederIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE_FEEDER) { - max_modes = 1; + void PriceFeederIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE_FEEDER, 1) { SetDataValueType(TYPE_DOUBLE); shift = _shift; } @@ -43,8 +42,7 @@ struct PriceFeederIndiParams : IndicatorParams { * * @todo Use more modes (full OHCL). */ - void PriceFeederIndiParams(const double& _price_data[], int _total = 0) : IndicatorParams(INDI_PRICE_FEEDER) { - max_modes = 1; + void PriceFeederIndiParams(const double& _price_data[], int _total = 0) : IndicatorParams(INDI_PRICE_FEEDER, 1) { SetDataValueType(TYPE_DOUBLE); tf = PERIOD_CURRENT; ArrayCopy(price_data, _price_data, 0, 0, _total == 0 ? WHOLE_ARRAY : _total); diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index 39b2f5753..42b249a48 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -30,9 +30,8 @@ struct PriceVolumeTrendParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. void PriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_PRICE_VOLUME_TREND) { + : IndicatorParams(INDI_PRICE_VOLUME_TREND, 1) { applied_volume = _applied_volume; - max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\PVT"); diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index ec5d04f5e..1109e4d39 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -30,9 +30,8 @@ struct RSParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_RS) { + void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_RS, 2) { applied_volume = _applied_volume; - max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_MATH); diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index bba2d3cfe..e85f3d8aa 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -49,8 +49,7 @@ struct RSIParams : IndicatorParams { public: void RSIParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : applied_price(_ap), IndicatorParams(INDI_RSI) { - max_modes = 1; + : applied_price(_ap), IndicatorParams(INDI_RSI, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index 07aafb0b5..169ec9752 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -34,8 +34,8 @@ double iRVI(string _symbol, int _tf, int _period, int _mode, int _shift) { struct RVIParams : IndicatorParams { unsigned int period; // Struct constructors. - void RVIParams(unsigned int _period = 10, int _shift = 0) : period(_period), IndicatorParams(INDI_RVI) { - max_modes = FINAL_SIGNAL_LINE_ENTRY; + void RVIParams(unsigned int _period = 10, int _shift = 0) + : period(_period), IndicatorParams(INDI_RVI, FINAL_SIGNAL_LINE_ENTRY) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index a0da8f3c0..0832823cb 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -31,9 +31,8 @@ struct RateOfChangeParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. void RateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_RATE_OF_CHANGE) { + : IndicatorParams(INDI_RATE_OF_CHANGE, 1) { applied_price = _ap; - max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ROC"); diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 943cce929..82de209a1 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -36,8 +36,7 @@ struct SARParams : IndicatorParams { double max; // Struct constructors. void SARParams(double _step = 0.02, double _max = 0.2, int _shift = 0) - : step(_step), max(_max), IndicatorParams(INDI_SAR) { - max_modes = 1; + : step(_step), max(_max), IndicatorParams(INDI_SAR, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); // @fixit It draws single dot for each bar! diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index 2b27032de..f6d02d3f8 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -56,8 +56,7 @@ struct StdDevParams : IndicatorParams { ma_shift(_ma_shift), ma_method(_ma_method), applied_price(_ap), - IndicatorParams(INDI_STDDEV) { - max_modes = 1; + IndicatorParams(INDI_STDDEV, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 227b2944b..7426a4efc 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -47,8 +47,7 @@ struct StochParams : IndicatorParams { slowing(_slowing), ma_method(_ma_method), price_field(_pf), - IndicatorParams(INDI_STOCHASTIC) { - max_modes = FINAL_SIGNAL_LINE_ENTRY; + IndicatorParams(INDI_STOCHASTIC, FINAL_SIGNAL_LINE_ENTRY) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index 1ca73aade..e2b081a90 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -33,9 +33,8 @@ struct TEMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. void TEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_TEMA) { + : IndicatorParams(INDI_TEMA, 1) { applied_price = _ap; - max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\TEMA"); diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index 6c4300c08..706d36082 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -32,9 +32,9 @@ struct TRIXParams : IndicatorParams { unsigned int tema_shift; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : IndicatorParams(INDI_TRIX) { + void TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + : IndicatorParams(INDI_TRIX, 1) { applied_price = _ap; - max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\TRIX"); diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 5bd4ddba9..38f78a1eb 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -39,10 +39,9 @@ struct UltimateOscillatorParams : IndicatorParams { // Struct constructor. void UltimateOscillatorParams(int _fast_period = 7, int _middle_period = 14, int _slow_period = 28, int _fast_k = 4, int _middle_k = 2, int _slow_k = 1, int _shift = 0) - : IndicatorParams(INDI_ULTIMATE_OSCILLATOR) { + : IndicatorParams(INDI_ULTIMATE_OSCILLATOR, 1) { fast_k = _fast_k; fast_period = _fast_period; - max_modes = 1; middle_k = _middle_k; middle_period = _middle_period; SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index c1c702523..bb14cfa70 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -35,11 +35,10 @@ struct VIDYAParams : IndicatorParams { // Struct constructor. void VIDYAParams(unsigned int _cmo_period = 9, unsigned int _ma_period = 14, unsigned int _vidya_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_VIDYA) { + : IndicatorParams(INDI_VIDYA, 1) { applied_price = _ap; cmo_period = _cmo_period; ma_period = _ma_period; - max_modes = 1; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\VIDYA"); diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index e9658344d..0d3a8d885 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -31,9 +31,8 @@ struct VROCParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. void VROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_VROC) { + : IndicatorParams(INDI_VROC, 1) { applied_volume = _applied_volume; - max_modes = 1; period = _period; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 5bf1e1337..1e3dabb27 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -30,9 +30,8 @@ struct VolumesParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. void VolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_VOLUMES) { + : IndicatorParams(INDI_VOLUMES, 2) { applied_volume = _applied_volume; - max_modes = 2; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Volumes"); diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index 2d1b99dd4..8cb6e3d2f 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -34,8 +34,7 @@ double iWPR(string _symbol, int _tf, int _period, int _shift) { struct WPRParams : IndicatorParams { unsigned int period; // Struct constructors. - void WPRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_WPR) { - max_modes = 1; + void WPRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_WPR, 1) { shift = _shift; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index 3276ad3ac..e014226f2 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -28,8 +28,7 @@ // Structs. struct WilliamsADParams : IndicatorParams { // Struct constructor. - void WilliamsADParams(int _shift = 0) : IndicatorParams(INDI_WILLIAMS_AD) { - max_modes = 1; + void WilliamsADParams(int _shift = 0) : IndicatorParams(INDI_WILLIAMS_AD, 1) { SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\W_AD"); diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index ddb97c72b..066d53050 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -35,8 +35,10 @@ struct ZigZagParams : IndicatorParams { unsigned int backstep; // Struct constructors. void ZigZagParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) - : depth(_depth), deviation(_deviation), backstep(_backstep), IndicatorParams(INDI_ZIGZAG) { - max_modes = FINAL_ZIGZAG_LINE_ENTRY; + : depth(_depth), + deviation(_deviation), + backstep(_backstep), + IndicatorParams(INDI_ZIGZAG, FINAL_ZIGZAG_LINE_ENTRY) { shift = _shift; SetCustomIndicatorName("Examples\\ZigZag"); SetDataValueType(TYPE_DOUBLE); diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 18342711d..f41bfbdc0 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -33,11 +33,10 @@ struct ZigZagColorParams : IndicatorParams { // Struct constructor. void ZigZagColorParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) - : IndicatorParams(INDI_ZIGZAG_COLOR) { + : IndicatorParams(INDI_ZIGZAG_COLOR, 3) { backstep = _backstep; depth = _depth; deviation = _deviation; - max_modes = 3; SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ZigZagColor"); diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index b21aace2a..3d3fe8ad1 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -43,8 +43,7 @@ struct MathParams : IndicatorParams { void MathParams(ENUM_MATH_OP _op = MATH_OP_SUB, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : IndicatorParams(INDI_SPECIAL_MATH) { - max_modes = 1; + : IndicatorParams(INDI_SPECIAL_MATH, 1) { mode_1 = _mode_1; mode_2 = _mode_2; op_builtin = _op; From 46b1d82d6997500a3937bdeabe4b7337dfb1519a Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 10 Oct 2021 23:12:09 +0100 Subject: [PATCH 62/78] Indicators: Moves dtype to initializer list --- Indicator.struct.h | 4 +++- Indicators/Bitwise/Indi_Candle.mqh | 6 +++--- Indicators/Indi_AC.mqh | 3 +-- Indicators/Indi_AD.mqh | 3 +-- Indicators/Indi_ADX.mqh | 6 +++--- Indicators/Indi_AMA.mqh | 3 +-- Indicators/Indi_AO.mqh | 3 +-- Indicators/Indi_ASI.mqh | 3 +-- Indicators/Indi_ATR.mqh | 4 ++-- Indicators/Indi_Alligator.mqh | 3 +-- Indicators/Indi_AppliedPrice.mqh | 3 +-- Indicators/Indi_BWMFI.mqh | 3 +-- Indicators/Indi_BWZT.mqh | 3 +-- Indicators/Indi_Bands.mqh | 3 +-- Indicators/Indi_BearsPower.mqh | 3 +-- Indicators/Indi_BullsPower.mqh | 3 +-- Indicators/Indi_CCI.mqh | 3 +-- Indicators/Indi_CHO.mqh | 3 +-- Indicators/Indi_CHV.mqh | 3 +-- Indicators/Indi_ColorBars.mqh | 3 +-- Indicators/Indi_ColorCandlesDaily.mqh | 3 +-- Indicators/Indi_ColorLine.mqh | 3 +-- Indicators/Indi_CustomMovingAverage.mqh | 3 +-- Indicators/Indi_DEMA.mqh | 3 +-- Indicators/Indi_DeMarker.mqh | 4 ++-- Indicators/Indi_Demo.mqh | 3 +-- Indicators/Indi_DetrendedPrice.mqh | 3 +-- Indicators/Indi_Drawer.struct.h | 3 +-- Indicators/Indi_Envelopes.mqh | 3 +-- Indicators/Indi_Force.mqh | 3 +-- Indicators/Indi_FractalAdaptiveMA.mqh | 3 +-- Indicators/Indi_Fractals.mqh | 3 +-- Indicators/Indi_Gator.mqh | 3 +-- Indicators/Indi_HeikenAshi.mqh | 3 +-- Indicators/Indi_Ichimoku.mqh | 3 +-- Indicators/Indi_Killzones.mqh | 3 +-- Indicators/Indi_MA.mqh | 7 +++++-- Indicators/Indi_MACD.mqh | 3 +-- Indicators/Indi_MFI.mqh | 3 +-- Indicators/Indi_MassIndex.mqh | 3 +-- Indicators/Indi_Momentum.mqh | 3 +-- Indicators/Indi_OBV.mqh | 11 +++++------ Indicators/Indi_OsMA.mqh | 3 +-- Indicators/Indi_Pattern.mqh | 3 +-- Indicators/Indi_Pivot.mqh | 3 +-- Indicators/Indi_Price.mqh | 3 +-- Indicators/Indi_PriceChannel.mqh | 4 ++-- Indicators/Indi_PriceFeeder.mqh | 9 +++------ Indicators/Indi_PriceVolumeTrend.mqh | 3 +-- Indicators/Indi_RS.mqh | 4 ++-- Indicators/Indi_RSI.mqh | 3 +-- Indicators/Indi_RVI.mqh | 3 +-- Indicators/Indi_RateOfChange.mqh | 3 +-- Indicators/Indi_SAR.mqh | 3 +-- Indicators/Indi_StdDev.mqh | 3 +-- Indicators/Indi_Stochastic.mqh | 3 +-- Indicators/Indi_TEMA.mqh | 3 +-- Indicators/Indi_TRIX.mqh | 3 +-- Indicators/Indi_UltimateOscillator.mqh | 3 +-- Indicators/Indi_VIDYA.mqh | 3 +-- Indicators/Indi_VROC.mqh | 3 +-- Indicators/Indi_Volumes.mqh | 3 +-- Indicators/Indi_WPR.mqh | 4 ++-- Indicators/Indi_WilliamsAD.mqh | 3 +-- Indicators/Indi_ZigZag.mqh | 3 +-- Indicators/Indi_ZigZagColor.mqh | 3 +-- Indicators/Special/Indi_Math.mqh | 9 ++++----- 67 files changed, 91 insertions(+), 146 deletions(-) diff --git a/Indicator.struct.h b/Indicator.struct.h index 39c79bff5..5b9bdbd0c 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -376,8 +376,10 @@ struct IndicatorParams { /* Special methods */ // Constructor. IndicatorParams(ENUM_INDICATOR_TYPE _itype = INDI_NONE, unsigned int _max_modes = 1, - ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, string _name = "") + ENUM_DATATYPE _dtype = TYPE_DOUBLE, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, + string _name = "") : custom_indi_name(""), + dtype(_dtype), name(_name), shift(0), max_modes(_max_modes), diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index 6c10a7a11..807d06731 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -32,14 +32,14 @@ // Structs. struct CandleParams : IndicatorParams { // Struct constructor. - void CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE, 1) { - SetDataValueType(TYPE_INT); + void CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE, 1, TYPE_INT) { SetDataValueRange(IDATA_RANGE_RANGE); SetDataSourceType(IDATA_BUILTIN); shift = _shift; tf = _tf; }; - void CandleParams(CandleParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE, 1) { + void CandleParams(CandleParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : IndicatorParams(INDI_CANDLE, 1, TYPE_INT) { this = _p; tf = _tf; }; diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 6b35a0c29..289b4a306 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -32,8 +32,7 @@ double iAC(string _symbol, int _tf, int _shift) { return Indi_AC::iAC(_symbol, ( // Structs. struct ACParams : IndicatorParams { // Struct constructor. - void ACParams(int _shift = 0) : IndicatorParams(INDI_AC, 1) { - SetDataValueType(TYPE_DOUBLE); + void ACParams(int _shift = 0) : IndicatorParams(INDI_AC, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Accelerator"); shift = _shift; diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index 0f75deb35..b6ad900fb 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -31,8 +31,7 @@ double iAD(string _symbol, int _tf, int _shift) { return Indi_AD::iAD(_symbol, ( // Structs. struct ADParams : IndicatorParams { // Struct constructor. - ADParams(int _shift = 0) : IndicatorParams(INDI_AD, 1) { - SetDataValueType(TYPE_DOUBLE); + ADParams(int _shift = 0) : IndicatorParams(INDI_AD, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\AD"); shift = _shift; diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 09eb3b05d..68b09b248 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -39,9 +39,8 @@ struct ADXParams : IndicatorParams { // Struct constructors. void ADXParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) - : period(_period), applied_price(_ap), IndicatorParams(INDI_ADX, FINAL_INDI_ADX_LINE_ENTRY) { + : period(_period), applied_price(_ap), IndicatorParams(INDI_ADX, FINAL_INDI_ADX_LINE_ENTRY, TYPE_DOUBLE) { SetDataSourceType(_idstype); - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetShift(_shift); switch (idstype) { @@ -59,7 +58,8 @@ struct ADXParams : IndicatorParams { break; } }; - void ADXParams(ADXParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_ADX) { + void ADXParams(ADXParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : IndicatorParams(INDI_ADX, FINAL_INDI_ADX_LINE_ENTRY, TYPE_DOUBLE) { this = _p; tf = _tf; }; diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index 4a4b6d10b..927e9ea9c 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -42,8 +42,7 @@ struct IndiAMAParams : IndicatorParams { slow_period(_slow_period), ama_shift(_ama_shift), applied_price(_ap), - IndicatorParams(INDI_AMA, 1) { - SetDataValueType(TYPE_DOUBLE); + IndicatorParams(INDI_AMA, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_PRICE); SetShift(_shift); switch (idstype) { diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index d69492c2e..4022963ca 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -31,11 +31,10 @@ double iAO(string _symbol, int _tf, int _shift) { return Indi_AO::iAO(_symbol, ( // Structs. struct AOParams : IndicatorParams { // Struct constructor. - void AOParams(int _shift = 0) : IndicatorParams(INDI_AO, 2) { + void AOParams(int _shift = 0) : IndicatorParams(INDI_AO, 2, TYPE_DOUBLE) { #ifdef __MQL4__ max_modes = 1; #endif - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Awesome_Oscillator"); shift = _shift; diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index b26ced65a..d2861b4b8 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -30,8 +30,7 @@ struct ASIParams : IndicatorParams { unsigned int period; double mpc; // Struct constructor. - void ASIParams(double _mpc = 300.0, int _shift = 0) : IndicatorParams(INDI_ASI, 1) { - SetDataValueType(TYPE_DOUBLE); + void ASIParams(double _mpc = 300.0, int _shift = 0) : IndicatorParams(INDI_ASI, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ASI"); mpc = _mpc; diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index cce835877..06c5bfbe3 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -34,9 +34,9 @@ double iATR(string _symbol, int _tf, int _period, int _shift) { struct ATRParams : IndicatorParams { unsigned int period; // Struct constructors. - void ATRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_ATR, 1) { + void ATRParams(unsigned int _period = 14, int _shift = 0) + : period(_period), IndicatorParams(INDI_ATR, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ATR"); }; diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index 80f115a76..dba50437f 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -80,9 +80,8 @@ struct AlligatorParams : IndicatorParams { lips_shift(_ls), ma_method(_mm), applied_price(_ap), - IndicatorParams(INDI_ALLIGATOR, FINAL_ALLIGATOR_LINE_ENTRY) { + IndicatorParams(INDI_ALLIGATOR, FINAL_ALLIGATOR_LINE_ENTRY, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Alligator"); }; diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index 1c0b0d2cf..6af51cc52 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -29,10 +29,9 @@ struct AppliedPriceParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. AppliedPriceParams(ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) - : IndicatorParams(INDI_APPLIED_PRICE, 1) { + : IndicatorParams(INDI_APPLIED_PRICE, 1, TYPE_DOUBLE) { applied_price = _applied_price; SetDataSourceType(IDATA_INDICATOR); - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); shift = _shift; }; diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index c24637576..fd500024a 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -43,8 +43,7 @@ enum ENUM_MFI_COLOR { // Structs. struct BWMFIParams : IndicatorParams { // Struct constructors. - BWMFIParams(int _shift = 0) : IndicatorParams(INDI_BWMFI, FINAL_BWMFI_BUFFER_ENTRY) { - SetDataValueType(TYPE_DOUBLE); + BWMFIParams(int _shift = 0) : IndicatorParams(INDI_BWMFI, FINAL_BWMFI_BUFFER_ENTRY, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\MarketFacilitationIndex"); shift = _shift; diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 5db079988..d27e80c79 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -33,8 +33,7 @@ struct BWZTParams : IndicatorParams { unsigned int second_period; unsigned int sum_period; // Struct constructor. - void BWZTParams(int _shift = 0) : IndicatorParams(INDI_BWZT, 5) { - SetDataValueType(TYPE_DOUBLE); + void BWZTParams(int _shift = 0) : IndicatorParams(INDI_BWZT, 5, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\BW-ZoneTrade"); shift = _shift; diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 00be01ee1..22377c084 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -70,9 +70,8 @@ struct BandsParams : IndicatorParams { deviation(_deviation), bshift(_bshift), applied_price(_ap), - IndicatorParams(INDI_BANDS, FINAL_BANDS_LINE_ENTRY) { + IndicatorParams(INDI_BANDS, FINAL_BANDS_LINE_ENTRY, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\BB"); }; diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index 5c7067b50..6bf8d2ba5 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -36,9 +36,8 @@ struct BearsPowerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void BearsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), applied_price(_ap), IndicatorParams(INDI_BEARS, 1) { + : period(_period), applied_price(_ap), IndicatorParams(INDI_BEARS, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Bears"); }; diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index 2dfeb69ae..b1d49062f 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -36,9 +36,8 @@ struct BullsPowerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // (MT5): not used // Struct constructor. void BullsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), applied_price(_ap), IndicatorParams(INDI_BULLS, 1) { + : period(_period), applied_price(_ap), IndicatorParams(INDI_BULLS, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Bulls"); }; diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 5329c0735..e9345101c 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -42,9 +42,8 @@ struct CCIParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void CCIParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) - : period(_period), applied_price(_applied_price), IndicatorParams(INDI_CCI, 1) { + : period(_period), applied_price(_applied_price), IndicatorParams(INDI_CCI, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CCI"); }; diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 85fbf0b21..b0706f88b 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -36,10 +36,9 @@ struct CHOParams : IndicatorParams { // Struct constructor. void CHOParams(int _fast_ma = 3, int _slow_ma = 10, ENUM_MA_METHOD _smooth_method = MODE_EMA, ENUM_APPLIED_VOLUME _input_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_CHAIKIN, 1) { + : IndicatorParams(INDI_CHAIKIN, 1, TYPE_DOUBLE) { fast_ma = _fast_ma; input_volume = _input_volume; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CHO"); shift = _shift; diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index fa1f39e7a..3c960b261 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -38,9 +38,8 @@ struct CHVParams : IndicatorParams { // Struct constructor. void CHVParams(int _smooth_period = 10, int _chv_period = 10, ENUM_CHV_SMOOTH_METHOD _smooth_method = CHV_SMOOTH_METHOD_EMA, int _shift = 0) - : IndicatorParams(INDI_CHAIKIN_V, 1) { + : IndicatorParams(INDI_CHAIKIN_V, 1, TYPE_DOUBLE) { chv_period = _chv_period; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CHV"); shift = _shift; diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index cb037cae9..308f2ce7c 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -28,8 +28,7 @@ // Structs. struct ColorBarsParams : IndicatorParams { // Struct constructor. - void ColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS, 5) { - SetDataValueType(TYPE_DOUBLE); + void ColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS, 5, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorBars"); shift = _shift; diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index 755bcc4c1..4ba882667 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -28,8 +28,7 @@ // Structs. struct ColorCandlesDailyParams : IndicatorParams { // Struct constructor. - void ColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY, 5) { - SetDataValueType(TYPE_DOUBLE); + void ColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY, 5, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorCandlesDaily"); shift = _shift; diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index fc93abc47..9e023fd18 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -29,8 +29,7 @@ // Structs. struct ColorLineParams : IndicatorParams { // Struct constructor. - void ColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE, 2) { - SetDataValueType(TYPE_DOUBLE); + void ColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE, 2, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorLine"); shift = _shift; diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index 20bd1a2c0..254c11278 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -32,8 +32,7 @@ struct CustomMovingAverageParams : IndicatorParams { // Struct constructor. void CustomMovingAverageParams(int _smooth_period = 13, int _smooth_shift = 0, ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0) - : IndicatorParams(INDI_CUSTOM_MOVING_AVG, 3) { - SetDataValueType(TYPE_DOUBLE); + : IndicatorParams(INDI_CUSTOM_MOVING_AVG, 3, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_ICUSTOM); #ifdef __MQL5__ diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index ac20fb0e8..9b8f87619 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -42,9 +42,8 @@ struct DEMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void DEMAParams(unsigned int _period = 14, int _ma_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), ma_shift(_ma_shift), applied_price(_ap), IndicatorParams(INDI_DEMA, 1) { + : period(_period), ma_shift(_ma_shift), applied_price(_ap), IndicatorParams(INDI_DEMA, 1, TYPE_DOUBLE) { SetCustomIndicatorName("Examples\\DEMA"); - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetShift(_shift); switch (idstype) { diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index 847e79c2d..ff425e99b 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -34,9 +34,9 @@ double iDeMarker(string _symbol, int _tf, int _period, int _shift) { struct DeMarkerParams : IndicatorParams { unsigned int period; // Struct constructors. - void DeMarkerParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_DEMARKER, 1) { + void DeMarkerParams(unsigned int _period = 14, int _shift = 0) + : period(_period), IndicatorParams(INDI_DEMARKER, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\DeMarker"); }; diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index 3c411836c..7154b7f45 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -33,8 +33,7 @@ // Structs. struct DemoIndiParams : IndicatorParams { // Struct constructors. - void DemoIndiParams(int _shift = 0) : IndicatorParams(INDI_DEMO, 1) { - SetDataValueType(TYPE_DOUBLE); + void DemoIndiParams(int _shift = 0) : IndicatorParams(INDI_DEMO, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetShift(_shift); switch (idstype) { diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 428a23334..a24bf3afb 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -32,9 +32,8 @@ struct DetrendedPriceParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. void DetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_DETRENDED_PRICE, 1) { + : IndicatorParams(INDI_DETRENDED_PRICE, 1, TYPE_DOUBLE) { applied_price = _ap; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\DPO"); period = _period; diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index 9b03d482e..94a7c3c14 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -35,10 +35,9 @@ struct DrawerParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; - DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap), IndicatorParams(INDI_DRAWER, 0) { + DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap), IndicatorParams(INDI_DRAWER, 0, TYPE_DOUBLE) { // Fetching history data is not yet implemented. SetCustomIndicatorName("Examples\\Drawer"); - SetDataValueType(TYPE_DOUBLE); }; void DrawerParams(DrawerParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { this = _p; diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 5feaf5f61..24666cc91 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -56,13 +56,12 @@ struct EnvelopesParams : IndicatorParams { ma_method(_ma_method), applied_price(_ap), deviation(_deviation), - IndicatorParams(INDI_ENVELOPES, 2) { + IndicatorParams(INDI_ENVELOPES, 2, TYPE_DOUBLE) { #ifdef __MQL4__ // There is extra LINE_MAIN in MQL4 for Envelopes. max_modes = 3; #endif shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Envelopes"); }; diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index 3835fd19e..bc90228bd 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -50,9 +50,8 @@ struct ForceParams : IndicatorParams { // Struct constructors. void ForceParams(unsigned int _period = 13, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), ma_method(_ma_method), applied_price(_ap), IndicatorParams(INDI_FORCE, 1) { + : period(_period), ma_method(_ma_method), applied_price(_ap), IndicatorParams(INDI_FORCE, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Force_Index"); }; diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 7bab86786..6082a590c 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -33,9 +33,8 @@ struct IndiFrAMAParams : IndicatorParams { // Struct constructor. void IndiFrAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_FRAMA, 1) { + : IndicatorParams(INDI_FRAMA, 1, TYPE_DOUBLE) { frama_shift = _frama_shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\FrAMA"); applied_price = _ap; diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index 182bf1246..b166b60eb 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -33,8 +33,7 @@ double iFractals(string _symbol, int _tf, int _mode, int _shift) { // Structs. struct FractalsParams : IndicatorParams { // Struct constructors. - void FractalsParams(int _shift = 0) : IndicatorParams(INDI_FRACTALS, FINAL_LO_UP_LINE_ENTRY) { - SetDataValueType(TYPE_DOUBLE); + void FractalsParams(int _shift = 0) : IndicatorParams(INDI_FRACTALS, FINAL_LO_UP_LINE_ENTRY, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_ARROW); SetCustomIndicatorName("Examples\\Fractals"); shift = _shift; diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index 30ede3e80..ba70d1cd8 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -88,9 +88,8 @@ struct GatorParams : IndicatorParams { lips_shift(_ls), ma_method(_mm), applied_price(_ap), - IndicatorParams(INDI_GATOR, FINAL_GATOR_LINE_HISTOGRAM_ENTRY) { + IndicatorParams(INDI_GATOR, FINAL_GATOR_LINE_HISTOGRAM_ENTRY, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Gator"); }; diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index 00a1f9223..db3bc7df3 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -50,8 +50,7 @@ enum ENUM_HA_MODE { // Structs. struct HeikenAshiParams : IndicatorParams { // Struct constructors. - void HeikenAshiParams(int _shift = 0) : IndicatorParams(INDI_HEIKENASHI, FINAL_HA_MODE_ENTRY) { - SetDataValueType(TYPE_DOUBLE); + void HeikenAshiParams(int _shift = 0) : IndicatorParams(INDI_HEIKENASHI, FINAL_HA_MODE_ENTRY, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); // @fixit It draws candles! #ifdef __MQL4__ SetCustomIndicatorName("Heiken Ashi"); diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index 7c464014e..14a624400 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -71,9 +71,8 @@ struct IchimokuParams : IndicatorParams { : tenkan_sen(_ts), kijun_sen(_ks), senkou_span_b(_ss_b), - IndicatorParams(INDI_ICHIMOKU, FINAL_ICHIMOKU_LINE_ENTRY) { + IndicatorParams(INDI_ICHIMOKU, FINAL_ICHIMOKU_LINE_ENTRY, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Not sure if not mixed. SetCustomIndicatorName("Examples\\Ichimoku"); }; diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index bd13de665..d089ac009 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -50,8 +50,7 @@ struct IndiKillzonesParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. void IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : IndicatorParams(INDI_PIVOT, FINAL_INDI_KILLZONES_MODE_ENTRY) { - SetDataValueType(TYPE_FLOAT); + : IndicatorParams(INDI_PIVOT, FINAL_INDI_KILLZONES_MODE_ENTRY, TYPE_FLOAT) { SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_CHART); SetShift(_shift); diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index 1f2cb9500..4de0f69b1 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -54,9 +54,12 @@ struct MAParams : IndicatorParams { // Struct constructors. void MAParams(unsigned int _period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_array(_ap), IndicatorParams(INDI_MA, 1) { + : period(_period), + ma_shift(_ma_shift), + ma_method(_ma_method), + applied_array(_ap), + IndicatorParams(INDI_MA, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Moving Average"); }; diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index a542f98b0..21c76f62f 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -44,9 +44,8 @@ struct MACDParams : IndicatorParams { ema_slow_period(_esp), signal_period(_sp), applied_price(_ap), - IndicatorParams(INDI_MACD, FINAL_SIGNAL_LINE_ENTRY) { + IndicatorParams(INDI_MACD, FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\MACD"); }; diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index 785f42c8d..2e4654549 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -36,9 +36,8 @@ struct MFIParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Ignored in MT4. // Struct constructors. void MFIParams(unsigned int _ma_period = 14, ENUM_APPLIED_VOLUME _av = VOLUME_TICK, int _shift = 0) - : ma_period(_ma_period), applied_volume(_av), IndicatorParams(INDI_MFI, 1) { + : ma_period(_ma_period), applied_volume(_av), IndicatorParams(INDI_MFI, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\MFI"); }; diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index e7807e8a5..1c404c1d7 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -33,10 +33,9 @@ struct MassIndexParams : IndicatorParams { int sum_period; // Struct constructor. void MassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0) - : IndicatorParams(INDI_MASS_INDEX, 1) { + : IndicatorParams(INDI_MASS_INDEX, 1, TYPE_DOUBLE) { period = _period; second_period = _second_period; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\MI"); shift = _shift; diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 0a04da3d8..8199a0df2 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -46,9 +46,8 @@ struct MomentumParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. void MomentumParams(unsigned int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), applied_price(_ap), IndicatorParams(INDI_MOMENTUM, 1) { + : period(_period), applied_price(_ap), IndicatorParams(INDI_MOMENTUM, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Momentum"); }; diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 6d3b9f7be..1c283e7e2 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -35,23 +35,22 @@ struct OBVParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // MT4 only. ENUM_APPLIED_VOLUME applied_volume; // MT5 only. // Struct constructors. - void OBVParams(int _shift = 0) : IndicatorParams(INDI_OBV, 1) { + void OBVParams(int _shift = 0) : IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\OBV"); applied_price = PRICE_CLOSE; applied_volume = VOLUME_TICK; } - void OBVParams(ENUM_APPLIED_VOLUME _av, int _shift = 0) : applied_volume(_av), IndicatorParams(INDI_OBV) { + void OBVParams(ENUM_APPLIED_VOLUME _av, int _shift = 0) + : applied_volume(_av), IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { max_modes = 1; shift = _shift; - SetDataValueType(TYPE_DOUBLE); }; - void OBVParams(ENUM_APPLIED_PRICE _ap, int _shift = 0) : applied_price(_ap), IndicatorParams(INDI_OBV) { + void OBVParams(ENUM_APPLIED_PRICE _ap, int _shift = 0) + : applied_price(_ap), IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { max_modes = 1; shift = _shift; - SetDataValueType(TYPE_DOUBLE); }; }; diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 06ecd1585..38f29527b 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -43,9 +43,8 @@ struct OsMAParams : IndicatorParams { ema_slow_period(_esp), signal_period(_sp), applied_price(_ap), - IndicatorParams(INDI_OSMA, 1) { + IndicatorParams(INDI_OSMA, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\OsMA"); }; diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index 157a5021c..415a6d8c5 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -32,8 +32,7 @@ // Structs. struct IndiPatternParams : IndicatorParams { // Struct constructor. - void IndiPatternParams(int _shift = 0) : IndicatorParams(INDI_PATTERN, 5) { - SetDataValueType(TYPE_INT); + void IndiPatternParams(int _shift = 0) : IndicatorParams(INDI_PATTERN, 5, TYPE_INT) { SetDataValueRange(IDATA_RANGE_BITWISE); shift = _shift; }; diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index 5e0bc36f8..dbeb0677b 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -30,9 +30,8 @@ struct IndiPivotParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) : IndicatorParams(INDI_PIVOT, 9) { + void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) : IndicatorParams(INDI_PIVOT, 9, TYPE_FLOAT) { method = _method; - SetDataValueType(TYPE_FLOAT); SetDataValueRange(IDATA_RANGE_MIXED); shift = _shift; }; diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index d0639c0e5..b8e14a5d5 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -39,8 +39,7 @@ enum ENUM_INDI_PRICE_MODE { // Structs. struct PriceIndiParams : IndicatorParams { // Struct constructor. - void PriceIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE, FINAL_INDI_PRICE_MODE) { - SetDataValueType(TYPE_DOUBLE); + void PriceIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE, FINAL_INDI_PRICE_MODE, TYPE_DOUBLE) { SetShift(_shift); }; }; diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index 813f68eed..92e6b1109 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -28,9 +28,9 @@ struct PriceChannelParams : IndicatorParams { unsigned int period; // Struct constructor. - void PriceChannelParams(unsigned int _period = 22, int _shift = 0) : IndicatorParams(INDI_PRICE_CHANNEL, 3) { + void PriceChannelParams(unsigned int _period = 22, int _shift = 0) + : IndicatorParams(INDI_PRICE_CHANNEL, 3, TYPE_DOUBLE) { period = _period; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Price_Channel"); SetDataSourceType(IDATA_ICUSTOM); diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index aab2c5f58..701581585 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -32,18 +32,15 @@ struct PriceFeederIndiParams : IndicatorParams { /** * Struct constructor. */ - void PriceFeederIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE_FEEDER, 1) { - SetDataValueType(TYPE_DOUBLE); - shift = _shift; - } + void PriceFeederIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE_FEEDER, 1, TYPE_DOUBLE) { shift = _shift; } /** * Struct constructor. * * @todo Use more modes (full OHCL). */ - void PriceFeederIndiParams(const double& _price_data[], int _total = 0) : IndicatorParams(INDI_PRICE_FEEDER, 1) { - SetDataValueType(TYPE_DOUBLE); + void PriceFeederIndiParams(const double& _price_data[], int _total = 0) + : IndicatorParams(INDI_PRICE_FEEDER, 1, TYPE_DOUBLE) { tf = PERIOD_CURRENT; ArrayCopy(price_data, _price_data, 0, 0, _total == 0 ? WHOLE_ARRAY : _total); }; diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index 42b249a48..0e46ae7c9 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -30,9 +30,8 @@ struct PriceVolumeTrendParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. void PriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_PRICE_VOLUME_TREND, 1) { + : IndicatorParams(INDI_PRICE_VOLUME_TREND, 1, TYPE_DOUBLE) { applied_volume = _applied_volume; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\PVT"); shift = _shift; diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index 1109e4d39..1de359a47 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -30,9 +30,9 @@ struct RSParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_RS, 2) { + void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) + : IndicatorParams(INDI_RS, 2, TYPE_DOUBLE) { applied_volume = _applied_volume; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_MATH); shift = _shift; diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index e85f3d8aa..763ff921a 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -49,9 +49,8 @@ struct RSIParams : IndicatorParams { public: void RSIParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : applied_price(_ap), IndicatorParams(INDI_RSI, 1) { + : applied_price(_ap), IndicatorParams(INDI_RSI, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\RSI"); SetPeriod(_period); diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index 169ec9752..c1eebc8cf 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -35,9 +35,8 @@ struct RVIParams : IndicatorParams { unsigned int period; // Struct constructors. void RVIParams(unsigned int _period = 10, int _shift = 0) - : period(_period), IndicatorParams(INDI_RVI, FINAL_SIGNAL_LINE_ENTRY) { + : period(_period), IndicatorParams(INDI_RVI, FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\RVI"); }; diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index 0832823cb..0c42cc126 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -31,9 +31,8 @@ struct RateOfChangeParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. void RateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_RATE_OF_CHANGE, 1) { + : IndicatorParams(INDI_RATE_OF_CHANGE, 1, TYPE_DOUBLE) { applied_price = _ap; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ROC"); period = _period; diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 82de209a1..279a10d33 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -36,9 +36,8 @@ struct SARParams : IndicatorParams { double max; // Struct constructors. void SARParams(double _step = 0.02, double _max = 0.2, int _shift = 0) - : step(_step), max(_max), IndicatorParams(INDI_SAR, 1) { + : step(_step), max(_max), IndicatorParams(INDI_SAR, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); // @fixit It draws single dot for each bar! SetCustomIndicatorName("Examples\\ParabolicSAR"); }; diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index f6d02d3f8..dd02f4f97 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -56,9 +56,8 @@ struct StdDevParams : IndicatorParams { ma_shift(_ma_shift), ma_method(_ma_method), applied_price(_ap), - IndicatorParams(INDI_STDDEV, 1) { + IndicatorParams(INDI_STDDEV, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\StdDev"); }; diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 7426a4efc..59159222e 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -47,9 +47,8 @@ struct StochParams : IndicatorParams { slowing(_slowing), ma_method(_ma_method), price_field(_pf), - IndicatorParams(INDI_STOCHASTIC, FINAL_SIGNAL_LINE_ENTRY) { + IndicatorParams(INDI_STOCHASTIC, FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\Stochastic"); }; diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index e2b081a90..17415ef79 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -33,9 +33,8 @@ struct TEMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. void TEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_TEMA, 1) { + : IndicatorParams(INDI_TEMA, 1, TYPE_DOUBLE) { applied_price = _ap; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\TEMA"); period = _period; diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index 706d36082..9fa4436d0 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -33,9 +33,8 @@ struct TRIXParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. void TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_TRIX, 1) { + : IndicatorParams(INDI_TRIX, 1, TYPE_DOUBLE) { applied_price = _ap; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\TRIX"); period = _period; diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 38f78a1eb..421b09425 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -39,12 +39,11 @@ struct UltimateOscillatorParams : IndicatorParams { // Struct constructor. void UltimateOscillatorParams(int _fast_period = 7, int _middle_period = 14, int _slow_period = 28, int _fast_k = 4, int _middle_k = 2, int _slow_k = 1, int _shift = 0) - : IndicatorParams(INDI_ULTIMATE_OSCILLATOR, 1) { + : IndicatorParams(INDI_ULTIMATE_OSCILLATOR, 1, TYPE_DOUBLE) { fast_k = _fast_k; fast_period = _fast_period; middle_k = _middle_k; middle_period = _middle_period; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Ultimate_Oscillator"); shift = _shift; diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index bb14cfa70..ddcc33c7b 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -35,11 +35,10 @@ struct VIDYAParams : IndicatorParams { // Struct constructor. void VIDYAParams(unsigned int _cmo_period = 9, unsigned int _ma_period = 14, unsigned int _vidya_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_VIDYA, 1) { + : IndicatorParams(INDI_VIDYA, 1, TYPE_DOUBLE) { applied_price = _ap; cmo_period = _cmo_period; ma_period = _ma_period; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\VIDYA"); shift = _shift; diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index 0d3a8d885..64454e927 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -31,10 +31,9 @@ struct VROCParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. void VROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_VROC, 1) { + : IndicatorParams(INDI_VROC, 1, TYPE_DOUBLE) { applied_volume = _applied_volume; period = _period; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\VROC"); shift = _shift; diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 1e3dabb27..7c297196c 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -30,9 +30,8 @@ struct VolumesParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. void VolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_VOLUMES, 2) { + : IndicatorParams(INDI_VOLUMES, 2, TYPE_DOUBLE) { applied_volume = _applied_volume; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Volumes"); SetDataSourceType(IDATA_BUILTIN); diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index 8cb6e3d2f..ec2c6400e 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -34,9 +34,9 @@ double iWPR(string _symbol, int _tf, int _period, int _shift) { struct WPRParams : IndicatorParams { unsigned int period; // Struct constructors. - void WPRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_WPR, 1) { + void WPRParams(unsigned int _period = 14, int _shift = 0) + : period(_period), IndicatorParams(INDI_WPR, 1, TYPE_DOUBLE) { shift = _shift; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\WPR"); }; diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index e014226f2..6791a82d9 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -28,8 +28,7 @@ // Structs. struct WilliamsADParams : IndicatorParams { // Struct constructor. - void WilliamsADParams(int _shift = 0) : IndicatorParams(INDI_WILLIAMS_AD, 1) { - SetDataValueType(TYPE_DOUBLE); + void WilliamsADParams(int _shift = 0) : IndicatorParams(INDI_WILLIAMS_AD, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\W_AD"); shift = _shift; diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index 066d53050..8c556c12a 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -38,10 +38,9 @@ struct ZigZagParams : IndicatorParams { : depth(_depth), deviation(_deviation), backstep(_backstep), - IndicatorParams(INDI_ZIGZAG, FINAL_ZIGZAG_LINE_ENTRY) { + IndicatorParams(INDI_ZIGZAG, FINAL_ZIGZAG_LINE_ENTRY, TYPE_DOUBLE) { shift = _shift; SetCustomIndicatorName("Examples\\ZigZag"); - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Draws lines between lowest and highest prices! }; }; diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index f41bfbdc0..97143ef32 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -33,11 +33,10 @@ struct ZigZagColorParams : IndicatorParams { // Struct constructor. void ZigZagColorParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) - : IndicatorParams(INDI_ZIGZAG_COLOR, 3) { + : IndicatorParams(INDI_ZIGZAG_COLOR, 3, TYPE_DOUBLE) { backstep = _backstep; depth = _depth; deviation = _deviation; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ZigZagColor"); SetDataSourceType(IDATA_ICUSTOM); diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 3d3fe8ad1..2936c5a73 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -43,12 +43,11 @@ struct MathParams : IndicatorParams { void MathParams(ENUM_MATH_OP _op = MATH_OP_SUB, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : IndicatorParams(INDI_SPECIAL_MATH, 1) { + : IndicatorParams(INDI_SPECIAL_MATH, 1, TYPE_DOUBLE) { mode_1 = _mode_1; mode_2 = _mode_2; op_builtin = _op; op_mode = MATH_OP_MODE_BUILTIN; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_INDICATOR); shift = _shift; @@ -61,13 +60,12 @@ struct MathParams : IndicatorParams { void MathParams(MathCustomOpFunction _op, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : IndicatorParams(INDI_SPECIAL_MATH) { + : IndicatorParams(INDI_SPECIAL_MATH, 1, TYPE_DOUBLE) { max_modes = 1; mode_1 = _mode_1; mode_2 = _mode_2; op_fn = _op; op_mode = MATH_OP_MODE_CUSTOM_FUNCTION; - SetDataValueType(TYPE_DOUBLE); SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_INDICATOR); shift = _shift; @@ -76,7 +74,8 @@ struct MathParams : IndicatorParams { tf = _tf; }; - void MathParams(MathParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { + void MathParams(MathParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : IndicatorParams(INDI_SPECIAL_MATH, 1, TYPE_DOUBLE) { this = _p; tf = _tf; }; From 106bc0d865fdd4366500e915d7f3756e282049a6 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 10 Oct 2021 23:25:23 +0100 Subject: [PATCH 63/78] Indicators: Code cleanup --- Indicator.mqh | 13 ++++++++++++- Indicator.struct.h | 2 ++ Indicators/Indi_ADX.mqh | 7 ------- Indicators/Indi_AMA.mqh | 8 -------- Indicators/Indi_DEMA.mqh | 8 -------- Indicators/Indi_Demo.mqh | 8 -------- 6 files changed, 14 insertions(+), 32 deletions(-) diff --git a/Indicator.mqh b/Indicator.mqh index 05860da5b..a582068fa 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -119,6 +119,17 @@ class Indicator : public IndicatorBase { bool Init() { ArrayResize(value_storages, iparams.GetMaxModes()); + switch (iparams.GetDataSourceType()) { + case IDATA_BUILTIN: + break; + case IDATA_ICUSTOM: + break; + case IDATA_INDICATOR: + if (indi_src == NULL) { + // SetDataSource(Indi_Price::GetCached(iparams.GetShift(), GetTf(), PRICE_TYPICAL, _period), true); + } + break; + } return InitDraw(); } @@ -502,7 +513,7 @@ class Indicator : public IndicatorBase { string GetDescriptiveName() { string name = iparams.name + " ("; - switch (iparams.idstype) { + switch (iparams.GetDataSourceType()) { case IDATA_BUILTIN: name += "built-in, "; break; diff --git a/Indicator.struct.h b/Indicator.struct.h index 5b9bdbd0c..215d57591 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -354,6 +354,7 @@ struct IndicatorDataEntry { /* Structure for indicator parameters. */ struct IndicatorParams { + public: // @todo: Change it to protected. string name; // Name of the indicator. int shift; // Shift (relative to the current bar, 0 - default). unsigned int max_buffers; // Max buffers to store. @@ -373,6 +374,7 @@ struct IndicatorParams { bool is_draw; // Draw active. int draw_window; // Drawing window. string custom_indi_name; // Name of the indicator passed to iCustom() method. + public: /* Special methods */ // Constructor. IndicatorParams(ENUM_INDICATOR_TYPE _itype = INDI_NONE, unsigned int _max_modes = 1, diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 68b09b248..008a1e741 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -49,13 +49,6 @@ struct ADXParams : IndicatorParams { SetCustomIndicatorName("Examples\\ADX"); } break; - case IDATA_INDICATOR: - /* @fixme - if (indi_src == NULL) { - SetDataSource(Indi_Price::GetCached(_shift, _tf, applied_price, _period)); - } - */ - break; } }; void ADXParams(ADXParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index 927e9ea9c..2a59d0331 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -51,14 +51,6 @@ struct IndiAMAParams : IndicatorParams { SetCustomIndicatorName("Examples\\AMA"); } break; - case IDATA_INDICATOR: - /* @fixme - if (indi_src == NULL) { - SetDataSource(Indi_Price::GetCached(_shift, _tf, _ap, _period), false); - SetDataSourceMode(0); - } - */ - break; } }; void IndiAMAParams(IndiAMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_AMA, 1) { diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 9b8f87619..e61f5fa69 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -52,14 +52,6 @@ struct DEMAParams : IndicatorParams { SetCustomIndicatorName("Examples\\DEMA"); } break; - case IDATA_INDICATOR: - /* @fixme - if (indi_src == NULL) { - SetDataSource(Indi_Price::GetCached(_shift, _tf, _ap, _period), false); - SetDataSourceMode(0); - } - */ - break; } }; void DEMAParams(DEMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index 7154b7f45..e52aa0465 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -42,14 +42,6 @@ struct DemoIndiParams : IndicatorParams { SetCustomIndicatorName("Examples\\Demo"); } break; - case IDATA_INDICATOR: - /* @fixme - if (indi_src == NULL) { - SetDataSource(Indi_Price::GetCached(_shift, _tf), false); - SetDataSourceMode(0); - } - */ - break; } }; void DemoIndiParams(DemoIndiParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_DEMO, 1) { From 1c432442ad9777dba222ec2143c9d5a074f1069c Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Tue, 12 Oct 2021 15:52:46 +0200 Subject: [PATCH 64/78] Should fix at least Ultimate Oscillator (problems in BarsCalculated() simulation). --- IndicatorBase.h | 13 ++++++++----- Indicators/Indi_UltimateOscillator.mqh | 8 +++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/IndicatorBase.h b/IndicatorBase.h index 7951c1675..b2ceab6b0 100644 --- a/IndicatorBase.h +++ b/IndicatorBase.h @@ -1172,11 +1172,9 @@ int BarsCalculated(IndicatorBase* _indi, int _bars_required, int _bars_at_least return _bars_required; } - if (_bars_at_least != -1) { - _bars_required = _bars_at_least; - } + int _bars_to_satisfy = (_bars_at_least != -1) ? _bars_at_least : _bars_required; - IndicatorDataEntry _entry = _indi.GetEntry(_bars_required - 1); + IndicatorDataEntry _entry = _indi.GetEntry(_bars_to_satisfy - 1); // GetEntry() could end up with an error. It is okay. ResetLastError(); @@ -1185,7 +1183,7 @@ int BarsCalculated(IndicatorBase* _indi, int _bars_required, int _bars_at_least if (!_entry.IsValid()) { // We don't have sufficient data. Counting how much data we have. - for (int i = 0; i < _bars_required; ++i) { + for (int i = 0; i < _bars_to_satisfy; ++i) { IndicatorDataEntry _check_entry = _indi.GetEntry(i); if (!_check_entry.IsValid()) { break; @@ -1196,5 +1194,10 @@ int BarsCalculated(IndicatorBase* _indi, int _bars_required, int _bars_at_least _valid_history_count = _bars_required; } + if (_bars_at_least != -1 && _valid_history_count >= _bars_at_least) { + // Faking BarsCalculated() that be have all the required bars. + return _bars_required; + } + return _valid_history_count; } diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 421b09425..e5457dba8 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -123,19 +123,21 @@ class Indi_UltimateOscillator : public Indicator { if (ExtMaxPeriod < InpMiddlePeriod) ExtMaxPeriod = InpMiddlePeriod; if (ExtMaxPeriod < InpFastPeriod) ExtMaxPeriod = InpFastPeriod; + int min_bars_required = MathMax(MathMax(InpFastPeriod, InpMiddlePeriod), InpSlowPeriod); + if (rates_total < ExtMaxPeriod) return (0); // Not all data may be calculated. - int calculated = BarsCalculated(ExtFastATRhandle, rates_total); + int calculated = BarsCalculated(ExtFastATRhandle, rates_total, min_bars_required); if (calculated < rates_total) { // Not all data of ExtFastATRhandle is calculated. return (0); } - calculated = BarsCalculated(ExtMiddleATRhandle, rates_total); + calculated = BarsCalculated(ExtMiddleATRhandle, rates_total, min_bars_required); if (calculated < rates_total) { // Not all data of ExtFastATRhandle is calculated. return (0); } - calculated = BarsCalculated(ExtSlowATRhandle, rates_total); + calculated = BarsCalculated(ExtSlowATRhandle, rates_total, min_bars_required); if (calculated < rates_total) { // Not all data of ExtFastATRhandle is calculated. return (0); From e4fdfd7ab47795c573be7de447f4145ac17d17b8 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 12 Oct 2021 22:47:24 +0100 Subject: [PATCH 65/78] Chart: Fixes timeframe bitwise defines --- Chart.define.h | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Chart.define.h b/Chart.define.h index f01ac1c3f..7f06e374a 100644 --- a/Chart.define.h +++ b/Chart.define.h @@ -28,27 +28,27 @@ /* Defines */ // Define type of timeframe periods using bitwise values. -#define M1B 1 << M1, // 1 minute -#define M2B 1 << M2, // 2 minutes (non-standard) -#define M3B 1 << M3, // 3 minutes (non-standard) -#define M4B 1 << M4, // 4 minutes (non-standard) -#define M5B 1 << M5, // 5 minutes -#define M6B 1 << M6, // 6 minutes (non-standard) -#define M10B 1 << M10, // 10 minutes (non-standard) -#define M12B 1 << M12, // 12 minutes (non-standard) -#define M15B 1 << M15, // 15 minutes -#define M20B 1 << M20, // 20 minutes (non-standard) -#define M30B 1 << M30, // 30 minutes -#define H1B 1 << H1, // 1 hour -#define H2B 1 << H2, // 2 hours (non-standard) -#define H3B 1 << H3, // 3 hours (non-standard) -#define H4B 1 << H4, // 4 hours -#define H6B 1 << H6, // 6 hours (non-standard) -#define H8B 1 << H8, // 8 hours (non-standard) -#define H12B 1 << H12, // 12 hours (non-standard) -#define D1B 1 << D1, // Daily -#define W1B 1 << W1, // Weekly -#define MN1B 1 << MN1, // Monthly +#define M1B (1 << M1) // 1 minute +#define M2B (1 << M2) // 2 minutes (non-standard) +#define M3B (1 << M3) // 3 minutes (non-standard) +#define M4B (1 << M4) // 4 minutes (non-standard) +#define M5B (1 << M5) // 5 minutes +#define M6B (1 << M6) // 6 minutes (non-standard) +#define M10B (1 << M10) // 10 minutes (non-standard) +#define M12B (1 << M12) // 12 minutes (non-standard) +#define M15B (1 << M15) // 15 minutes +#define M20B (1 << M20) // 20 minutes (non-standard) +#define M30B (1 << M30) // 30 minutes +#define H1B (1 << H1) // 1 hour +#define H2B (1 << H2) // 2 hours (non-standard) +#define H3B (1 << H3) // 3 hours (non-standard) +#define H4B (1 << H4) // 4 hours +#define H6B (1 << H6) // 6 hours (non-standard) +#define H8B (1 << H8) // 8 hours (non-standard) +#define H12B (1 << H12) // 12 hours (non-standard) +#define D1B (1 << D1) // Daily +#define W1B (1 << W1) // Weekly +#define MN1B (1 << MN1) // Monthly #ifndef __MQL4__ // Chart. From 4c11315e6175e07e64a92ad3d36cab8980f94c77 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 12 Oct 2021 23:34:24 +0100 Subject: [PATCH 66/78] Indicator: Adds IsValidEntry() --- Indicator.mqh | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Indicator.mqh b/Indicator.mqh index a582068fa..b5e786b7e 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -800,6 +800,26 @@ class Indicator : public IndicatorBase { */ virtual bool IsDataSourceModeSelectable() { return true; } + /** + * Checks if indicator entry is valid. + * + * @return + * Returns true if entry is valid (has valid values), otherwise false. + */ + virtual bool IsValidEntry(IndicatorDataEntry& _entry) { + bool _result = true; + _result &= !_entry.HasValue(NULL); + _result &= !_entry.HasValue(EMPTY_VALUE); + if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_DOUBLE)) { + _result &= !_entry.HasValue(DBL_MAX); + } else if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_FLOAT)) { + _result &= !_entry.HasValue(FLT_MAX); + } else if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_INT)) { + _result &= !_entry.HasValue(INT_MAX); + } + return _result; + } + /** * Update indicator. */ @@ -810,8 +830,13 @@ class Indicator : public IndicatorBase { /** * Returns the indicator's struct value. + * + * @see: IndicatorDataEntry. + * + * @return + * Returns IndicatorDataEntry struct filled with indicator values. */ - IndicatorDataEntry GetEntry(int _shift = 0) { + virtual IndicatorDataEntry GetEntry(int _shift = 0) { long _bar_time = GetBarTime(_shift); IndicatorDataEntry _entry = idata.GetByKey(_bar_time); if (!_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) { @@ -820,9 +845,7 @@ class Indicator : public IndicatorBase { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && - !_entry.HasValue(EMPTY_VALUE) && - !_entry.HasValue(DBL_MAX)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); From 481de6aaf00bef0ddeb364baf0d430a8ed8626f1 Mon Sep 17 00:00:00 2001 From: kenorb Date: Wed, 13 Oct 2021 00:15:15 +0100 Subject: [PATCH 67/78] Indicators: Adds IsValidEntry() to indicator files --- Indicators/Bitwise/Indi_Candle.mqh | 1 + Indicators/Indi_AC.mqh | 9 ++++++++- Indicators/Indi_AD.mqh | 9 ++++++++- Indicators/Indi_ADX.mqh | 10 ++++++++-- Indicators/Indi_ADXW.mqh | 9 ++++++++- Indicators/Indi_AMA.mqh | 9 ++++++++- Indicators/Indi_AO.mqh | 7 ++++++- Indicators/Indi_ASI.mqh | 9 ++++++++- Indicators/Indi_ATR.mqh | 9 ++++++++- Indicators/Indi_Alligator.mqh | 10 ++++++++-- Indicators/Indi_AppliedPrice.mqh | 9 ++++++++- Indicators/Indi_BWMFI.mqh | 9 ++++++++- Indicators/Indi_BWZT.mqh | 9 ++++++++- Indicators/Indi_Bands.mqh | 12 +++++++++--- Indicators/Indi_BearsPower.mqh | 9 ++++++++- Indicators/Indi_BullsPower.mqh | 9 ++++++++- Indicators/Indi_CCI.mqh | 9 ++++++++- Indicators/Indi_CHO.mqh | 9 ++++++++- Indicators/Indi_CHV.mqh | 9 ++++++++- Indicators/Indi_ColorBars.mqh | 9 ++++++++- Indicators/Indi_ColorCandlesDaily.mqh | 9 ++++++++- Indicators/Indi_ColorLine.mqh | 9 ++++++++- Indicators/Indi_CustomMovingAverage.mqh | 9 ++++++++- Indicators/Indi_DEMA.mqh | 9 ++++++++- Indicators/Indi_DeMarker.mqh | 9 ++++++++- Indicators/Indi_Demo.mqh | 2 +- Indicators/Indi_DetrendedPrice.mqh | 9 ++++++++- Indicators/Indi_Drawer.mqh | 1 - Indicators/Indi_Envelopes.mqh | 10 ++++++++-- Indicators/Indi_Force.mqh | 9 ++++++++- Indicators/Indi_FractalAdaptiveMA.mqh | 9 ++++++++- Indicators/Indi_Fractals.mqh | 20 ++++++++++++++------ Indicators/Indi_Gator.mqh | 12 +++++++++--- Indicators/Indi_HeikenAshi.mqh | 12 +++++++++--- Indicators/Indi_Ichimoku.mqh | 10 ++++++++-- Indicators/Indi_Killzones.mqh | 9 ++++++++- Indicators/Indi_MA.mqh | 11 ++++++++--- Indicators/Indi_MACD.mqh | 10 ++++++++-- Indicators/Indi_MFI.mqh | 9 ++++++++- Indicators/Indi_MassIndex.mqh | 9 ++++++++- Indicators/Indi_Momentum.mqh | 9 ++++++++- Indicators/Indi_OBV.mqh | 9 ++++++++- Indicators/Indi_OsMA.mqh | 9 ++++++++- Indicators/Indi_Pattern.mqh | 8 ++++++-- Indicators/Indi_Pivot.mqh | 8 ++++++-- Indicators/Indi_PriceChannel.mqh | 9 ++++++++- Indicators/Indi_PriceVolumeTrend.mqh | 9 ++++++++- Indicators/Indi_RS.mqh | 7 ++++++- Indicators/Indi_RSI.mqh | 9 ++++++++- Indicators/Indi_RVI.mqh | 9 ++++++++- Indicators/Indi_RateOfChange.mqh | 9 ++++++++- Indicators/Indi_SAR.mqh | 9 ++++++++- Indicators/Indi_StdDev.mqh | 9 ++++++++- Indicators/Indi_Stochastic.mqh | 10 ++++++++-- Indicators/Indi_TEMA.mqh | 9 ++++++++- Indicators/Indi_TRIX.mqh | 9 ++++++++- Indicators/Indi_UltimateOscillator.mqh | 9 ++++++++- Indicators/Indi_VIDYA.mqh | 9 ++++++++- Indicators/Indi_VROC.mqh | 9 ++++++++- Indicators/Indi_Volumes.mqh | 7 ++++++- Indicators/Indi_WPR.mqh | 9 ++++++++- Indicators/Indi_WilliamsAD.mqh | 9 ++++++++- Indicators/Indi_ZigZag.mqh | 7 ++++++- Indicators/Indi_ZigZagColor.mqh | 7 ++++++- Indicators/Special/Indi_Math.mqh | 9 ++++++++- 65 files changed, 493 insertions(+), 85 deletions(-) diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index 807d06731..ed5251be0 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -111,6 +111,7 @@ class Indi_Candle : public Indicator { _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, true); istate.is_ready = true; + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 289b4a306..f72074a6f 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -127,7 +127,7 @@ class Indi_AC : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -148,6 +148,13 @@ class Indi_AC : public Indicator { return _ptr; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /** * Returns the indicator's entry value. */ diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index b6ad900fb..0c28217b5 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -126,7 +126,7 @@ class Indi_AD : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -143,4 +143,11 @@ class Indi_AD : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } + + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } }; diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 008a1e741..813ec26de 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -150,8 +150,7 @@ class Indi_ADX : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = Indi_ADX::GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && - _entry.IsWithinRange(0.0, 100.0)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -169,6 +168,13 @@ class Indi_ADX : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsWithinRange(0.0, 100.0); + } + /* Getters */ /** diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index 6c07e48ac..3cb21ddb0 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -248,7 +248,7 @@ class Indi_ADXW : public Indicator { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_DOUBLE, true); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { idata.Add(_entry, _bar_time); } @@ -265,6 +265,13 @@ class Indi_ADXW : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index 2a59d0331..bb6e56702 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -238,7 +238,7 @@ class Indi_AMA : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -256,6 +256,13 @@ class Indi_AMA : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index 4022963ca..704a21f88 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -130,7 +130,7 @@ class Indi_AO : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.values[0].Get() != EMPTY_VALUE); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -151,6 +151,11 @@ class Indi_AO : public Indicator { return _ptr; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { return _entry.values[0].Get() != EMPTY_VALUE; } + /** * Returns the indicator's entry value. */ diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index d2861b4b8..2eb63b122 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -183,7 +183,7 @@ class Indi_ASI : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -201,6 +201,13 @@ class Indi_ASI : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index 06c5bfbe3..e37f123cc 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -132,7 +132,7 @@ class Indi_ATR : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -150,6 +150,13 @@ class Indi_ATR : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /** * Returns reusable indicator for a given parameters. */ diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index dba50437f..e5f95ea7a 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -203,8 +203,7 @@ class Indi_Alligator : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_ALLIGATOR_LINE)_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, - !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -226,6 +225,13 @@ class Indi_Alligator : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0); + } + /* Class getters */ /** diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index 6af51cc52..62a141fa3 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -103,7 +103,7 @@ class Indi_AppliedPrice : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -121,6 +121,13 @@ class Indi_AppliedPrice : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index fd500024a..da3a49958 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -174,7 +174,7 @@ class Indi_BWMFI : public Indicator { _histcolor = GetValue(BWMFI_HISTCOLOR, _shift); #endif _entry.values[BWMFI_HISTCOLOR] = _histcolor; - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.values[BWMFI_BUFFER] != 0 && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -191,4 +191,11 @@ class Indi_BWMFI : public Indicator { GetEntry(_shift).values[_mode].Get(_param.double_value); return _param; } + + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return _entry.values[BWMFI_BUFFER] != 0 && !_entry.HasValue(EMPTY_VALUE); + } }; diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index d27e80c79..e93c49931 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -187,7 +187,7 @@ class Indi_BWZT : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -204,4 +204,11 @@ class Indi_BWZT : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } + + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } }; diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 22377c084..36ccae4b9 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -274,9 +274,7 @@ class Indi_Bands : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_BANDS_LINE)_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, - !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0) && - _entry.values[BAND_LOWER].GetDbl() < _entry.values[BAND_UPPER].GetDbl()); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -295,6 +293,14 @@ class Indi_Bands : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0) && + _entry.values[BAND_LOWER].GetDbl() < _entry.values[BAND_UPPER].GetDbl(); + } + /** * Provides built-in indicators whose can be used as data source. */ diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index 6bf8d2ba5..57f671593 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -133,7 +133,7 @@ class Indi_BearsPower : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -151,6 +151,13 @@ class Indi_BearsPower : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index b1d49062f..6c32510ac 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -133,7 +133,7 @@ class Indi_BullsPower : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -151,6 +151,13 @@ class Indi_BullsPower : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index e9345101c..71f26b154 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -203,7 +203,7 @@ class Indi_CCI : public Indicator { } else { _entry.timestamp = GetBarTime(_shift); _entry.values[0] = GetValue(0); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -221,6 +221,13 @@ class Indi_CCI : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index b0706f88b..f260bacf0 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -196,7 +196,7 @@ class Indi_CHO : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -214,6 +214,13 @@ class Indi_CHO : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 3c960b261..57ac6d206 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -192,7 +192,7 @@ class Indi_CHV : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -210,6 +210,13 @@ class Indi_CHV : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 308f2ce7c..2974de566 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -140,7 +140,7 @@ class Indi_ColorBars : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -157,4 +157,11 @@ class Indi_ColorBars : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } + + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } }; diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index 4ba882667..ed10e212b 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -137,7 +137,7 @@ class Indi_ColorCandlesDaily : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -154,4 +154,11 @@ class Indi_ColorCandlesDaily : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } + + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } }; diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 9e023fd18..b7b2dffc9 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -200,7 +200,7 @@ class Indi_ColorLine : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -217,4 +217,11 @@ class Indi_ColorLine : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } + + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } }; diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index 254c11278..a52bcbc93 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -92,7 +92,7 @@ class Indi_CustomMovingAverage : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -110,6 +110,13 @@ class Indi_CustomMovingAverage : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry& _entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index e61f5fa69..473d022e4 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -210,7 +210,7 @@ class Indi_DEMA : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.IsGt(0) && _entry.IsLt(DBL_MAX)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -228,6 +228,13 @@ class Indi_DEMA : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return _entry.IsGt(0) && _entry.IsLt(DBL_MAX); + } + /* Getters */ /** diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index ff425e99b..e9fee1eeb 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -131,7 +131,7 @@ class Indi_DeMarker : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -149,6 +149,13 @@ class Indi_DeMarker : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index e52aa0465..f80aa770b 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -96,7 +96,7 @@ class Indi_Demo : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.AddFlags(INDI_ENTRY_FLAG_IS_VALID); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index a24bf3afb..6cb796ac1 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -145,7 +145,7 @@ class Indi_DetrendedPrice : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -163,6 +163,13 @@ class Indi_DetrendedPrice : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index fa7071062..fee405272 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -89,7 +89,6 @@ class Indi_Drawer : public Indicator { // Assuming that passed values are correct. entry.AddFlags(INDI_ENTRY_FLAG_IS_VALID); - idata.Add(entry, _args[0].integer_value); return true; } diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 24666cc91..dee23e517 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -235,8 +235,7 @@ class Indi_Envelopes : public Indicator { // The LINE_MAIN only exists in MQL4 for Envelopes. _entry.values[LINE_MAIN] = GetValue((ENUM_LO_UP_LINE)LINE_MAIN, _shift); #endif - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, - !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -258,6 +257,13 @@ class Indi_Envelopes : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0); + } + /* Getters */ /** diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index bc90228bd..b2125964f 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -148,7 +148,7 @@ class Indi_Force : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -166,6 +166,13 @@ class Indi_Force : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 6082a590c..e1d9bbfc0 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -163,7 +163,7 @@ class Indi_FrAMA : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -181,6 +181,13 @@ class Indi_FrAMA : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index b166b60eb..c0d970556 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -129,16 +129,11 @@ class Indi_Fractals : public Indicator { _entry.timestamp = GetBarTime(_shift); _entry.values[LINE_UPPER] = GetValue(LINE_UPPER, _shift); _entry.values[LINE_LOWER] = GetValue(LINE_LOWER, _shift); - double _wrong_value = (double)NULL; - ; #ifdef __MQL4__ // In MT4 line identifiers starts from 1, so populating also at 0. _entry.values[0] = _entry.values[LINE_UPPER]; - // In MT4, the empty value for iFractals is 0, not EMPTY_VALUE=DBL_MAX as in MT5. - // So the wrong value is the opposite. - _wrong_value = EMPTY_VALUE; #endif - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(_wrong_value)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -155,4 +150,17 @@ class Indi_Fractals : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } + + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + double _wrong_value = (double)NULL; +#ifdef __MQL4__ + // In MT4, the empty value for iFractals is 0, not EMPTY_VALUE=DBL_MAX as in MT5. + // So the wrong value is the opposite. + _wrong_value = EMPTY_VALUE; +#endif + return !_entry.HasValue(_wrong_value); + } }; diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index ba70d1cd8..af3c33ca7 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -214,9 +214,7 @@ class Indi_Gator : public Indicator { _entry.values[LINE_UPPER_HISTCOLOR] = GetValue(LINE_UPPER_HISTCOLOR, _shift); _entry.values[LINE_LOWER_HISTCOLOR] = GetValue(LINE_LOWER_HISTCOLOR, _shift); #endif - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, - !_entry.HasValue(EMPTY_VALUE) && (_entry.values[LINE_UPPER_HISTOGRAM].GetDbl() != 0 || - _entry.values[LINE_LOWER_HISTOGRAM].GetDbl() != 0)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -234,6 +232,14 @@ class Indi_Gator : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(EMPTY_VALUE) && + (_entry.values[LINE_UPPER_HISTOGRAM].GetDbl() != 0 || _entry.values[LINE_LOWER_HISTOGRAM].GetDbl() != 0); + } + /* Getters */ /** diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index db3bc7df3..1420f0aba 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -245,9 +245,7 @@ class Indi_HeikenAshi : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_HA_MODE)_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && - !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0) && - _entry.values[HA_LOW].GetDbl() < _entry.values[HA_HIGH].GetDbl()); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -264,4 +262,12 @@ class Indi_HeikenAshi : public Indicator { GetEntry(_shift).values[_mode].Get(_param.double_value); return _param; } + + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0) && + _entry.values[HA_LOW].GetDbl() < _entry.values[HA_HIGH].GetDbl(); + } }; diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index 14a624400..0d2821255 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -179,8 +179,7 @@ class Indi_Ichimoku : public Indicator { _entry.values[LINE_SENKOUSPANA] = GetValue(LINE_SENKOUSPANA, _shift); _entry.values[LINE_SENKOUSPANB] = GetValue(LINE_SENKOUSPANB, _shift); _entry.values[LINE_CHIKOUSPAN] = GetValue(LINE_CHIKOUSPAN, _shift + 26); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, - !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -198,6 +197,13 @@ class Indi_Ichimoku : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0); + } + /* Getters */ /** diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index d089ac009..1646bb538 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -150,7 +150,7 @@ class Indi_Killzones : public Indicator { float _value = GetValue(_mode, _shift); _entry.values[_mode] = IsValidValue(_value, _mode, _shift) ? _value : 0.0f; } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.IsGe(0) && !_entry.HasValue(FLT_MAX)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -173,6 +173,13 @@ class Indi_Killzones : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return _entry.IsGe(0) && !_entry.HasValue(FLT_MAX); + } + /* Getters */ /** diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index 4de0f69b1..cd05b0221 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -660,9 +660,7 @@ class Indi_MA : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && - !_entry.HasValue(EMPTY_VALUE) && - !_entry.HasValue(DBL_MAX)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -682,6 +680,13 @@ class Indi_MA : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && !_entry.HasValue(DBL_MAX); + } + /** * Returns reusable indicator. */ diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index 21c76f62f..7bac7dcfd 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -146,8 +146,7 @@ class Indi_MACD : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_SIGNAL_LINE)_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, - !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -165,6 +164,13 @@ class Indi_MACD : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0); + } + /* Getters */ /** diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index 2e4654549..c1a13ba4e 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -145,7 +145,7 @@ class Indi_MFI : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -163,6 +163,13 @@ class Indi_MFI : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index 1c404c1d7..ee782775e 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -182,7 +182,7 @@ class Indi_MassIndex : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -200,6 +200,13 @@ class Indi_MassIndex : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 8199a0df2..7ec4a3eea 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -180,7 +180,7 @@ class Indi_Momentum : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -198,6 +198,13 @@ class Indi_Momentum : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 1c283e7e2..48691e52e 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -152,7 +152,7 @@ class Indi_OBV : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -170,6 +170,13 @@ class Indi_OBV : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 38f29527b..cc54c6590 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -143,7 +143,7 @@ class Indi_OsMA : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -161,6 +161,13 @@ class Indi_OsMA : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index 415a6d8c5..d2abd7b0f 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -116,8 +116,7 @@ class Indi_Pattern : public Indicator { } _entry.SetFlag(INDI_ENTRY_FLAG_IS_BITWISE, true); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _ohlcs[0].IsValid() && _entry.values[1] > 0); - + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry) && _ohlcs[0].IsValid()); if (_entry.IsValid()) { istate.is_ready = true; _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); @@ -127,6 +126,11 @@ class Indi_Pattern : public Indicator { return _entry; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry& _entry) { return _entry.values[1] > 0; } + /** * Returns the indicator's entry value. */ diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index dbeb0677b..73b3f9b65 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -99,8 +99,7 @@ class Indi_Pivot : public Indicator { _entry.values[3].vflt, _entry.values[4].vflt, _entry.values[5].vflt, _entry.values[6].vflt, _entry.values[7].vflt, _entry.values[8].vflt); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, true); - + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -110,6 +109,11 @@ class Indi_Pivot : public Indicator { return _entry; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry& _entry) { return true; } + /** * Returns the indicator's entry value. */ diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index 92e6b1109..45fa40bf1 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -83,7 +83,7 @@ class Indi_PriceChannel : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -101,6 +101,13 @@ class Indi_PriceChannel : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry& _entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index 0e46ae7c9..b2bdd1220 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -150,7 +150,7 @@ class Indi_PriceVolumeTrend : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -168,6 +168,13 @@ class Indi_PriceVolumeTrend : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index 1de359a47..e4f45c2cc 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -104,7 +104,7 @@ class Indi_RS : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, true); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -122,6 +122,11 @@ class Indi_RS : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { return true; } + /* Getters */ /** diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index 763ff921a..64279b707 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -351,7 +351,7 @@ class Indi_RSI : public Indicator { _entry.values[_mode] = GetValue(_mode, _shift); } _entry.SetFlag(INDI_ENTRY_FLAG_IS_DOUBLE, iparams.GetDataValueType() == TYPE_DOUBLE); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -369,6 +369,13 @@ class Indi_RSI : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /** * Provides built-in indicators whose can be used as data source. */ diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index c1eebc8cf..42d1e45e1 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -133,7 +133,7 @@ class Indi_RVI : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_SIGNAL_LINE)_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -151,6 +151,13 @@ class Indi_RVI : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index 0c42cc126..183ed2c9f 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -139,7 +139,7 @@ class Indi_RateOfChange : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -157,6 +157,13 @@ class Indi_RateOfChange : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 279a10d33..30096efa8 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -132,7 +132,7 @@ class Indi_SAR : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -150,6 +150,13 @@ class Indi_SAR : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index dd02f4f97..e40aee27d 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -244,7 +244,7 @@ class Indi_StdDev : public Indicator { } else { _entry.timestamp = GetBarTime(_shift); _entry.values[0].Set(GetValue(_shift)); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -262,6 +262,13 @@ class Indi_StdDev : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 59159222e..525affda3 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -150,8 +150,7 @@ class Indi_Stochastic : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_SIGNAL_LINE)_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, - !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGe(0)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -169,6 +168,13 @@ class Indi_Stochastic : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGe(0); + } + /* Getters */ /** diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index 17415ef79..830b8c39b 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -154,7 +154,7 @@ class Indi_TEMA : public Indicator { } else { _entry.timestamp = GetBarTime(_shift); _entry.values[0] = GetValue(_shift); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -172,6 +172,13 @@ class Indi_TEMA : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index 9fa4436d0..c63699416 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -157,7 +157,7 @@ class Indi_TRIX : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -175,6 +175,13 @@ class Indi_TRIX : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index e5457dba8..9a0e7a714 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -242,7 +242,7 @@ class Indi_UltimateOscillator : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -260,6 +260,13 @@ class Indi_UltimateOscillator : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index ddcc33c7b..81b261308 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -180,7 +180,7 @@ class Indi_VIDYA : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -198,6 +198,13 @@ class Indi_VIDYA : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index 64454e927..076ad5c9f 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -160,7 +160,7 @@ class Indi_VROC : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -178,6 +178,13 @@ class Indi_VROC : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 7c297196c..bf5da34f9 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -154,7 +154,7 @@ class Indi_Volumes : public Indicator { double _v = GetValue(_mode, _shift); _entry.values[_mode] = _v; } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -172,6 +172,11 @@ class Indi_Volumes : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { return !_entry.HasValue(EMPTY_VALUE); } + /* Getters */ /** diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index ec2c6400e..ecd56613e 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -131,7 +131,7 @@ class Indi_WPR : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -149,6 +149,13 @@ class Indi_WPR : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE); + } + /* Getters */ /** diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index 6791a82d9..d026b5669 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -151,7 +151,7 @@ class Indi_WilliamsAD : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -168,4 +168,11 @@ class Indi_WilliamsAD : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } + + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } }; diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index 8c556c12a..a25b38f8c 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -366,7 +366,7 @@ class Indi_ZigZag : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue((ENUM_ZIGZAG_LINE)_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -384,6 +384,11 @@ class Indi_ZigZag : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { return !_entry.HasValue(EMPTY_VALUE); } + /* Getters */ /** diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 97143ef32..fc0646e5c 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -89,7 +89,7 @@ class Indi_ZigZagColor : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.values[0].Get() != EMPTY_VALUE); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -107,6 +107,11 @@ class Indi_ZigZagColor : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry& _entry) { return _entry.values[0].Get() != EMPTY_VALUE; } + /* Getters */ /** diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 2936c5a73..360e5e81e 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -146,7 +146,7 @@ class Indi_Math : public Indicator { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE)); + _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); @@ -164,6 +164,13 @@ class Indi_Math : public Indicator { return _param; } + /** + * Checks if indicator entry values are valid. + */ + virtual bool IsValidEntry(IndicatorDataEntry &_entry) { + return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); + } + static double iMathOnIndicator(IndicatorBase *_indi, string _symbol, ENUM_TIMEFRAMES _tf, ENUM_MATH_OP op, unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, unsigned int _shift_2, unsigned int _mode, int _shift, Indi_Math *_obj) { From b975ef968b9236cd279ce8bdafecc5a1cc4a39f7 Mon Sep 17 00:00:00 2001 From: kenorb Date: Wed, 13 Oct 2021 00:42:54 +0100 Subject: [PATCH 68/78] Indicator: Adds data type flag before the validation --- Indicator.mqh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Indicator.mqh b/Indicator.mqh index b5e786b7e..a22f72366 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -845,9 +845,9 @@ class Indicator : public IndicatorBase { for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { _entry.values[_mode] = GetValue(_mode, _shift); } + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } else { _entry.AddFlags(INDI_ENTRY_FLAG_INSUFFICIENT_DATA); From 24aeaa8bcf75a71215ef8e88721894f66aa03820 Mon Sep 17 00:00:00 2001 From: kenorb Date: Wed, 13 Oct 2021 00:45:18 +0100 Subject: [PATCH 69/78] Indicators: Removes GetEntry() and IsValidEntry() when not needed --- Indicators/Bitwise/Indi_Candle.mqh | 1 - Indicators/Indi_AC.mqh | 30 ------------------------ Indicators/Indi_AD.mqh | 30 ------------------------ Indicators/Indi_ADX.mqh | 25 +------------------- Indicators/Indi_ADXW.mqh | 30 ------------------------ Indicators/Indi_AMA.mqh | 30 ------------------------ Indicators/Indi_AO.mqh | 23 ------------------ Indicators/Indi_ASI.mqh | 30 ------------------------ Indicators/Indi_ATR.mqh | 30 ------------------------ Indicators/Indi_AppliedPrice.mqh | 30 ------------------------ Indicators/Indi_BWMFI.mqh | 9 +------ Indicators/Indi_BWZT.mqh | 30 ------------------------ Indicators/Indi_BearsPower.mqh | 30 ------------------------ Indicators/Indi_BullsPower.mqh | 30 ------------------------ Indicators/Indi_CCI.mqh | 28 ---------------------- Indicators/Indi_CHO.mqh | 30 ------------------------ Indicators/Indi_CHV.mqh | 30 ------------------------ Indicators/Indi_ColorBars.mqh | 30 ------------------------ Indicators/Indi_ColorCandlesDaily.mqh | 30 ------------------------ Indicators/Indi_ColorLine.mqh | 30 ------------------------ Indicators/Indi_CustomMovingAverage.mqh | 30 ------------------------ Indicators/Indi_DEMA.mqh | 2 +- Indicators/Indi_DeMarker.mqh | 30 ------------------------ Indicators/Indi_Demo.mqh | 23 ------------------ Indicators/Indi_DetrendedPrice.mqh | 30 ------------------------ Indicators/Indi_Envelopes.mqh | 2 +- Indicators/Indi_Force.mqh | 30 ------------------------ Indicators/Indi_FractalAdaptiveMA.mqh | 30 ------------------------ Indicators/Indi_Ichimoku.mqh | 2 +- Indicators/Indi_MA.mqh | 30 ------------------------ Indicators/Indi_MFI.mqh | 30 ------------------------ Indicators/Indi_MassIndex.mqh | 30 ------------------------ Indicators/Indi_Momentum.mqh | 30 ------------------------ Indicators/Indi_OBV.mqh | 30 ------------------------ Indicators/Indi_OsMA.mqh | 30 ------------------------ Indicators/Indi_Pivot.mqh | 2 +- Indicators/Indi_PriceChannel.mqh | 30 ------------------------ Indicators/Indi_PriceVolumeTrend.mqh | 30 ------------------------ Indicators/Indi_RS.mqh | 23 ------------------ Indicators/Indi_RSI.mqh | 31 ------------------------- Indicators/Indi_RateOfChange.mqh | 30 ------------------------ Indicators/Indi_SAR.mqh | 30 ------------------------ Indicators/Indi_StdDev.mqh | 28 ---------------------- Indicators/Indi_TRIX.mqh | 30 ------------------------ Indicators/Indi_UltimateOscillator.mqh | 30 ------------------------ Indicators/Indi_VIDYA.mqh | 30 ------------------------ Indicators/Indi_VROC.mqh | 30 ------------------------ Indicators/Indi_Volumes.mqh | 29 ----------------------- Indicators/Indi_WPR.mqh | 30 ------------------------ Indicators/Indi_WilliamsAD.mqh | 30 ------------------------ Indicators/Indi_ZigZagColor.mqh | 23 ------------------ Indicators/Special/Indi_Math.mqh | 30 ------------------------ 52 files changed, 6 insertions(+), 1355 deletions(-) diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index ed5251be0..807d06731 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -111,7 +111,6 @@ class Indi_Candle : public Indicator { _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, true); istate.is_ready = true; - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index f72074a6f..0012e1a78 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -113,29 +113,6 @@ class Indi_AC : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns reusable indicator for a given symbol and time-frame. */ @@ -148,13 +125,6 @@ class Indi_AC : public Indicator { return _ptr; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /** * Returns the indicator's entry value. */ diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index 0c28217b5..f75b3867c 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -112,29 +112,6 @@ class Indi_AD : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -143,11 +120,4 @@ class Indi_AD : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } - - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } }; diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 813ec26de..843d96ee3 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -136,29 +136,6 @@ class Indi_ADX : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = Indi_ADX::GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -172,7 +149,7 @@ class Indi_ADX : public Indicator { * Checks if indicator entry values are valid. */ virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsWithinRange(0.0, 100.0); + return Indicator::IsValidEntry(_entry) && _entry.IsWithinRange(0.0, 100.0); } /* Getters */ diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index 3cb21ddb0..669f7f1d3 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -233,29 +233,6 @@ class Indi_ADXW : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_DOUBLE, true); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -265,13 +242,6 @@ class Indi_ADXW : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index bb6e56702..a22630004 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -224,29 +224,6 @@ class Indi_AMA : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -256,13 +233,6 @@ class Indi_AMA : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index 704a21f88..18de319b6 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -116,29 +116,6 @@ class Indi_AO : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns reusable indicator for a given symbol and time-frame. */ diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index 2eb63b122..db5e47723 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -169,29 +169,6 @@ class Indi_ASI : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -201,13 +178,6 @@ class Indi_ASI : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index e37f123cc..9f836f697 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -118,29 +118,6 @@ class Indi_ATR : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -150,13 +127,6 @@ class Indi_ATR : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /** * Returns reusable indicator for a given parameters. */ diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index 62a141fa3..cd12b2c8f 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -89,29 +89,6 @@ class Indi_AppliedPrice : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -121,13 +98,6 @@ class Indi_AppliedPrice : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index da3a49958..c5d4c5bce 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -174,9 +174,9 @@ class Indi_BWMFI : public Indicator { _histcolor = GetValue(BWMFI_HISTCOLOR, _shift); #endif _entry.values[BWMFI_HISTCOLOR] = _histcolor; + _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); idata.Add(_entry, _bar_time); } } @@ -191,11 +191,4 @@ class Indi_BWMFI : public Indicator { GetEntry(_shift).values[_mode].Get(_param.double_value); return _param; } - - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return _entry.values[BWMFI_BUFFER] != 0 && !_entry.HasValue(EMPTY_VALUE); - } }; diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index e93c49931..93ec40625 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -173,29 +173,6 @@ class Indi_BWZT : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -204,11 +181,4 @@ class Indi_BWZT : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } - - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } }; diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index 57f671593..da9b08200 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -119,29 +119,6 @@ class Indi_BearsPower : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -151,13 +128,6 @@ class Indi_BearsPower : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index 6c32510ac..dc7fc3b59 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -119,29 +119,6 @@ class Indi_BullsPower : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -151,13 +128,6 @@ class Indi_BullsPower : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 71f26b154..49d258f2f 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -191,27 +191,6 @@ class Indi_CCI : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - _entry.values[0] = GetValue(0); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -221,13 +200,6 @@ class Indi_CCI : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index f260bacf0..1e2de52da 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -182,29 +182,6 @@ class Indi_CHO : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -214,13 +191,6 @@ class Indi_CHO : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 57ac6d206..3ced8ded3 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -178,29 +178,6 @@ class Indi_CHV : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -210,13 +187,6 @@ class Indi_CHV : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 2974de566..431dadb60 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -126,29 +126,6 @@ class Indi_ColorBars : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -157,11 +134,4 @@ class Indi_ColorBars : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } - - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } }; diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index ed10e212b..357894a89 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -123,29 +123,6 @@ class Indi_ColorCandlesDaily : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -154,11 +131,4 @@ class Indi_ColorCandlesDaily : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } - - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } }; diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index b7b2dffc9..58cc0c8b3 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -186,29 +186,6 @@ class Indi_ColorLine : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -217,11 +194,4 @@ class Indi_ColorLine : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } - - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } }; diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index a52bcbc93..ea7b67775 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -78,29 +78,6 @@ class Indi_CustomMovingAverage : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -110,13 +87,6 @@ class Indi_CustomMovingAverage : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry& _entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 473d022e4..3b8316f5e 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -232,7 +232,7 @@ class Indi_DEMA : public Indicator { * Checks if indicator entry values are valid. */ virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return _entry.IsGt(0) && _entry.IsLt(DBL_MAX); + return Indicator::IsValidEntry(_entry) && _entry.IsGt(0) && _entry.IsLt(DBL_MAX); } /* Getters */ diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index e9fee1eeb..1c3642122 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -117,29 +117,6 @@ class Indi_DeMarker : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -149,13 +126,6 @@ class Indi_DeMarker : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index f80aa770b..362c25233 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -82,29 +82,6 @@ class Indi_Demo : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 6cb796ac1..452662d44 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -131,29 +131,6 @@ class Indi_DetrendedPrice : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -163,13 +140,6 @@ class Indi_DetrendedPrice : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index dee23e517..7de6b923b 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -261,7 +261,7 @@ class Indi_Envelopes : public Indicator { * Checks if indicator entry values are valid. */ virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0); + return Indicator::IsValidEntry(_entry) && _entry.IsGt(0); } /* Getters */ diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index b2125964f..6a6be32f3 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -134,29 +134,6 @@ class Indi_Force : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -166,13 +143,6 @@ class Indi_Force : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index e1d9bbfc0..39c3f472a 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -149,29 +149,6 @@ class Indi_FrAMA : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -181,13 +158,6 @@ class Indi_FrAMA : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index 0d2821255..276ffb10d 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -201,7 +201,7 @@ class Indi_Ichimoku : public Indicator { * Checks if indicator entry values are valid. */ virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0); + return Indicator::IsValidEntry(_entry) && _entry.IsGt(0); } /* Getters */ diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index cd05b0221..f134e6cf0 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -648,29 +648,6 @@ class Indi_MA : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - IndicatorDataEntry _entry = idata.GetByKey(_bar_time); - if (!_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) { - _entry.Resize(iparams.GetMaxModes()); - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } else { - _entry.AddFlags(INDI_ENTRY_FLAG_INSUFFICIENT_DATA); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -680,13 +657,6 @@ class Indi_MA : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE) && !_entry.HasValue(DBL_MAX); - } - /** * Returns reusable indicator. */ diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index c1a13ba4e..132ebc9f3 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -131,29 +131,6 @@ class Indi_MFI : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -163,13 +140,6 @@ class Indi_MFI : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index ee782775e..0f9564234 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -168,29 +168,6 @@ class Indi_MassIndex : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -200,13 +177,6 @@ class Indi_MassIndex : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 7ec4a3eea..140770866 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -166,29 +166,6 @@ class Indi_Momentum : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -198,13 +175,6 @@ class Indi_Momentum : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 48691e52e..64718ec6c 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -138,29 +138,6 @@ class Indi_OBV : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -170,13 +147,6 @@ class Indi_OBV : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index cc54c6590..9e62b1c6b 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -129,29 +129,6 @@ class Indi_OsMA : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -161,13 +138,6 @@ class Indi_OsMA : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index 73b3f9b65..3b132da3e 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -112,7 +112,7 @@ class Indi_Pivot : public Indicator { /** * Checks if indicator entry values are valid. */ - virtual bool IsValidEntry(IndicatorDataEntry& _entry) { return true; } + virtual bool IsValidEntry(IndicatorDataEntry& _entry) { return true; } // @todo /** * Returns the indicator's entry value. diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index 45fa40bf1..7e82d4dc8 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -69,29 +69,6 @@ class Indi_PriceChannel : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -101,13 +78,6 @@ class Indi_PriceChannel : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry& _entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index b2bdd1220..767dd21e4 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -136,29 +136,6 @@ class Indi_PriceVolumeTrend : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -168,13 +145,6 @@ class Indi_PriceVolumeTrend : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index e4f45c2cc..43e23f0e7 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -90,29 +90,6 @@ class Indi_RS : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index 64279b707..2d9c3fd00 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -336,30 +336,6 @@ class Indi_RSI : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_DOUBLE, iparams.GetDataValueType() == TYPE_DOUBLE); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -369,13 +345,6 @@ class Indi_RSI : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /** * Provides built-in indicators whose can be used as data source. */ diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index 183ed2c9f..7995fe06e 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -125,29 +125,6 @@ class Indi_RateOfChange : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -157,13 +134,6 @@ class Indi_RateOfChange : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 30096efa8..f010d10e5 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -118,29 +118,6 @@ class Indi_SAR : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -150,13 +127,6 @@ class Indi_SAR : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index e40aee27d..d58f3fffb 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -232,27 +232,6 @@ class Indi_StdDev : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - _entry.values[0].Set(GetValue(_shift)); - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -262,13 +241,6 @@ class Indi_StdDev : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index c63699416..12b7ce742 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -143,29 +143,6 @@ class Indi_TRIX : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -175,13 +152,6 @@ class Indi_TRIX : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 9a0e7a714..45a26f73c 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -228,29 +228,6 @@ class Indi_UltimateOscillator : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -260,13 +237,6 @@ class Indi_UltimateOscillator : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index 81b261308..e4d744406 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -166,29 +166,6 @@ class Indi_VIDYA : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -198,13 +175,6 @@ class Indi_VIDYA : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index 076ad5c9f..55a9ed8ae 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -146,29 +146,6 @@ class Indi_VROC : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -178,13 +155,6 @@ class Indi_VROC : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index bf5da34f9..f4a9bced4 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -139,30 +139,6 @@ class Indi_Volumes : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - double _v = GetValue(_mode, _shift); - _entry.values[_mode] = _v; - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -172,11 +148,6 @@ class Indi_Volumes : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { return !_entry.HasValue(EMPTY_VALUE); } - /* Getters */ /** diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index ecd56613e..e2d831b88 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -117,29 +117,6 @@ class Indi_WPR : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -149,13 +126,6 @@ class Indi_WPR : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE); - } - /* Getters */ /** diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index d026b5669..0700df7d9 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -137,29 +137,6 @@ class Indi_WilliamsAD : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -168,11 +145,4 @@ class Indi_WilliamsAD : public Indicator { _param.double_value = GetEntry(_shift)[_mode]; return _param; } - - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } }; diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index fc0646e5c..6a87b6413 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -75,29 +75,6 @@ class Indi_ZigZagColor : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 360e5e81e..b4c3d6abd 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -132,29 +132,6 @@ class Indi_Math : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue(_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ @@ -164,13 +141,6 @@ class Indi_Math : public Indicator { return _param; } - /** - * Checks if indicator entry values are valid. - */ - virtual bool IsValidEntry(IndicatorDataEntry &_entry) { - return !_entry.HasValue(NULL) && !_entry.HasValue(EMPTY_VALUE); - } - static double iMathOnIndicator(IndicatorBase *_indi, string _symbol, ENUM_TIMEFRAMES _tf, ENUM_MATH_OP op, unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, unsigned int _shift_2, unsigned int _mode, int _shift, Indi_Math *_obj) { From 54f3684a7813bea9762f3a46f70fca381d4ea567 Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Thu, 14 Oct 2021 16:05:02 +0200 Subject: [PATCH 70/78] Fixes BarsCalculated() method and historic values retrieval (prices, volumes, spread). Also boost up Dicts' performance. --- Dict.enum.h | 34 +++++++++ Dict.mqh | 30 ++++++-- DictBase.mqh | 1 + DictIteratorBase.mqh | 19 +---- DictObject.mqh | 38 +++++++--- DictSlotsRef.h | 72 +++++++++++++++++++ DictStruct.mqh | 38 +++++++--- Indicator.define.h | 4 +- Indicator.mqh | 25 ------- IndicatorBase.h | 99 +++++++++----------------- Indicators/Indi_AC.mqh | 2 +- Indicators/Indi_AO.mqh | 2 +- Indicators/Indi_BWZT.mqh | 4 +- Indicators/Indi_ColorLine.mqh | 5 +- Indicators/Indi_RSI.mqh | 2 - Indicators/Indi_UltimateOscillator.mqh | 6 +- Storage/ValueStorage.history.h | 13 ++-- tests/IndicatorsTest.mq5 | 1 + 18 files changed, 241 insertions(+), 154 deletions(-) create mode 100644 Dict.enum.h create mode 100644 DictSlotsRef.h diff --git a/Dict.enum.h b/Dict.enum.h new file mode 100644 index 000000000..33887918c --- /dev/null +++ b/Dict.enum.h @@ -0,0 +1,34 @@ +//+------------------------------------------------------------------+ +//| 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 . + * + */ + +/** + * @file + * Includes Dicts's enums and defines. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#define DICT_GROW_UP_PERCENT_DEFAULT 25 +#define DICT_PERFORMANCE_PROBLEM_AVG_CONFLICTS 10 diff --git a/Dict.mqh b/Dict.mqh index 099002d7a..c5275b985 100644 --- a/Dict.mqh +++ b/Dict.mqh @@ -112,7 +112,7 @@ class Dict : public DictBase { * Inserts or replaces value for a given key. */ bool Set(K key, V value) { - if (!InsertInto(_DictSlots_ref, key, value)) return false; + if (!InsertInto(_DictSlots_ref, key, value, true)) return false; return true; } @@ -190,7 +190,14 @@ class Dict : public DictBase { /** * Inserts value into given array of DictSlots. */ - bool InsertInto(DictSlotsRef& dictSlotsRef, const K key, V value) { + bool InsertInto(DictSlotsRef& dictSlotsRef, const K key, V value, bool allow_resize) { + // Will resize dict if there were performance problems before. + if (allow_resize && !dictSlotsRef.IsPerformant()) { + if (!GrowUp()) { + return false; + } + } + if (_mode == DictModeUnknown) _mode = DictModeDict; else if (_mode != DictModeDict) { @@ -213,8 +220,8 @@ class Dict : public DictBase { } if (keySlot == NULL) { - // We need to expand array of DictSlotsRef.DictSlots (by 25%). - if (!Resize(MathMax(10, (int)((float)ArraySize(dictSlotsRef.DictSlots) * 1.25)))) return false; + // We need to expand array of DictSlotsRef.DictSlots (by 25% by default). + if (!GrowUp()) return false; } } @@ -254,6 +261,8 @@ class Dict : public DictBase { // Slot overwrite is not needed. Using empty slot. ++dictSlotsRef._num_used; } + + dictSlotsRef.AddConflicts(_num_conflicts); } dictSlotsRef.DictSlots[position].key = key; @@ -275,8 +284,8 @@ class Dict : public DictBase { } if (dictSlotsRef._num_used == ArraySize(dictSlotsRef.DictSlots)) { - // No DictSlotsRef.DictSlots available, we need to expand array of DictSlotsRef.DictSlots (by 25%). - if (!Resize(MathMax(10, (int)((float)ArraySize(dictSlotsRef.DictSlots) * 1.25)))) return false; + // No DictSlotsRef.DictSlots available, we need to expand array of DictSlotsRef.DictSlots. + if (!GrowUp()) return false; } unsigned int position = Hash((unsigned int)dictSlotsRef._list_index) % ArraySize(dictSlotsRef.DictSlots); @@ -295,6 +304,13 @@ class Dict : public DictBase { return true; } + /** + * Expands array of DictSlots by given percentage value. + */ + bool GrowUp(int percent = DICT_GROW_UP_PERCENT_DEFAULT) { + return Resize(MathMax(10, (int)((float)ArraySize(_DictSlots_ref.DictSlots) * ((float)(percent + 100) / 100.0f)))); + } + /** * Shrinks or expands array of DictSlots. */ @@ -321,7 +337,7 @@ class Dict : public DictBase { if (!_DictSlots_ref.DictSlots[i].IsUsed()) continue; if (_DictSlots_ref.DictSlots[i].HasKey()) { - if (!InsertInto(new_DictSlots, _DictSlots_ref.DictSlots[i].key, _DictSlots_ref.DictSlots[i].value)) + if (!InsertInto(new_DictSlots, _DictSlots_ref.DictSlots[i].key, _DictSlots_ref.DictSlots[i].value, false)) return false; } else { if (!InsertInto(new_DictSlots, _DictSlots_ref.DictSlots[i].value)) return false; diff --git a/DictBase.mqh b/DictBase.mqh index cde978864..534f91e8a 100644 --- a/DictBase.mqh +++ b/DictBase.mqh @@ -26,6 +26,7 @@ // Includes. #include "Convert.mqh" +#include "Dict.enum.h" #include "DictIteratorBase.mqh" #include "DictSlot.mqh" #include "Serializer.mqh" diff --git a/DictIteratorBase.mqh b/DictIteratorBase.mqh index ca72c86cc..16fafb8a8 100644 --- a/DictIteratorBase.mqh +++ b/DictIteratorBase.mqh @@ -26,6 +26,7 @@ #endif #include "DictBase.mqh" +#include "DictSlotsRef.h" #include "SerializerConversions.h" template @@ -137,21 +138,3 @@ class DictIteratorBase { _invalid_until_incremented |= invalid_until_incremented; } }; - -template -class DictSlot; - -template -struct DictSlotsRef { - DictSlot DictSlots[]; - - // Incremental index for dict operating in list mode. - int _list_index; - - int _num_used; - - DictSlotsRef() { - _list_index = 0; - _num_used = 0; - } -}; diff --git a/DictObject.mqh b/DictObject.mqh index 880ae132f..3585c1972 100644 --- a/DictObject.mqh +++ b/DictObject.mqh @@ -114,7 +114,7 @@ class DictObject : public DictBase { * Inserts or replaces value for a given key. */ bool Set(K key, V& value) { - if (!InsertInto(_DictSlots_ref, key, value)) return false; + if (!InsertInto(_DictSlots_ref, key, value, true)) return false; return true; } @@ -177,7 +177,14 @@ class DictObject : public DictBase { /** * Inserts value into given array of DictSlots. */ - bool InsertInto(DictSlotsRef& dictSlotsRef, const K key, V& value) { + bool InsertInto(DictSlotsRef& dictSlotsRef, const K key, V& value, bool allow_resize) { + // Will resize dict if there were performance problems before. + if (allow_resize && !dictSlotsRef.IsPerformant()) { + if (!GrowUp()) { + return false; + } + } + if (_mode == DictModeUnknown) _mode = DictModeDict; else if (_mode != DictModeDict) { @@ -200,8 +207,8 @@ class DictObject : public DictBase { } if (keySlot == NULL) { - // We need to expand array of DictSlotsRef.DictSlots (by 25%). - if (!Resize(MathMax(10, (int)((float)ArraySize(dictSlotsRef.DictSlots) * 1.25)))) return false; + // We need to expand array of DictSlotsRef.DictSlots. + if (!GrowUp()) return false; } } @@ -241,6 +248,8 @@ class DictObject : public DictBase { // Slot overwrite is not needed. Using empty slot. ++dictSlotsRef._num_used; } + + dictSlotsRef.AddConflicts(_num_conflicts); } dictSlotsRef.DictSlots[position].key = key; @@ -262,8 +271,8 @@ class DictObject : public DictBase { } if (dictSlotsRef._num_used == ArraySize(dictSlotsRef.DictSlots)) { - // No DictSlotsRef.DictSlots available, we need to expand array of DictSlotsRef.DictSlots (by 25%). - if (!Resize(MathMax(10, (int)((float)ArraySize(dictSlotsRef.DictSlots) * 1.25)))) return false; + // No DictSlotsRef.DictSlots available, we need to expand array of DictSlotsRef.DictSlots. + if (!GrowUp()) return false; } unsigned int position = Hash((unsigned int)dictSlotsRef._list_index) % ArraySize(dictSlotsRef.DictSlots); @@ -282,6 +291,13 @@ class DictObject : public DictBase { return true; } + /** + * Expands array of DictSlots by given percentage value. + */ + bool GrowUp(int percent = DICT_GROW_UP_PERCENT_DEFAULT) { + return Resize(MathMax(10, (int)((float)ArraySize(_DictSlots_ref.DictSlots) * ((float)(percent + 100) / 100.0f)))); + } + /** * Shrinks or expands array of DictSlots. */ @@ -293,14 +309,20 @@ class DictObject : public DictBase { DictSlotsRef new_DictSlots; + int i; + if (ArrayResize(new_DictSlots.DictSlots, new_size) == -1) return false; + for (i = 0; i < new_size; ++i) { + new_DictSlots.DictSlots[i].SetFlags(0); + } + // Copies entire array of DictSlots into new array of DictSlots. Hashes will be rehashed. - for (unsigned int i = 0; i < (unsigned int)ArraySize(_DictSlots_ref.DictSlots); ++i) { + for (i = 0; i < ArraySize(_DictSlots_ref.DictSlots); ++i) { if (!_DictSlots_ref.DictSlots[i].IsUsed()) continue; if (_DictSlots_ref.DictSlots[i].HasKey()) { - if (!InsertInto(new_DictSlots, _DictSlots_ref.DictSlots[i].key, _DictSlots_ref.DictSlots[i].value)) + if (!InsertInto(new_DictSlots, _DictSlots_ref.DictSlots[i].key, _DictSlots_ref.DictSlots[i].value, false)) return false; } else { if (!InsertInto(new_DictSlots, _DictSlots_ref.DictSlots[i].value)) return false; diff --git a/DictSlotsRef.h b/DictSlotsRef.h new file mode 100644 index 000000000..140140c49 --- /dev/null +++ b/DictSlotsRef.h @@ -0,0 +1,72 @@ +//+------------------------------------------------------------------+ +//| 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 . + * + */ + +/** + * @file + * DictSlotsRef struct. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Includes. +#include "Dict.enum.h" + +template +class DictSlot; + +template +struct DictSlotsRef { + DictSlot DictSlots[]; + + // Incremental index for dict operating in list mode. + int _list_index; + + int _num_used; + + int _num_conflicts; + + float _avg_conflicts; + + DictSlotsRef() { + _list_index = 0; + _num_used = 0; + _num_conflicts = 0; + _avg_conflicts = 0; + } + + /** + * Adds given number of conflicts for an insert action, so we can store average number of conflicts. + */ + void AddConflicts(int num) { + if (num != 0) { + _avg_conflicts += float(num) / ++_num_conflicts; + } + } + + /** + * Checks whethere there is no performance problems with slots. + */ + bool IsPerformant() { return _avg_conflicts < DICT_PERFORMANCE_PROBLEM_AVG_CONFLICTS; } +}; diff --git a/DictStruct.mqh b/DictStruct.mqh index d55c5051e..f9d33c15d 100644 --- a/DictStruct.mqh +++ b/DictStruct.mqh @@ -126,7 +126,7 @@ class DictStruct : public DictBase { * Inserts or replaces value for a given key. */ bool Set(K key, V& value) { - if (!InsertInto(_DictSlots_ref, key, value)) return false; + if (!InsertInto(_DictSlots_ref, key, value, true)) return false; return true; } @@ -220,7 +220,14 @@ class DictStruct : public DictBase { /** * Inserts value into given array of DictSlots. */ - bool InsertInto(DictSlotsRef& dictSlotsRef, const K key, V& value) { + bool InsertInto(DictSlotsRef& dictSlotsRef, const K key, V& value, bool allow_resize) { + // Will resize dict if there were performance problems before. + if (allow_resize && !dictSlotsRef.IsPerformant()) { + if (!GrowUp()) { + return false; + } + } + if (_mode == DictModeUnknown) _mode = DictModeDict; else if (_mode != DictModeDict) { @@ -242,8 +249,8 @@ class DictStruct : public DictBase { } if (keySlot == NULL) { - // We need to expand array of DictSlotsRef.DictSlots (by 25%). - if (!Resize(MathMax(10, (int)((float)ArraySize(dictSlotsRef.DictSlots) * 1.25)))) return false; + // We need to expand array of DictSlotsRef.DictSlots. + if (!GrowUp()) return false; } } @@ -283,6 +290,8 @@ class DictStruct : public DictBase { // Slot overwrite is not needed. Using empty slot. ++dictSlotsRef._num_used; } + + dictSlotsRef.AddConflicts(_num_conflicts); } dictSlotsRef.DictSlots[position].key = key; @@ -303,8 +312,8 @@ class DictStruct : public DictBase { } if (dictSlotsRef._num_used == ArraySize(dictSlotsRef.DictSlots)) { - // No DictSlotsRef.DictSlots available, we need to expand array of DictSlotsRef.DictSlots (by 25%). - if (!Resize(MathMax(10, (int)((float)ArraySize(dictSlotsRef.DictSlots) * 1.25)))) return false; + // No DictSlotsRef.DictSlots available, we need to expand array of DictSlotsRef.DictSlots. + if (!GrowUp()) return false; } unsigned int position = Hash((unsigned int)dictSlotsRef._list_index) % ArraySize(dictSlotsRef.DictSlots); @@ -323,6 +332,13 @@ class DictStruct : public DictBase { return true; } + /** + * Expands array of DictSlots by given percentage value. + */ + bool GrowUp(int percent = DICT_GROW_UP_PERCENT_DEFAULT) { + return Resize(MathMax(10, (int)((float)ArraySize(_DictSlots_ref.DictSlots) * ((float)(percent + 100) / 100.0f)))); + } + /** * Shrinks or expands array of DictSlots. */ @@ -336,12 +352,18 @@ class DictStruct : public DictBase { if (ArrayResize(new_DictSlots.DictSlots, new_size) == -1) return false; + int i; + + for (i = 0; i < new_size; ++i) { + new_DictSlots.DictSlots[i].SetFlags(0); + } + // Copies entire array of DictSlots into new array of DictSlots. Hashes will be rehashed. - for (unsigned int i = 0; i < (unsigned int)ArraySize(_DictSlots_ref.DictSlots); ++i) { + for (i = 0; i < ArraySize(_DictSlots_ref.DictSlots); ++i) { if (!_DictSlots_ref.DictSlots[i].IsUsed()) continue; if (_DictSlots_ref.DictSlots[i].HasKey()) { - if (!InsertInto(new_DictSlots, _DictSlots_ref.DictSlots[i].key, _DictSlots_ref.DictSlots[i].value)) + if (!InsertInto(new_DictSlots, _DictSlots_ref.DictSlots[i].key, _DictSlots_ref.DictSlots[i].value, false)) return false; } else { if (!InsertInto(new_DictSlots, _DictSlots_ref.DictSlots[i].value)) return false; diff --git a/Indicator.define.h b/Indicator.define.h index 40e0d811c..08c221d64 100644 --- a/Indicator.define.h +++ b/Indicator.define.h @@ -41,14 +41,14 @@ return EMPTY_VALUE; \ } \ } \ - int _bars_calc = BarsCalculated(_handle); \ + int _bars_calc = ::BarsCalculated(_handle); \ if (GetLastError() > 0) { \ return EMPTY_VALUE; \ } else if (_bars_calc <= 2) { \ SetUserError(ERR_USER_INVALID_BUFF_NUM); \ return EMPTY_VALUE; \ } \ - if (CopyBuffer(_handle, _mode, _shift, 1, _res) < 0) { \ + if (::CopyBuffer(_handle, _mode, _shift, 1, _res) < 0) { \ return EMPTY_VALUE; \ } \ return _res[0]; diff --git a/Indicator.mqh b/Indicator.mqh index a22f72366..3897e2929 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -748,31 +748,6 @@ class Indicator : public IndicatorBase { return true; } - /** - * Feed history entries. - */ - void FeedHistoryEntries(int period, int shift = 0) { - if (is_feeding || is_fed) { - // Avoiding forever loop. - return; - } - - is_feeding = true; - - for (int i = shift + period; i > shift; --i) { - if (ChartStatic::iPrice(PRICE_OPEN, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), i) <= - 0) { - // No data for that entry - continue; - } - - GetEntry(i); - } - - is_feeding = false; - is_fed = true; - } - ENUM_IDATA_VALUE_RANGE GetIDataValueRange() { return iparams.idvrange; } virtual void OnTick() { diff --git a/IndicatorBase.h b/IndicatorBase.h index b2ceab6b0..6eb088215 100644 --- a/IndicatorBase.h +++ b/IndicatorBase.h @@ -75,8 +75,8 @@ class IndicatorBase : public Chart { DrawIndicator* draw; IndicatorState istate; void* mydata; - bool is_feeding; // Whether FeedHistoryEntries is already working. - bool is_fed; // Whether FeedHistoryEntries already done its job. + bool is_fed; // Whether calc_start_bar is already calculated. + int calc_start_bar; // Index of the first valid bar (from 0). DictStruct> indicators; // Indicators list keyed by id. bool indicator_builtin; ARRAY(ValueStorage*, value_storages); @@ -102,18 +102,18 @@ class IndicatorBase : public Chart { /** * Class constructor. */ - IndicatorBase() : indi_src(NULL) { is_feeding = is_fed = false; } + IndicatorBase() : indi_src(NULL) { is_fed = false; } /** * Class constructor. */ - IndicatorBase(ChartParams& _cparams) : indi_src(NULL), Chart(_cparams) { is_feeding = is_fed = false; } + IndicatorBase(ChartParams& _cparams) : indi_src(NULL), Chart(_cparams) { is_fed = false; } /** * Class constructor. */ IndicatorBase(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL) : Chart(_tf, _symbol) { - is_feeding = is_fed = false; + is_fed = false; indi_src = NULL; } @@ -121,7 +121,7 @@ class IndicatorBase : public Chart { * Class constructor. */ IndicatorBase(ENUM_TIMEFRAMES_INDEX _tfi, string _symbol = NULL) : Chart(_tfi, _symbol) { - is_feeding = is_fed = false; + is_fed = false; indi_src = NULL; } @@ -965,31 +965,6 @@ class IndicatorBase : public Chart { return true; } - /** - * Feed history entries. - */ - void FeedHistoryEntries(int period, int shift = 0) { - if (is_feeding || is_fed) { - // Avoiding forever loop. - return; - } - - is_feeding = true; - - for (int i = shift + period; i > shift; --i) { - if (ChartStatic::iPrice(PRICE_OPEN, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), i) <= - 0) { - // No data for that entry - continue; - } - - GetEntry(i); - } - - is_feeding = false; - is_fed = true; - } - virtual ENUM_IDATA_VALUE_RANGE GetIDataValueRange() = 0; ValueStorage* GetValueStorage(int _mode = 0) { @@ -1129,6 +1104,31 @@ class IndicatorBase : public Chart { SerializerConverter::MakeStubObject(_serializer_flags, _entry.GetSize()); return SerializerConverter::FromObject(_entry, _serializer_flags).ToString(0, &_stub_indi); } + + int GetBarsCalculated() { + int _bars = Bars(GetSymbol(), GetTf()); + + if (!is_fed) { + calc_start_bar = 0; + + // Calculating start_bar. + for (int i = 0; i < _bars; ++i) { + // Iterating from the oldest. + IndicatorDataEntry _entry = GetEntry(_bars - i - 1); + + if (_entry.IsValid()) { + // From this point we assume that future entries will be all valid. + calc_start_bar = i; + is_fed = true; + + return _bars - calc_start_bar; + } + } + } + + // Assuming all entries are calculated (even if have invalid values). + return _bars; + } }; /** @@ -1165,39 +1165,6 @@ int CopyBuffer(IndicatorBase* _indi, int _mode, int _start, int _count, ValueSto } /** - * BarsCalculated() method to be used on Indicator instance. + * BarsCalculated()-compatible method to be used on Indicator instance. */ -int BarsCalculated(IndicatorBase* _indi, int _bars_required, int _bars_at_least = -1) { - if (_bars_required == 0) { - return _bars_required; - } - - int _bars_to_satisfy = (_bars_at_least != -1) ? _bars_at_least : _bars_required; - - IndicatorDataEntry _entry = _indi.GetEntry(_bars_to_satisfy - 1); - // GetEntry() could end up with an error. It is okay. - ResetLastError(); - - int _valid_history_count = 0; - - if (!_entry.IsValid()) { - // We don't have sufficient data. Counting how much data we have. - - for (int i = 0; i < _bars_to_satisfy; ++i) { - IndicatorDataEntry _check_entry = _indi.GetEntry(i); - if (!_check_entry.IsValid()) { - break; - } - ++_valid_history_count; - } - } else { - _valid_history_count = _bars_required; - } - - if (_bars_at_least != -1 && _valid_history_count >= _bars_at_least) { - // Faking BarsCalculated() that be have all the required bars. - return _bars_required; - } - - return _valid_history_count; -} +int BarsCalculated(IndicatorBase* _indi) { return _indi.GetBarsCalculated(); } diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 0012e1a78..2e0c14996 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -76,7 +76,7 @@ class Indi_AC : public Indicator { if (Terminal::IsVisualMode()) { // To avoid error 4806 (ERR_INDICATOR_DATA_NOT_FOUND), // we check the number of calculated data only in visual mode. - int _bars_calc = BarsCalculated(_handle); + int _bars_calc = ::BarsCalculated(_handle); if (GetLastError() > 0) { return EMPTY_VALUE; } else if (_bars_calc <= 2) { diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index 18de319b6..ecd52ef25 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -79,7 +79,7 @@ class Indi_AO : public Indicator { if (Terminal::IsVisualMode()) { // To avoid error 4806 (ERR_INDICATOR_DATA_NOT_FOUND), // we check the number of calculated data only in visual mode. - int _bars_calc = BarsCalculated(_handle); + int _bars_calc = ::BarsCalculated(_handle); if (GetLastError() > 0) { return EMPTY_VALUE; } else if (_bars_calc <= 2) { diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 93ec40625..6a171b97b 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -97,12 +97,12 @@ class Indi_BWZT : public Indicator { IndicatorBase *ExtACHandle, IndicatorBase *ExtAOHandle) { if (rates_total < DATA_LIMIT) return (0); // Not all data may be calculated. - int calculated = BarsCalculated(ExtACHandle, rates_total); + int calculated = BarsCalculated(ExtACHandle); if (calculated < rates_total) { // Not all data of ExtACHandle is calculated. return (0); } - calculated = BarsCalculated(ExtAOHandle, rates_total); + calculated = BarsCalculated(ExtAOHandle); if (calculated < rates_total) { // Not all data of ExtAOHandle is calculated. return (0); diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 58cc0c8b3..7fb5d94b1 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -88,11 +88,10 @@ class Indi_ColorLine : public Indicator { ValueStorage &ExtColorsBuffer, IndicatorBase *ExtMAHandle) { static int ticks = 0, modified = 0; // Check data. - int i, calculated = BarsCalculated(ExtMAHandle, rates_total); + int i, calculated = BarsCalculated(ExtMAHandle); // @added History of 100 values should be enough for MA. - if (calculated < rates_total && calculated < 100) { + if (calculated < rates_total) { // Not all data of ExtMAHandle is calculated. - Print("Not all MA data calculate for ColorLine! Expected ", rates_total, ", got only ", calculated); return (0); } // First calculation or number of bars was changed. diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index 2d9c3fd00..d99922b06 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -184,8 +184,6 @@ class Indi_RSI : public Indicator { // Return empty value on invalid bar time. return EMPTY_VALUE; } - // Looks like MT uses specified period as start of the SMMA calculations. - _obj.FeedHistoryEntries(_period); int i; double indi_values[]; diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 45a26f73c..576878bac 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -127,17 +127,17 @@ class Indi_UltimateOscillator : public Indicator { if (rates_total < ExtMaxPeriod) return (0); // Not all data may be calculated. - int calculated = BarsCalculated(ExtFastATRhandle, rates_total, min_bars_required); + int calculated = BarsCalculated(ExtFastATRhandle); if (calculated < rates_total) { // Not all data of ExtFastATRhandle is calculated. return (0); } - calculated = BarsCalculated(ExtMiddleATRhandle, rates_total, min_bars_required); + calculated = BarsCalculated(ExtMiddleATRhandle); if (calculated < rates_total) { // Not all data of ExtFastATRhandle is calculated. return (0); } - calculated = BarsCalculated(ExtSlowATRhandle, rates_total, min_bars_required); + calculated = BarsCalculated(ExtSlowATRhandle); if (calculated < rates_total) { // Not all data of ExtFastATRhandle is calculated. return (0); diff --git a/Storage/ValueStorage.history.h b/Storage/ValueStorage.history.h index 9babdf989..98f90b93f 100644 --- a/Storage/ValueStorage.history.h +++ b/Storage/ValueStorage.history.h @@ -61,7 +61,7 @@ class HistoryValueStorage : public ValueStorage { */ HistoryValueStorage(string _symbol, ENUM_TIMEFRAMES _tf, bool _is_series = false) : symbol(_symbol), tf(_tf), is_series(_is_series) { - start_bar_time = ChartStatic::iTime(_symbol, _tf, INDICATOR_BUFFER_VALUE_STORAGE_HISTORY - 1); + start_bar_time = ChartStatic::iTime(_symbol, _tf, BarsFromStart() - 1); } /** @@ -79,22 +79,19 @@ class HistoryValueStorage : public ValueStorage { if (is_series) { return _shift; } else { - int _bars_from_start = BarsFromStart(); - return _bars_from_start - _shift; + return BarsFromStart() - _shift - 1; } } /** - * Number of bars passed from the start. + * Number of bars passed from the start. There will be a single bar at the start. */ - int BarsFromStart() const { - return (int)((ChartStatic::iTime(symbol, tf, 0) - start_bar_time) / (long)PeriodSeconds(tf)); - } + int BarsFromStart() const { return Bars(symbol, tf); } /** * Returns number of values available to fetch (size of the values buffer). */ - virtual int Size() const { return BarsFromStart() + 1; } + virtual int Size() const { return BarsFromStart(); } /** * Resizes storage to given size. diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index 0a7788476..c648ff30d 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -124,6 +124,7 @@ int OnInit() { bool _result = true; // Initialize chart. chart = new Chart(); + Print("We have ", Bars(NULL, 0), " bars to analyze"); // Initialize indicators. _result &= InitIndicators(); Print("Indicators to test: ", indis.Size()); From 10970006906c2e5c9f75388763f619be788c0b3f Mon Sep 17 00:00:00 2001 From: kenorb Date: Thu, 14 Oct 2021 22:39:49 +0100 Subject: [PATCH 71/78] Indicator: Moves min/max methods from base to main class --- Indicator.mqh | 127 ++++++++++++++++++++++++++++++++++++++++++- Indicator.struct.h | 2 +- IndicatorBase.h | 131 ++------------------------------------------- 3 files changed, 129 insertions(+), 131 deletions(-) diff --git a/Indicator.mqh b/Indicator.mqh index 3897e2929..9a5c7659d 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -412,6 +412,131 @@ class Indicator : public IndicatorBase { /* Getters */ + /** + * Returns the highest bar's index (shift). + */ + template + int GetHighest(int count = WHOLE_ARRAY, int start_bar = 0) { + int max_idx = -1; + double max = -DBL_MAX; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value = GetEntry(shift).GetMax(GetModeCount()); + if (value > max) { + max = value; + max_idx = shift; + } + } + + return max_idx; + } + + /** + * Returns the lowest bar's index (shift). + */ + template + int GetLowest(int count = WHOLE_ARRAY, int start_bar = 0) { + int min_idx = -1; + double min = DBL_MAX; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value = GetEntry(shift).GetMin(GetModeCount()); + if (value < min) { + min = value; + min_idx = shift; + } + } + + return min_idx; + } + + /** + * Returns the highest value. + */ + template + double GetMax(int start_bar = 0, int count = WHOLE_ARRAY) { + double max = NULL; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value = GetEntry(shift).GetMax(iparams.GetMaxModes()); + if (max == NULL || value > max) { + max = value; + } + } + + return max; + } + + /** + * Returns the lowest value. + */ + template + double GetMin(int start_bar, int count = WHOLE_ARRAY) { + double min = NULL; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value = GetEntry(shift).GetMin(iparams.GetMaxModes()); + if (min == NULL || value < min) { + min = value; + } + } + + return min; + } + + /** + * Returns average value. + */ + template + double GetAvg(int start_bar, int count = WHOLE_ARRAY) { + int num_values = 0; + double sum = 0; + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + double value_min = GetEntry(shift).GetMin(iparams.GetMaxModes()); + double value_max = GetEntry(shift).GetMax(iparams.GetMaxModes()); + + sum += value_min + value_max; + num_values += 2; + } + + return sum / num_values; + } + + /** + * Returns median of values. + */ + template + double GetMed(int start_bar, int count = WHOLE_ARRAY) { + double array[]; + + int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + int num_bars = last_bar - start_bar + 1; + int index = 0; + + ArrayResize(array, num_bars); + + for (int shift = start_bar; shift <= last_bar; ++shift) { + array[index++] = GetEntry(shift).GetAvg(iparams.GetMaxModes()); + } + + ArraySort(array); + double median; + int len = ArraySize(array); + if (len % 2 == 0) { + median = (array[len / 2] + array[(len / 2) - 1]) / 2; + } else { + median = array[len / 2]; + } + + return median; + } + /** * Returns currently selected data source doing validation. */ @@ -454,8 +579,6 @@ class Indicator : public IndicatorBase { */ virtual bool HasDataSource() { return GetDataSourceRaw() != NULL || iparams.GetDataSourceId() != -1; } - /* State methods */ - /** * Gets indicator's params. */ diff --git a/Indicator.struct.h b/Indicator.struct.h index 215d57591..d9d98a3fd 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -354,7 +354,7 @@ struct IndicatorDataEntry { /* Structure for indicator parameters. */ struct IndicatorParams { - public: // @todo: Change it to protected. + public: // @todo: Change it to protected. string name; // Name of the indicator. int shift; // Shift (relative to the current bar, 0 - default). unsigned int max_buffers; // Max buffers to store. diff --git a/IndicatorBase.h b/IndicatorBase.h index 6eb088215..eed35dcdb 100644 --- a/IndicatorBase.h +++ b/IndicatorBase.h @@ -566,142 +566,17 @@ class IndicatorBase : public Chart { /* Getters */ - /** - * Returns currently selected data source doing validation. - */ - virtual IndicatorBase* GetDataSource() { return NULL; } - - int GetDataSourceMode() { return indi_src_mode; } - /** * Whether data source is selected. */ virtual bool HasDataSource() { return false; } /** - * Returns the highest bar's index (shift). - */ - template - int GetHighest(int count = WHOLE_ARRAY, int start_bar = 0) { - int max_idx = -1; - double max = -DBL_MAX; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMax(GetModeCount()); - if (value > max) { - max = value; - max_idx = shift; - } - } - - return max_idx; - } - - /** - * Returns the lowest bar's index (shift). - */ - template - int GetLowest(int count = WHOLE_ARRAY, int start_bar = 0) { - int min_idx = -1; - double min = DBL_MAX; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMin(GetModeCount()); - if (value < min) { - min = value; - min_idx = shift; - } - } - - return min_idx; - } - - /** - * Returns the highest value. - */ - template - double GetMax(int start_bar = 0, int count = WHOLE_ARRAY) { - double max = NULL; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMax(iparams.max_modes); - if (max == NULL || value > max) { - max = value; - } - } - - return max; - } - - /** - * Returns the lowest value. - */ - template - double GetMin(int start_bar, int count = WHOLE_ARRAY) { - double min = NULL; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMin(iparams.max_modes); - if (min == NULL || value < min) { - min = value; - } - } - - return min; - } - - /** - * Returns average value. - */ - template - double GetAvg(int start_bar, int count = WHOLE_ARRAY) { - int num_values = 0; - double sum = 0; - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - double value_min = GetEntry(shift).GetMin(iparams.max_modes); - double value_max = GetEntry(shift).GetMax(iparams.max_modes); - - sum += value_min + value_max; - num_values += 2; - } - - return sum / num_values; - } - - /** - * Returns median of values. + * Returns currently selected data source doing validation. */ - template - double GetMed(int start_bar, int count = WHOLE_ARRAY) { - double array[]; - - int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); - int num_bars = last_bar - start_bar + 1; - int index = 0; - - ArrayResize(array, num_bars); - - for (int shift = start_bar; shift <= last_bar; ++shift) { - array[index++] = GetEntry(shift).GetAvg(iparams.max_modes); - } - - ArraySort(array); - double median; - int len = ArraySize(array); - if (len % 2 == 0) { - median = (array[len / 2] + array[(len / 2) - 1]) / 2; - } else { - median = array[len / 2]; - } + virtual IndicatorBase* GetDataSource() { return NULL; } - return median; - } + int GetDataSourceMode() { return indi_src_mode; } /** * Gets indicator's symbol. From 60ffcc319638fcfc0a2c4a21cb599840f3daa995 Mon Sep 17 00:00:00 2001 From: kenorb Date: Fri, 15 Oct 2021 00:01:49 +0100 Subject: [PATCH 72/78] Indicators: Adds copy constructor to struct params --- Indicators/Bitwise/Indi_Candle.mqh | 7 +++---- Indicators/Indi_AC.mqh | 6 +++++- Indicators/Indi_AD.mqh | 4 ++++ Indicators/Indi_ADX.mqh | 9 ++++----- Indicators/Indi_ADXW.mqh | 10 ++++++---- Indicators/Indi_AMA.mqh | 8 ++++---- Indicators/Indi_AO.mqh | 6 +++++- Indicators/Indi_ASI.mqh | 6 +++++- Indicators/Indi_ATR.mqh | 7 +++++-- Indicators/Indi_Alligator.mqh | 8 ++++++-- Indicators/Indi_AppliedPrice.mqh | 4 ++++ Indicators/Indi_BWMFI.mqh | 4 ++++ Indicators/Indi_BWZT.mqh | 6 +++++- Indicators/Indi_Bands.mqh | 8 ++++++-- Indicators/Indi_BearsPower.mqh | 6 +++++- Indicators/Indi_BullsPower.mqh | 6 +++++- Indicators/Indi_CCI.mqh | 6 +++++- Indicators/Indi_CHO.mqh | 8 ++++++-- Indicators/Indi_CHV.mqh | 8 ++++++-- Indicators/Indi_ColorBars.mqh | 6 +++++- Indicators/Indi_ColorCandlesDaily.mqh | 6 +++++- Indicators/Indi_ColorLine.mqh | 6 +++++- Indicators/Indi_CustomMovingAverage.mqh | 8 ++++++-- Indicators/Indi_DEMA.mqh | 6 +++--- Indicators/Indi_DeMarker.mqh | 6 +++++- Indicators/Indi_Demo.mqh | 6 +++--- Indicators/Indi_DetrendedPrice.mqh | 6 +++++- Indicators/Indi_Drawer.struct.h | 7 ++++--- Indicators/Indi_Envelopes.mqh | 8 ++++++-- Indicators/Indi_Force.mqh | 8 ++++++-- Indicators/Indi_FractalAdaptiveMA.mqh | 6 +++++- Indicators/Indi_Fractals.mqh | 6 +++++- Indicators/Indi_Gator.mqh | 8 ++++++-- Indicators/Indi_HeikenAshi.mqh | 6 +++++- Indicators/Indi_Ichimoku.mqh | 6 +++++- Indicators/Indi_Killzones.mqh | 7 +++---- Indicators/Indi_MA.mqh | 8 ++++++-- Indicators/Indi_MACD.mqh | 8 ++++++-- Indicators/Indi_MFI.mqh | 6 +++++- Indicators/Indi_MassIndex.mqh | 6 +++++- Indicators/Indi_Momentum.mqh | 6 +++++- Indicators/Indi_OBV.mqh | 12 +++++++----- Indicators/Indi_OsMA.mqh | 6 +++++- Indicators/Indi_Pattern.mqh | 6 +++++- Indicators/Indi_Pivot.mqh | 6 +++++- Indicators/Indi_Price.mqh | 6 +++++- Indicators/Indi_PriceChannel.mqh | 7 +++++-- Indicators/Indi_PriceFeeder.mqh | 8 ++++++-- Indicators/Indi_PriceVolumeTrend.mqh | 6 +++++- Indicators/Indi_RS.mqh | 6 +++++- Indicators/Indi_RSI.mqh | 6 +++--- Indicators/Indi_RVI.mqh | 6 +++++- Indicators/Indi_RateOfChange.mqh | 6 +++++- Indicators/Indi_SAR.mqh | 6 +++++- Indicators/Indi_StdDev.mqh | 8 ++++++-- Indicators/Indi_Stochastic.mqh | 8 ++++++-- Indicators/Indi_TEMA.mqh | 6 +++++- Indicators/Indi_TRIX.mqh | 6 +++++- Indicators/Indi_UltimateOscillator.mqh | 8 ++++++-- Indicators/Indi_VIDYA.mqh | 8 ++++++-- Indicators/Indi_VROC.mqh | 6 +++++- Indicators/Indi_Volumes.mqh | 6 +++++- Indicators/Indi_WPR.mqh | 7 +++++-- Indicators/Indi_WilliamsAD.mqh | 6 +++++- Indicators/Indi_ZigZag.mqh | 6 +++++- Indicators/Indi_ZigZagColor.mqh | 7 +++++-- Indicators/Special/Indi_Math.mqh | 16 ++++++---------- 67 files changed, 338 insertions(+), 120 deletions(-) diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index 807d06731..9ec62d809 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -32,15 +32,14 @@ // Structs. struct CandleParams : IndicatorParams { // Struct constructor. - void CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE, 1, TYPE_INT) { + CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE, 1, TYPE_INT) { SetDataValueRange(IDATA_RANGE_RANGE); SetDataSourceType(IDATA_BUILTIN); shift = _shift; tf = _tf; }; - void CandleParams(CandleParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : IndicatorParams(INDI_CANDLE, 1, TYPE_INT) { - this = _p; + CandleParams(CandleParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; tf = _tf; }; }; diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 2e0c14996..82d58f1ca 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -32,11 +32,15 @@ double iAC(string _symbol, int _tf, int _shift) { return Indi_AC::iAC(_symbol, ( // Structs. struct ACParams : IndicatorParams { // Struct constructor. - void ACParams(int _shift = 0) : IndicatorParams(INDI_AC, 1, TYPE_DOUBLE) { + ACParams(int _shift = 0) : IndicatorParams(INDI_AC, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Accelerator"); shift = _shift; }; + ACParams(ACParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index f75b3867c..cf8e34b59 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -36,6 +36,10 @@ struct ADParams : IndicatorParams { SetCustomIndicatorName("Examples\\AD"); shift = _shift; }; + ADParams(ADParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 843d96ee3..3db34ea1b 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -37,8 +37,8 @@ struct ADXParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void ADXParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) + ADXParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) : period(_period), applied_price(_ap), IndicatorParams(INDI_ADX, FINAL_INDI_ADX_LINE_ENTRY, TYPE_DOUBLE) { SetDataSourceType(_idstype); SetDataValueRange(IDATA_RANGE_RANGE); @@ -51,9 +51,8 @@ struct ADXParams : IndicatorParams { break; } }; - void ADXParams(ADXParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : IndicatorParams(INDI_ADX, FINAL_INDI_ADX_LINE_ENTRY, TYPE_DOUBLE) { - this = _p; + ADXParams(ADXParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; tf = _tf; }; }; diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index 669f7f1d3..b833c3278 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -36,8 +36,8 @@ // Structs. struct ADXWParams : ADXParams { // Struct constructor. - void ADXWParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) + ADXWParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) : ADXParams(_period, _ap, _shift, _tf, _idstype) { itype = itype == INDI_NONE || itype == INDI_ADX ? INDI_ADXW : itype; switch (idstype) { @@ -46,8 +46,10 @@ struct ADXWParams : ADXParams { break; } }; - void ADXWParams(ADXWParams &_p, IndicatorBase *_indi_src = NULL) { THIS_REF = _p; } - void ADXWParams(ADXParams &_p) { THIS_REF = _p; } + ADXWParams(ADXWParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index a22630004..040dd9b67 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -35,8 +35,8 @@ struct IndiAMAParams : IndicatorParams { unsigned int ama_shift; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void IndiAMAParams(int _period = 10, int _fast_period = 2, int _slow_period = 30, int _ama_shift = 0, - ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0) + IndiAMAParams(int _period = 10, int _fast_period = 2, int _slow_period = 30, int _ama_shift = 0, + ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0) : period(_period), fast_period(_fast_period), slow_period(_slow_period), @@ -53,8 +53,8 @@ struct IndiAMAParams : IndicatorParams { break; } }; - void IndiAMAParams(IndiAMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_AMA, 1) { - this = _p; + IndiAMAParams(IndiAMAParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; tf = _tf; }; }; diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index ecd52ef25..f7dfdae45 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -31,7 +31,7 @@ double iAO(string _symbol, int _tf, int _shift) { return Indi_AO::iAO(_symbol, ( // Structs. struct AOParams : IndicatorParams { // Struct constructor. - void AOParams(int _shift = 0) : IndicatorParams(INDI_AO, 2, TYPE_DOUBLE) { + AOParams(int _shift = 0) : IndicatorParams(INDI_AO, 2, TYPE_DOUBLE) { #ifdef __MQL4__ max_modes = 1; #endif @@ -39,6 +39,10 @@ struct AOParams : IndicatorParams { SetCustomIndicatorName("Examples\\Awesome_Oscillator"); shift = _shift; }; + AOParams(AOParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index db5e47723..b30a079e3 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -30,12 +30,16 @@ struct ASIParams : IndicatorParams { unsigned int period; double mpc; // Struct constructor. - void ASIParams(double _mpc = 300.0, int _shift = 0) : IndicatorParams(INDI_ASI, 1, TYPE_DOUBLE) { + ASIParams(double _mpc = 300.0, int _shift = 0) : IndicatorParams(INDI_ASI, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ASI"); mpc = _mpc; shift = _shift; }; + ASIParams(ASIParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index 9f836f697..cd9a4cfff 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -34,12 +34,15 @@ double iATR(string _symbol, int _tf, int _period, int _shift) { struct ATRParams : IndicatorParams { unsigned int period; // Struct constructors. - void ATRParams(unsigned int _period = 14, int _shift = 0) - : period(_period), IndicatorParams(INDI_ATR, 1, TYPE_DOUBLE) { + ATRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_ATR, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ATR"); }; + ATRParams(ATRParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index e5f95ea7a..3a402bcd7 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -70,8 +70,8 @@ struct AlligatorParams : IndicatorParams { ENUM_MA_METHOD ma_method; // Averaging method. ENUM_APPLIED_PRICE applied_price; // Applied price. // Struct constructors. - void AlligatorParams(int _jp = 13, int _js = 8, int _tp = 8, int _ts = 5, int _lp = 5, int _ls = 3, - ENUM_MA_METHOD _mm = MODE_SMMA, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN, int _shift = 0) + AlligatorParams(int _jp = 13, int _js = 8, int _tp = 8, int _ts = 5, int _lp = 5, int _ls = 3, + ENUM_MA_METHOD _mm = MODE_SMMA, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN, int _shift = 0) : jaw_period(_jp), jaw_shift(_js), teeth_period(_tp), @@ -85,6 +85,10 @@ struct AlligatorParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Alligator"); }; + AlligatorParams(AlligatorParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index cd12b2c8f..9a0effec5 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -35,6 +35,10 @@ struct AppliedPriceParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); shift = _shift; }; + AppliedPriceParams(AppliedPriceParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index c5d4c5bce..b5fadf2e1 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -48,6 +48,10 @@ struct BWMFIParams : IndicatorParams { SetCustomIndicatorName("Examples\\MarketFacilitationIndex"); shift = _shift; }; + BWMFIParams(BWMFIParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 6a171b97b..c85064f30 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -33,11 +33,15 @@ struct BWZTParams : IndicatorParams { unsigned int second_period; unsigned int sum_period; // Struct constructor. - void BWZTParams(int _shift = 0) : IndicatorParams(INDI_BWZT, 5, TYPE_DOUBLE) { + BWZTParams(int _shift = 0) : IndicatorParams(INDI_BWZT, 5, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\BW-ZoneTrade"); shift = _shift; }; + BWZTParams(BWZTParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 36ccae4b9..80accbdd2 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -64,8 +64,8 @@ struct BandsParams : IndicatorParams { unsigned int bshift; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void BandsParams(unsigned int _period = 20, double _deviation = 2, int _bshift = 0, - ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) + BandsParams(unsigned int _period = 20, double _deviation = 2, int _bshift = 0, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, + int _shift = 0) : period(_period), deviation(_deviation), bshift(_bshift), @@ -75,6 +75,10 @@ struct BandsParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\BB"); }; + BandsParams(BandsParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index da9b08200..9a3be5ea3 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -35,12 +35,16 @@ struct BearsPowerParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void BearsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + BearsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), applied_price(_ap), IndicatorParams(INDI_BEARS, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Bears"); }; + BearsPowerParams(BearsPowerParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index dc7fc3b59..e905c8114 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -35,12 +35,16 @@ struct BullsPowerParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // (MT5): not used // Struct constructor. - void BullsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + BullsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), applied_price(_ap), IndicatorParams(INDI_BULLS, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Bulls"); }; + BullsPowerParams(BullsPowerParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 49d258f2f..b7f59c045 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -41,12 +41,16 @@ struct CCIParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void CCIParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) + CCIParams(unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) : period(_period), applied_price(_applied_price), IndicatorParams(INDI_CCI, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CCI"); }; + CCIParams(CCIParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 1e2de52da..0e3a3b421 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -34,8 +34,8 @@ struct CHOParams : IndicatorParams { ENUM_MA_METHOD smooth_method; ENUM_APPLIED_VOLUME input_volume; // Struct constructor. - void CHOParams(int _fast_ma = 3, int _slow_ma = 10, ENUM_MA_METHOD _smooth_method = MODE_EMA, - ENUM_APPLIED_VOLUME _input_volume = VOLUME_TICK, int _shift = 0) + CHOParams(int _fast_ma = 3, int _slow_ma = 10, ENUM_MA_METHOD _smooth_method = MODE_EMA, + ENUM_APPLIED_VOLUME _input_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_CHAIKIN, 1, TYPE_DOUBLE) { fast_ma = _fast_ma; input_volume = _input_volume; @@ -45,6 +45,10 @@ struct CHOParams : IndicatorParams { slow_ma = _slow_ma; smooth_method = _smooth_method; }; + CHOParams(CHOParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 3ced8ded3..035fce96a 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -36,8 +36,8 @@ struct CHVParams : IndicatorParams { unsigned int chv_period; ENUM_CHV_SMOOTH_METHOD smooth_method; // Struct constructor. - void CHVParams(int _smooth_period = 10, int _chv_period = 10, - ENUM_CHV_SMOOTH_METHOD _smooth_method = CHV_SMOOTH_METHOD_EMA, int _shift = 0) + CHVParams(int _smooth_period = 10, int _chv_period = 10, + ENUM_CHV_SMOOTH_METHOD _smooth_method = CHV_SMOOTH_METHOD_EMA, int _shift = 0) : IndicatorParams(INDI_CHAIKIN_V, 1, TYPE_DOUBLE) { chv_period = _chv_period; SetDataValueRange(IDATA_RANGE_MIXED); @@ -46,6 +46,10 @@ struct CHVParams : IndicatorParams { smooth_method = _smooth_method; smooth_period = _smooth_period; }; + CHVParams(CHVParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 431dadb60..10098517a 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -28,11 +28,15 @@ // Structs. struct ColorBarsParams : IndicatorParams { // Struct constructor. - void ColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS, 5, TYPE_DOUBLE) { + ColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS, 5, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorBars"); shift = _shift; }; + ColorBarsParams(ColorBarsParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index 357894a89..a83d64091 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -28,11 +28,15 @@ // Structs. struct ColorCandlesDailyParams : IndicatorParams { // Struct constructor. - void ColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY, 5, TYPE_DOUBLE) { + ColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY, 5, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorCandlesDaily"); shift = _shift; }; + ColorCandlesDailyParams(ColorCandlesDailyParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 7fb5d94b1..4d81bde62 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -29,11 +29,15 @@ // Structs. struct ColorLineParams : IndicatorParams { // Struct constructor. - void ColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE, 2, TYPE_DOUBLE) { + ColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE, 2, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorLine"); shift = _shift; }; + ColorLineParams(ColorLineParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index ea7b67775..a8520dc45 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -30,8 +30,8 @@ struct CustomMovingAverageParams : IndicatorParams { unsigned int smooth_shift; ENUM_MA_METHOD smooth_method; // Struct constructor. - void CustomMovingAverageParams(int _smooth_period = 13, int _smooth_shift = 0, - ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0) + CustomMovingAverageParams(int _smooth_period = 13, int _smooth_shift = 0, ENUM_MA_METHOD _smooth_method = MODE_SMMA, + int _shift = 0) : IndicatorParams(INDI_CUSTOM_MOVING_AVG, 3, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_ICUSTOM); @@ -45,6 +45,10 @@ struct CustomMovingAverageParams : IndicatorParams { smooth_period = _smooth_period; smooth_shift = _smooth_shift; }; + CustomMovingAverageParams(CustomMovingAverageParams& _params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 3b8316f5e..26f1ec6b0 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -41,7 +41,7 @@ struct DEMAParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void DEMAParams(unsigned int _period = 14, int _ma_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + DEMAParams(unsigned int _period = 14, int _ma_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : period(_period), ma_shift(_ma_shift), applied_price(_ap), IndicatorParams(INDI_DEMA, 1, TYPE_DOUBLE) { SetCustomIndicatorName("Examples\\DEMA"); SetDataValueRange(IDATA_RANGE_PRICE); @@ -54,8 +54,8 @@ struct DEMAParams : IndicatorParams { break; } }; - void DEMAParams(DEMAParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _p; + DEMAParams(DEMAParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; tf = _tf; }; }; diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index 1c3642122..ba5e682f0 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -34,12 +34,16 @@ double iDeMarker(string _symbol, int _tf, int _period, int _shift) { struct DeMarkerParams : IndicatorParams { unsigned int period; // Struct constructors. - void DeMarkerParams(unsigned int _period = 14, int _shift = 0) + DeMarkerParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_DEMARKER, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\DeMarker"); }; + DeMarkerParams(DeMarkerParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index 362c25233..0d0d0ba83 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -33,7 +33,7 @@ // Structs. struct DemoIndiParams : IndicatorParams { // Struct constructors. - void DemoIndiParams(int _shift = 0) : IndicatorParams(INDI_DEMO, 1, TYPE_DOUBLE) { + DemoIndiParams(int _shift = 0) : IndicatorParams(INDI_DEMO, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetShift(_shift); switch (idstype) { @@ -44,8 +44,8 @@ struct DemoIndiParams : IndicatorParams { break; } }; - void DemoIndiParams(DemoIndiParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_DEMO, 1) { - this = _p; + DemoIndiParams(DemoIndiParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; tf = _tf; }; }; diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 452662d44..7b888bf3f 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -31,7 +31,7 @@ struct DetrendedPriceParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void DetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + DetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : IndicatorParams(INDI_DETRENDED_PRICE, 1, TYPE_DOUBLE) { applied_price = _ap; SetDataValueRange(IDATA_RANGE_MIXED); @@ -39,6 +39,10 @@ struct DetrendedPriceParams : IndicatorParams { period = _period; shift = _shift; }; + DetrendedPriceParams(DetrendedPriceParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index 94a7c3c14..d033752b6 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -35,12 +35,13 @@ struct DrawerParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; - DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) : period(_period), applied_price(_ap), IndicatorParams(INDI_DRAWER, 0, TYPE_DOUBLE) { + DrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) + : period(_period), applied_price(_ap), IndicatorParams(INDI_DRAWER, 0, TYPE_DOUBLE) { // Fetching history data is not yet implemented. SetCustomIndicatorName("Examples\\Drawer"); }; - void DrawerParams(DrawerParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _p; + DrawerParams(DrawerParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; tf = _tf; }; // Serializers. diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 7de6b923b..bd5439826 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -49,8 +49,8 @@ struct EnvelopesParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; double deviation; // Struct constructors. - void EnvelopesParams(int _ma_period = 13, int _ma_shift = 0, ENUM_MA_METHOD _ma_method = MODE_SMA, - ENUM_APPLIED_PRICE _ap = PRICE_OPEN, double _deviation = 2, int _shift = 0) + EnvelopesParams(int _ma_period = 13, int _ma_shift = 0, ENUM_MA_METHOD _ma_method = MODE_SMA, + ENUM_APPLIED_PRICE _ap = PRICE_OPEN, double _deviation = 2, int _shift = 0) : ma_period(_ma_period), ma_shift(_ma_shift), ma_method(_ma_method), @@ -65,6 +65,10 @@ struct EnvelopesParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Envelopes"); }; + EnvelopesParams(EnvelopesParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index 6a6be32f3..a4a87e93f 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -48,13 +48,17 @@ struct ForceParams : IndicatorParams { ENUM_MA_METHOD ma_method; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void ForceParams(unsigned int _period = 13, ENUM_MA_METHOD _ma_method = MODE_SMA, - ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + ForceParams(unsigned int _period = 13, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, + int _shift = 0) : period(_period), ma_method(_ma_method), applied_price(_ap), IndicatorParams(INDI_FORCE, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Force_Index"); }; + ForceParams(ForceParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 39c3f472a..715357c65 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -32,7 +32,7 @@ struct IndiFrAMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void IndiFrAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + IndiFrAMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : IndicatorParams(INDI_FRAMA, 1, TYPE_DOUBLE) { frama_shift = _frama_shift; SetDataValueRange(IDATA_RANGE_MIXED); @@ -41,6 +41,10 @@ struct IndiFrAMAParams : IndicatorParams { period = _period; shift = _shift; }; + IndiFrAMAParams(IndiFrAMAParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index c0d970556..b84f2c0c9 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -33,11 +33,15 @@ double iFractals(string _symbol, int _tf, int _mode, int _shift) { // Structs. struct FractalsParams : IndicatorParams { // Struct constructors. - void FractalsParams(int _shift = 0) : IndicatorParams(INDI_FRACTALS, FINAL_LO_UP_LINE_ENTRY, TYPE_DOUBLE) { + FractalsParams(int _shift = 0) : IndicatorParams(INDI_FRACTALS, FINAL_LO_UP_LINE_ENTRY, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_ARROW); SetCustomIndicatorName("Examples\\Fractals"); shift = _shift; }; + FractalsParams(FractalsParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index af3c33ca7..4984d1ca7 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -78,8 +78,8 @@ struct GatorParams : IndicatorParams { ENUM_MA_METHOD ma_method; // Averaging method. ENUM_APPLIED_PRICE applied_price; // Applied price. // Struct constructors. - void GatorParams(int _jp = 13, int _js = 8, int _tp = 8, int _ts = 5, int _lp = 5, int _ls = 3, - ENUM_MA_METHOD _mm = MODE_SMMA, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN, int _shift = 0) + GatorParams(int _jp = 13, int _js = 8, int _tp = 8, int _ts = 5, int _lp = 5, int _ls = 3, + ENUM_MA_METHOD _mm = MODE_SMMA, ENUM_APPLIED_PRICE _ap = PRICE_MEDIAN, int _shift = 0) : jaw_period(_jp), jaw_shift(_js), teeth_period(_tp), @@ -93,6 +93,10 @@ struct GatorParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Gator"); }; + GatorParams(GatorParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index 1420f0aba..df4236589 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -50,7 +50,7 @@ enum ENUM_HA_MODE { // Structs. struct HeikenAshiParams : IndicatorParams { // Struct constructors. - void HeikenAshiParams(int _shift = 0) : IndicatorParams(INDI_HEIKENASHI, FINAL_HA_MODE_ENTRY, TYPE_DOUBLE) { + HeikenAshiParams(int _shift = 0) : IndicatorParams(INDI_HEIKENASHI, FINAL_HA_MODE_ENTRY, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); // @fixit It draws candles! #ifdef __MQL4__ SetCustomIndicatorName("Heiken Ashi"); @@ -59,6 +59,10 @@ struct HeikenAshiParams : IndicatorParams { #endif shift = _shift; }; + HeikenAshiParams(HeikenAshiParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index 276ffb10d..c303cf214 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -67,7 +67,7 @@ struct IchimokuParams : IndicatorParams { unsigned int kijun_sen; unsigned int senkou_span_b; // Struct constructors. - void IchimokuParams(unsigned int _ts = 9, unsigned int _ks = 26, unsigned int _ss_b = 52, int _shift = 0) + IchimokuParams(unsigned int _ts = 9, unsigned int _ks = 26, unsigned int _ss_b = 52, int _shift = 0) : tenkan_sen(_ts), kijun_sen(_ks), senkou_span_b(_ss_b), @@ -76,6 +76,10 @@ struct IchimokuParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Not sure if not mixed. SetCustomIndicatorName("Examples\\Ichimoku"); }; + IchimokuParams(IchimokuParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index 1646bb538..6454e49d3 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -49,16 +49,15 @@ enum ENUM_INDI_KILLZONES_MODE { struct IndiKillzonesParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - void IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_PIVOT, FINAL_INDI_KILLZONES_MODE_ENTRY, TYPE_FLOAT) { SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_CHART); SetShift(_shift); tf = _tf; }; - void IndiKillzonesParams(IndiKillzonesParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : IndicatorParams(INDI_PIVOT) { - this = _p; + IndiKillzonesParams(IndiKillzonesParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; tf = _tf; }; }; diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index f134e6cf0..3b439255d 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -52,8 +52,8 @@ struct MAParams : IndicatorParams { ENUM_MA_METHOD ma_method; ENUM_APPLIED_PRICE applied_array; // Struct constructors. - void MAParams(unsigned int _period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, - ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) + MAParams(unsigned int _period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, + ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : period(_period), ma_shift(_ma_shift), ma_method(_ma_method), @@ -63,6 +63,10 @@ struct MAParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Moving Average"); }; + MAParams(MAParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index 7bac7dcfd..8bc246a89 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -38,8 +38,8 @@ struct MACDParams : IndicatorParams { unsigned int signal_period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void MACDParams(unsigned int _efp = 12, unsigned int _esp = 26, unsigned int _sp = 9, - ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + MACDParams(unsigned int _efp = 12, unsigned int _esp = 26, unsigned int _sp = 9, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, + int _shift = 0) : ema_fast_period(_efp), ema_slow_period(_esp), signal_period(_sp), @@ -49,6 +49,10 @@ struct MACDParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\MACD"); }; + MACDParams(MACDParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index 132ebc9f3..1b4995e62 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -35,12 +35,16 @@ struct MFIParams : IndicatorParams { unsigned int ma_period; ENUM_APPLIED_VOLUME applied_volume; // Ignored in MT4. // Struct constructors. - void MFIParams(unsigned int _ma_period = 14, ENUM_APPLIED_VOLUME _av = VOLUME_TICK, int _shift = 0) + MFIParams(unsigned int _ma_period = 14, ENUM_APPLIED_VOLUME _av = VOLUME_TICK, int _shift = 0) : ma_period(_ma_period), applied_volume(_av), IndicatorParams(INDI_MFI, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\MFI"); }; + MFIParams(MFIParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index 0f9564234..4d84ec872 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -32,7 +32,7 @@ struct MassIndexParams : IndicatorParams { int second_period; int sum_period; // Struct constructor. - void MassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0) + MassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0) : IndicatorParams(INDI_MASS_INDEX, 1, TYPE_DOUBLE) { period = _period; second_period = _second_period; @@ -41,6 +41,10 @@ struct MassIndexParams : IndicatorParams { shift = _shift; sum_period = _sum_period; }; + MassIndexParams(MassIndexParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 140770866..02c51401a 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -45,12 +45,16 @@ struct MomentumParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void MomentumParams(unsigned int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) + MomentumParams(unsigned int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : period(_period), applied_price(_ap), IndicatorParams(INDI_MOMENTUM, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Momentum"); }; + MomentumParams(MomentumParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 64718ec6c..6740e8630 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -35,23 +35,25 @@ struct OBVParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // MT4 only. ENUM_APPLIED_VOLUME applied_volume; // MT5 only. // Struct constructors. - void OBVParams(int _shift = 0) : IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { + OBVParams(int _shift = 0) : IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\OBV"); applied_price = PRICE_CLOSE; applied_volume = VOLUME_TICK; } - void OBVParams(ENUM_APPLIED_VOLUME _av, int _shift = 0) - : applied_volume(_av), IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { + OBVParams(ENUM_APPLIED_VOLUME _av, int _shift = 0) : applied_volume(_av), IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { max_modes = 1; shift = _shift; }; - void OBVParams(ENUM_APPLIED_PRICE _ap, int _shift = 0) - : applied_price(_ap), IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { + OBVParams(ENUM_APPLIED_PRICE _ap, int _shift = 0) : applied_price(_ap), IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { max_modes = 1; shift = _shift; }; + OBVParams(OBVParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 9e62b1c6b..c215c6589 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -38,7 +38,7 @@ struct OsMAParams : IndicatorParams { int signal_period; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void OsMAParams(int _efp = 12, int _esp = 26, int _sp = 9, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + OsMAParams(int _efp = 12, int _esp = 26, int _sp = 9, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : ema_fast_period(_efp), ema_slow_period(_esp), signal_period(_sp), @@ -48,6 +48,10 @@ struct OsMAParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\OsMA"); }; + OsMAParams(OsMAParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Pattern.mqh b/Indicators/Indi_Pattern.mqh index d2abd7b0f..9e359f816 100644 --- a/Indicators/Indi_Pattern.mqh +++ b/Indicators/Indi_Pattern.mqh @@ -32,10 +32,14 @@ // Structs. struct IndiPatternParams : IndicatorParams { // Struct constructor. - void IndiPatternParams(int _shift = 0) : IndicatorParams(INDI_PATTERN, 5, TYPE_INT) { + IndiPatternParams(int _shift = 0) : IndicatorParams(INDI_PATTERN, 5, TYPE_INT) { SetDataValueRange(IDATA_RANGE_BITWISE); shift = _shift; }; + IndiPatternParams(IndiPatternParams& _params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index 3b132da3e..392e24bde 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -30,11 +30,15 @@ struct IndiPivotParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - void IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) : IndicatorParams(INDI_PIVOT, 9, TYPE_FLOAT) { + IndiPivotParams(ENUM_PP_TYPE _method = PP_CLASSIC, int _shift = 0) : IndicatorParams(INDI_PIVOT, 9, TYPE_FLOAT) { method = _method; SetDataValueRange(IDATA_RANGE_MIXED); shift = _shift; }; + IndiPivotParams(IndiPivotParams& _params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index b8e14a5d5..b73b0f8b1 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -39,9 +39,13 @@ enum ENUM_INDI_PRICE_MODE { // Structs. struct PriceIndiParams : IndicatorParams { // Struct constructor. - void PriceIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE, FINAL_INDI_PRICE_MODE, TYPE_DOUBLE) { + PriceIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE, FINAL_INDI_PRICE_MODE, TYPE_DOUBLE) { SetShift(_shift); }; + PriceIndiParams(PriceIndiParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index 7e82d4dc8..8f87a7996 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -28,14 +28,17 @@ struct PriceChannelParams : IndicatorParams { unsigned int period; // Struct constructor. - void PriceChannelParams(unsigned int _period = 22, int _shift = 0) - : IndicatorParams(INDI_PRICE_CHANNEL, 3, TYPE_DOUBLE) { + PriceChannelParams(unsigned int _period = 22, int _shift = 0) : IndicatorParams(INDI_PRICE_CHANNEL, 3, TYPE_DOUBLE) { period = _period; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Price_Channel"); SetDataSourceType(IDATA_ICUSTOM); shift = _shift; }; + PriceChannelParams(PriceChannelParams& _params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index 701581585..ffb341cfa 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -32,18 +32,22 @@ struct PriceFeederIndiParams : IndicatorParams { /** * Struct constructor. */ - void PriceFeederIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE_FEEDER, 1, TYPE_DOUBLE) { shift = _shift; } + PriceFeederIndiParams(int _shift = 0) : IndicatorParams(INDI_PRICE_FEEDER, 1, TYPE_DOUBLE) { shift = _shift; } /** * Struct constructor. * * @todo Use more modes (full OHCL). */ - void PriceFeederIndiParams(const double& _price_data[], int _total = 0) + PriceFeederIndiParams(const double& _price_data[], int _total = 0) : IndicatorParams(INDI_PRICE_FEEDER, 1, TYPE_DOUBLE) { tf = PERIOD_CURRENT; ArrayCopy(price_data, _price_data, 0, 0, _total == 0 ? WHOLE_ARRAY : _total); }; + PriceFeederIndiParams(PriceFeederIndiParams& _params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index 767dd21e4..5dd2d502b 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -29,13 +29,17 @@ struct PriceVolumeTrendParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void PriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) + PriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_PRICE_VOLUME_TREND, 1, TYPE_DOUBLE) { applied_volume = _applied_volume; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\PVT"); shift = _shift; }; + PriceVolumeTrendParams(PriceVolumeTrendParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index 43e23f0e7..a1b9c815a 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -30,13 +30,17 @@ struct RSParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) + RSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_RS, 2, TYPE_DOUBLE) { applied_volume = _applied_volume; SetDataValueRange(IDATA_RANGE_MIXED); SetDataSourceType(IDATA_MATH); shift = _shift; }; + RSParams(RSParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index d99922b06..d4c520a3c 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -48,15 +48,15 @@ struct RSIParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; public: - void RSIParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) + RSIParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : applied_price(_ap), IndicatorParams(INDI_RSI, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\RSI"); SetPeriod(_period); }; - void RSIParams(RSIParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - this = _p; + RSIParams(RSIParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; tf = _tf; }; // Getters. diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index 42d1e45e1..abf3373a8 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -34,12 +34,16 @@ double iRVI(string _symbol, int _tf, int _period, int _mode, int _shift) { struct RVIParams : IndicatorParams { unsigned int period; // Struct constructors. - void RVIParams(unsigned int _period = 10, int _shift = 0) + RVIParams(unsigned int _period = 10, int _shift = 0) : period(_period), IndicatorParams(INDI_RVI, FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\RVI"); }; + RVIParams(RVIParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index 7995fe06e..8b31c29c6 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -30,7 +30,7 @@ struct RateOfChangeParams : IndicatorParams { unsigned int period; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void RateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + RateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : IndicatorParams(INDI_RATE_OF_CHANGE, 1, TYPE_DOUBLE) { applied_price = _ap; SetDataValueRange(IDATA_RANGE_MIXED); @@ -38,6 +38,10 @@ struct RateOfChangeParams : IndicatorParams { period = _period; shift = _shift; }; + RateOfChangeParams(RateOfChangeParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index f010d10e5..7c6b5b3ef 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -35,12 +35,16 @@ struct SARParams : IndicatorParams { double step; double max; // Struct constructors. - void SARParams(double _step = 0.02, double _max = 0.2, int _shift = 0) + SARParams(double _step = 0.02, double _max = 0.2, int _shift = 0) : step(_step), max(_max), IndicatorParams(INDI_SAR, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_PRICE); // @fixit It draws single dot for each bar! SetCustomIndicatorName("Examples\\ParabolicSAR"); }; + SARParams(SARParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index d58f3fffb..b2669b811 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -50,8 +50,8 @@ struct StdDevParams : IndicatorParams { ENUM_MA_METHOD ma_method; ENUM_APPLIED_PRICE applied_price; // Struct constructors. - void StdDevParams(int _ma_period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, - ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) + StdDevParams(int _ma_period = 13, int _ma_shift = 10, ENUM_MA_METHOD _ma_method = MODE_SMA, + ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) : ma_period(_ma_period), ma_shift(_ma_shift), ma_method(_ma_method), @@ -61,6 +61,10 @@ struct StdDevParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\StdDev"); }; + StdDevParams(StdDevParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 525affda3..90c45f4dd 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -40,8 +40,8 @@ struct StochParams : IndicatorParams { ENUM_MA_METHOD ma_method; ENUM_STO_PRICE price_field; // Struct constructors. - void StochParams(int _kperiod = 5, int _dperiod = 3, int _slowing = 3, ENUM_MA_METHOD _ma_method = MODE_SMA, - ENUM_STO_PRICE _pf = STO_LOWHIGH, int _shift = 0) + StochParams(int _kperiod = 5, int _dperiod = 3, int _slowing = 3, ENUM_MA_METHOD _ma_method = MODE_SMA, + ENUM_STO_PRICE _pf = STO_LOWHIGH, int _shift = 0) : kperiod(_kperiod), dperiod(_dperiod), slowing(_slowing), @@ -52,6 +52,10 @@ struct StochParams : IndicatorParams { SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\Stochastic"); }; + StochParams(StochParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index 830b8c39b..3c1708cbc 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -32,7 +32,7 @@ struct TEMAParams : IndicatorParams { unsigned int tema_shift; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void TEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + TEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : IndicatorParams(INDI_TEMA, 1, TYPE_DOUBLE) { applied_price = _ap; SetDataValueRange(IDATA_RANGE_MIXED); @@ -41,6 +41,10 @@ struct TEMAParams : IndicatorParams { shift = _shift; tema_shift = _tema_shift; }; + TEMAParams(TEMAParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index 12b7ce742..44095d48d 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -32,7 +32,7 @@ struct TRIXParams : IndicatorParams { unsigned int tema_shift; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + TRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : IndicatorParams(INDI_TRIX, 1, TYPE_DOUBLE) { applied_price = _ap; SetDataValueRange(IDATA_RANGE_MIXED); @@ -40,6 +40,10 @@ struct TRIXParams : IndicatorParams { period = _period; shift = _shift; }; + TRIXParams(TRIXParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 576878bac..462eb4f17 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -37,8 +37,8 @@ struct UltimateOscillatorParams : IndicatorParams { int slow_k; // Struct constructor. - void UltimateOscillatorParams(int _fast_period = 7, int _middle_period = 14, int _slow_period = 28, int _fast_k = 4, - int _middle_k = 2, int _slow_k = 1, int _shift = 0) + UltimateOscillatorParams(int _fast_period = 7, int _middle_period = 14, int _slow_period = 28, int _fast_k = 4, + int _middle_k = 2, int _slow_k = 1, int _shift = 0) : IndicatorParams(INDI_ULTIMATE_OSCILLATOR, 1, TYPE_DOUBLE) { fast_k = _fast_k; fast_period = _fast_period; @@ -50,6 +50,10 @@ struct UltimateOscillatorParams : IndicatorParams { slow_k = _slow_k; slow_period = _slow_period; }; + UltimateOscillatorParams(UltimateOscillatorParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index e4d744406..c8a91b4cf 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -33,8 +33,8 @@ struct VIDYAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. - void VIDYAParams(unsigned int _cmo_period = 9, unsigned int _ma_period = 14, unsigned int _vidya_shift = 0, - ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) + VIDYAParams(unsigned int _cmo_period = 9, unsigned int _ma_period = 14, unsigned int _vidya_shift = 0, + ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : IndicatorParams(INDI_VIDYA, 1, TYPE_DOUBLE) { applied_price = _ap; cmo_period = _cmo_period; @@ -44,6 +44,10 @@ struct VIDYAParams : IndicatorParams { shift = _shift; vidya_shift = _vidya_shift; }; + VIDYAParams(VIDYAParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index 55a9ed8ae..d8c99ca10 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -30,7 +30,7 @@ struct VROCParams : IndicatorParams { unsigned int period; ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void VROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) + VROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_VROC, 1, TYPE_DOUBLE) { applied_volume = _applied_volume; period = _period; @@ -38,6 +38,10 @@ struct VROCParams : IndicatorParams { SetCustomIndicatorName("Examples\\VROC"); shift = _shift; }; + VROCParams(VROCParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index f4a9bced4..812facaab 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -29,7 +29,7 @@ struct VolumesParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - void VolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) + VolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_VOLUMES, 2, TYPE_DOUBLE) { applied_volume = _applied_volume; SetDataValueRange(IDATA_RANGE_MIXED); @@ -37,6 +37,10 @@ struct VolumesParams : IndicatorParams { SetDataSourceType(IDATA_BUILTIN); shift = _shift; }; + VolumesParams(VolumesParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index e2d831b88..a6d72aebf 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -34,12 +34,15 @@ double iWPR(string _symbol, int _tf, int _period, int _shift) { struct WPRParams : IndicatorParams { unsigned int period; // Struct constructors. - void WPRParams(unsigned int _period = 14, int _shift = 0) - : period(_period), IndicatorParams(INDI_WPR, 1, TYPE_DOUBLE) { + WPRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_WPR, 1, TYPE_DOUBLE) { shift = _shift; SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\WPR"); }; + WPRParams(WPRParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index 0700df7d9..b7f36749d 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -28,11 +28,15 @@ // Structs. struct WilliamsADParams : IndicatorParams { // Struct constructor. - void WilliamsADParams(int _shift = 0) : IndicatorParams(INDI_WILLIAMS_AD, 1, TYPE_DOUBLE) { + WilliamsADParams(int _shift = 0) : IndicatorParams(INDI_WILLIAMS_AD, 1, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\W_AD"); shift = _shift; }; + WilliamsADParams(WilliamsADParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index a25b38f8c..a44040012 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -34,7 +34,7 @@ struct ZigZagParams : IndicatorParams { unsigned int deviation; unsigned int backstep; // Struct constructors. - void ZigZagParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) + ZigZagParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) : depth(_depth), deviation(_deviation), backstep(_backstep), @@ -43,6 +43,10 @@ struct ZigZagParams : IndicatorParams { SetCustomIndicatorName("Examples\\ZigZag"); SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Draws lines between lowest and highest prices! }; + ZigZagParams(ZigZagParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; enum EnSearchMode { diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 6a87b6413..9b6ba986d 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -31,8 +31,7 @@ struct ZigZagColorParams : IndicatorParams { unsigned int backstep; // Struct constructor. - void ZigZagColorParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, - int _shift = 0) + ZigZagColorParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) : IndicatorParams(INDI_ZIGZAG_COLOR, 3, TYPE_DOUBLE) { backstep = _backstep; depth = _depth; @@ -42,6 +41,10 @@ struct ZigZagColorParams : IndicatorParams { SetDataSourceType(IDATA_ICUSTOM); shift = _shift; }; + ZigZagColorParams(ZigZagColorParams& _params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; + tf = _tf; + }; }; /** diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index b4c3d6abd..5aa0f7a6e 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -40,9 +40,8 @@ struct MathParams : IndicatorParams { unsigned int shift_2; // Struct constructor. - void MathParams(ENUM_MATH_OP _op = MATH_OP_SUB, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, - unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + MathParams(ENUM_MATH_OP _op = MATH_OP_SUB, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, + unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_SPECIAL_MATH, 1, TYPE_DOUBLE) { mode_1 = _mode_1; mode_2 = _mode_2; @@ -57,9 +56,8 @@ struct MathParams : IndicatorParams { }; // Struct constructor. - void MathParams(MathCustomOpFunction _op, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, - unsigned int _shift_1 = 0, unsigned int _shift_2 = 0, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + MathParams(MathCustomOpFunction _op, unsigned int _mode_1 = 0, unsigned int _mode_2 = 1, unsigned int _shift_1 = 0, + unsigned int _shift_2 = 0, int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_SPECIAL_MATH, 1, TYPE_DOUBLE) { max_modes = 1; mode_1 = _mode_1; @@ -73,10 +71,8 @@ struct MathParams : IndicatorParams { shift_2 = _shift_2; tf = _tf; }; - - void MathParams(MathParams &_p, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) - : IndicatorParams(INDI_SPECIAL_MATH, 1, TYPE_DOUBLE) { - this = _p; + MathParams(MathParams &_params, ENUM_TIMEFRAMES _tf) { + THIS_REF = _params; tf = _tf; }; }; From 48552b9f79a1a08e6d4a0ac60e168472d3f14295 Mon Sep 17 00:00:00 2001 From: kenorb Date: Fri, 15 Oct 2021 00:02:49 +0100 Subject: [PATCH 73/78] Indicator: Minor code fixes --- Indicator.struct.h | 12 ++++++++++-- Strategy.mqh | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Indicator.struct.h b/Indicator.struct.h index d9d98a3fd..1cbcbf7b5 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -378,7 +378,7 @@ struct IndicatorParams { /* Special methods */ // Constructor. IndicatorParams(ENUM_INDICATOR_TYPE _itype = INDI_NONE, unsigned int _max_modes = 1, - ENUM_DATATYPE _dtype = TYPE_DOUBLE, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, + ENUM_DATATYPE _dtype = TYPE_DOUBLE, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, string _name = "") : custom_indi_name(""), dtype(_dtype), @@ -393,7 +393,8 @@ struct IndicatorParams { itype(_itype), is_draw(false), indi_color(clrNONE), - draw_window(0) { + draw_window(0), + tf(_tf) { SetDataSourceType(_idstype); Init(); }; @@ -413,6 +414,13 @@ struct IndicatorParams { SetDataSourceType(_idstype); Init(); }; + // Copy constructor. + IndicatorParams(IndicatorParams &_iparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : tf(_tf) { + this = _iparams; + if (_tf != PERIOD_CURRENT) { + tf.SetTf(_tf); + } + } void Init() {} /* Getters */ string GetCustomIndicatorName() const { return custom_indi_name; } diff --git a/Strategy.mqh b/Strategy.mqh index 3e8ecc1fa..b4fa1bcc6 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -1216,7 +1216,7 @@ class Strategy : public Object { StrategyPriceStop _psm(_method); _psm.SetChartParams(_chart.GetParams()); if (Object::IsValid(_indi)) { - int _ishift = fmax(0, _direction > 0 ? _indi.GetHighest(_bars) : _indi.GetLowest(_bars)); + int _ishift = 12; // @todo: Make it dynamic or as variable. float _value = _indi.GetValuePrice(_ishift, 0, _direction > 0 ? PRICE_HIGH : PRICE_LOW); _value = _value + (float)Math::ChangeByPct(fabs(_value - _chart.GetCloseOffer(0)), _level) * _direction; _psm.SetIndicatorPriceValue(_value); From 203e04cfcd5b6b3a14ba82a892bf63ff591c1fe8 Mon Sep 17 00:00:00 2001 From: kenorb Date: Fri, 15 Oct 2021 19:55:24 +0100 Subject: [PATCH 74/78] Indicator: Sets SetDataSource by default when source is NULL [WIP] --- Indicator.enum.h | 2 +- Indicator.mqh | 3 ++- Indicator.struct.cache.h | 1 + Indicator.struct.h | 6 ++---- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Indicator.enum.h b/Indicator.enum.h index 941b250c9..379a30ec7 100644 --- a/Indicator.enum.h +++ b/Indicator.enum.h @@ -128,7 +128,7 @@ enum ENUM_INDICATOR_TYPE { /* Defines type of source data for indicator. */ enum ENUM_IDATA_SOURCE_TYPE { - IDATA_BUILTIN, // Platform built-in + IDATA_BUILTIN = 0, // Platform built-in IDATA_CHART, // Chart calculation IDATA_ICUSTOM, // iCustom: Custom indicator file IDATA_ICUSTOM_LEGACY, // iCustom: Custom, legacy, provided by MT indicator file diff --git a/Indicator.mqh b/Indicator.mqh index 9a5c7659d..3717c10aa 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -126,7 +126,8 @@ class Indicator : public IndicatorBase { break; case IDATA_INDICATOR: if (indi_src == NULL) { - // SetDataSource(Indi_Price::GetCached(iparams.GetShift(), GetTf(), PRICE_TYPICAL, _period), true); + // Indi_Price* _indi_price = Indi_Price::GetCached(GetSymbol(), GetTf(), iparams.GetShift()); + // SetDataSource(_indi_price, true, PRICE_OPEN); } break; } diff --git a/Indicator.struct.cache.h b/Indicator.struct.cache.h index 69a652eb4..2c4df7097 100644 --- a/Indicator.struct.cache.h +++ b/Indicator.struct.cache.h @@ -32,6 +32,7 @@ // Includes. #include "Refs.mqh" +#include "Storage/ValueStorage.h" /** * Holds buffers used to cache values calculated via OnCalculate methods. diff --git a/Indicator.struct.h b/Indicator.struct.h index 1cbcbf7b5..8bedbd5b0 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -378,8 +378,8 @@ struct IndicatorParams { /* Special methods */ // Constructor. IndicatorParams(ENUM_INDICATOR_TYPE _itype = INDI_NONE, unsigned int _max_modes = 1, - ENUM_DATATYPE _dtype = TYPE_DOUBLE, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, - string _name = "") + ENUM_DATATYPE _dtype = TYPE_DOUBLE, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, + ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, string _name = "") : custom_indi_name(""), dtype(_dtype), name(_name), @@ -395,7 +395,6 @@ struct IndicatorParams { indi_color(clrNONE), draw_window(0), tf(_tf) { - SetDataSourceType(_idstype); Init(); }; IndicatorParams(string _name, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) @@ -411,7 +410,6 @@ struct IndicatorParams { is_draw(false), indi_color(clrNONE), draw_window(0) { - SetDataSourceType(_idstype); Init(); }; // Copy constructor. From c54cb63ffb4fd5b1d8ca81f2ac906c6cf82a950f Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 16 Oct 2021 00:29:32 +0100 Subject: [PATCH 75/78] Strategy: TickFilter: Updates last tick for method 1 --- Strategy.mqh | 1 + 1 file changed, 1 insertion(+) diff --git a/Strategy.mqh b/Strategy.mqh index b4fa1bcc6..839b86425 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -967,6 +967,7 @@ class Strategy : public Object { // Process on every minute. _val = _tick.time % 60 < last_tick.time % 60; _res = _method > 0 ? _res & _val : _res | _val; + last_tick = _tick; } if (METHOD(_method_abs, 1)) { // 2 // Process low and high ticks of a bar. From d9738dc936764471fc8d3e5f17570ac596db1464 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 16 Oct 2021 16:02:55 +0100 Subject: [PATCH 76/78] Indicator: Adds IDATA_ONCALCULATE enum --- Indicator.enum.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Indicator.enum.h b/Indicator.enum.h index 379a30ec7..fe21abd88 100644 --- a/Indicator.enum.h +++ b/Indicator.enum.h @@ -133,6 +133,7 @@ enum ENUM_IDATA_SOURCE_TYPE { IDATA_ICUSTOM, // iCustom: Custom indicator file IDATA_ICUSTOM_LEGACY, // iCustom: Custom, legacy, provided by MT indicator file IDATA_INDICATOR, // OnIndicator: Another indicator as a source of data + IDATA_ONCALCULATE, // OnCalculate: Custom calculation function IDATA_MATH // Math-based indicator }; From 7c25ec1f669efad27f06b4a5d681f0c3c6b91f11 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 16 Oct 2021 16:11:21 +0100 Subject: [PATCH 77/78] Indi_ASI: Uses IDATA_ONCALCULATE mode --- Indicators/Indi_ASI.mqh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index b30a079e3..1e0b9e88c 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -158,13 +158,17 @@ class Indi_ASI : public Indicator { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { - case IDATA_BUILTIN: - _value = Indi_ASI::iASI(GetSymbol(), GetTf(), /*[*/ GetMaximumPriceChanging() /*]*/, _mode, _shift, THIS_PTR); - break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetMaximumPriceChanging() /*]*/, 0, _shift); break; + case IDATA_ONCALCULATE: { + INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(GetSymbol(), GetTf(), + Util::MakeKey("Indi_ASI", GetMaximumPriceChanging())); + _value = + iASIOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, GetMaximumPriceChanging(), _mode, _shift, _cache); + break; + } default: SetUserError(ERR_INVALID_PARAMETER); } From fa43170699b9edf2327dfeb3ea14dbc6d674414d Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 16 Oct 2021 17:33:55 +0100 Subject: [PATCH 78/78] Indicators: Improves GetValue() definition and mode casting --- Indicators/Indi_AC.mqh | 2 +- Indicators/Indi_AD.mqh | 2 +- Indicators/Indi_ADX.mqh | 2 +- Indicators/Indi_ADXW.mqh | 2 +- Indicators/Indi_AMA.mqh | 2 +- Indicators/Indi_AO.mqh | 2 +- Indicators/Indi_ASI.mqh | 5 ++-- Indicators/Indi_ATR.mqh | 2 +- Indicators/Indi_Alligator.mqh | 4 +-- Indicators/Indi_AppliedPrice.mqh | 2 +- Indicators/Indi_BWMFI.mqh | 7 ++--- Indicators/Indi_BWZT.mqh | 2 +- Indicators/Indi_Bands.mqh | 29 +++------------------ Indicators/Indi_BearsPower.mqh | 2 +- Indicators/Indi_BullsPower.mqh | 2 +- Indicators/Indi_CCI.mqh | 2 +- Indicators/Indi_CHO.mqh | 2 +- Indicators/Indi_CHV.mqh | 2 +- Indicators/Indi_ColorBars.mqh | 2 +- Indicators/Indi_ColorCandlesDaily.mqh | 2 +- Indicators/Indi_ColorLine.mqh | 2 +- Indicators/Indi_CustomMovingAverage.mqh | 2 +- Indicators/Indi_DEMA.mqh | 2 +- Indicators/Indi_DeMarker.mqh | 2 +- Indicators/Indi_Demo.mqh | 2 +- Indicators/Indi_DetrendedPrice.mqh | 2 +- Indicators/Indi_Drawer.mqh | 2 +- Indicators/Indi_Envelopes.mqh | 2 +- Indicators/Indi_Force.mqh | 2 +- Indicators/Indi_FractalAdaptiveMA.mqh | 2 +- Indicators/Indi_Fractals.mqh | 4 +-- Indicators/Indi_Gator.mqh | 4 +-- Indicators/Indi_HeikenAshi.mqh | 2 +- Indicators/Indi_Ichimoku.mqh | 2 +- Indicators/Indi_MA.mqh | 2 +- Indicators/Indi_MACD.mqh | 4 +-- Indicators/Indi_MFI.mqh | 2 +- Indicators/Indi_MassIndex.mqh | 2 +- Indicators/Indi_Momentum.mqh | 2 +- Indicators/Indi_OBV.mqh | 2 +- Indicators/Indi_OsMA.mqh | 2 +- Indicators/Indi_Price.mqh | 4 +-- Indicators/Indi_PriceChannel.mqh | 2 +- Indicators/Indi_PriceFeeder.mqh | 2 +- Indicators/Indi_PriceVolumeTrend.mqh | 2 +- Indicators/Indi_RS.mqh | 2 +- Indicators/Indi_RSI.mqh | 2 +- Indicators/Indi_RVI.mqh | 27 ++------------------ Indicators/Indi_RateOfChange.mqh | 2 +- Indicators/Indi_SAR.mqh | 2 +- Indicators/Indi_StdDev.mqh | 2 +- Indicators/Indi_Stochastic.mqh | 34 +------------------------ Indicators/Indi_TEMA.mqh | 2 +- Indicators/Indi_TRIX.mqh | 2 +- Indicators/Indi_UltimateOscillator.mqh | 2 +- Indicators/Indi_VIDYA.mqh | 2 +- Indicators/Indi_VROC.mqh | 2 +- Indicators/Indi_Volumes.mqh | 2 +- Indicators/Indi_WPR.mqh | 2 +- Indicators/Indi_WilliamsAD.mqh | 2 +- Indicators/Indi_ZigZag.mqh | 8 +++--- Indicators/Indi_ZigZagColor.mqh | 2 +- Indicators/Special/Indi_Math.mqh | 2 +- 63 files changed, 79 insertions(+), 155 deletions(-) diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 82d58f1ca..e280631f4 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -98,7 +98,7 @@ class Indi_AC : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index cf8e34b59..b935032f5 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -97,7 +97,7 @@ class Indi_AD : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 3db34ea1b..104c0ca15 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -115,7 +115,7 @@ class Indi_ADX : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = LINE_MAIN_ADX, int _shift = 0) { + virtual double GetValue(int _mode = LINE_MAIN_ADX, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index b833c3278..ee8ac7436 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -215,7 +215,7 @@ class Indi_ADXW : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = LINE_MAIN_ADX, int _shift = 0) { + virtual double GetValue(int _mode = LINE_MAIN_ADX, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index 040dd9b67..1e16b0a81 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -199,7 +199,7 @@ class Indi_AMA : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index f7dfdae45..8d974e9ae 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -101,7 +101,7 @@ class Indi_AO : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index 1e0b9e88c..9e2fa43b4 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -30,7 +30,8 @@ struct ASIParams : IndicatorParams { unsigned int period; double mpc; // Struct constructor. - ASIParams(double _mpc = 300.0, int _shift = 0) : IndicatorParams(INDI_ASI, 1, TYPE_DOUBLE) { + ASIParams(double _mpc = 300.0, int _shift = 0) + : IndicatorParams(INDI_ASI, 1, TYPE_DOUBLE, PERIOD_CURRENT, IDATA_ONCALCULATE) { SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ASI"); mpc = _mpc; @@ -154,7 +155,7 @@ class Indi_ASI : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index cd9a4cfff..72e536663 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -102,7 +102,7 @@ class Indi_ATR : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index 3a402bcd7..9784d0876 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -161,7 +161,7 @@ class Indi_Alligator : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_ALLIGATOR_LINE _mode, int _shift = 0) { + virtual double GetValue(int _mode, int _shift = 0) { #ifdef __MQL4__ if (_mode == 0) { // In MQL4 mode 0 should be treated as mode 1 as Alligator buffers starts from index 1. @@ -175,7 +175,7 @@ class Indi_Alligator : public Indicator { istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_Alligator::iAlligator(GetSymbol(), GetTf(), GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), - GetAppliedPrice(), _mode, _shift, THIS_PTR); + GetAppliedPrice(), (ENUM_ALLIGATOR_LINE)_mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index 9a0effec5..c8fdf1b7b 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -62,7 +62,7 @@ class Indi_AppliedPrice : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index b5fadf2e1..0b192e89d 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -42,11 +42,12 @@ enum ENUM_MFI_COLOR { // Structs. struct BWMFIParams : IndicatorParams { + ENUM_APPLIED_VOLUME ap; // @todo // Struct constructors. BWMFIParams(int _shift = 0) : IndicatorParams(INDI_BWMFI, FINAL_BWMFI_BUFFER_ENTRY, TYPE_DOUBLE) { SetDataValueRange(IDATA_RANGE_MIXED); - SetCustomIndicatorName("Examples\\MarketFacilitationIndex"); shift = _shift; + SetCustomIndicatorName("Examples\\MarketFacilitationIndex"); }; BWMFIParams(BWMFIParams &_params, ENUM_TIMEFRAMES _tf) { THIS_REF = _params; @@ -111,13 +112,13 @@ class Indi_BWMFI : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_BWMFI_BUFFER _mode = BWMFI_BUFFER, int _shift = 0) { + virtual double GetValue(int _mode = BWMFI_BUFFER, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = _value = iBWMFI(GetSymbol(), GetTf(), _shift, _mode, THIS_PTR); + _value = Indi_BWMFI::iBWMFI(GetSymbol(), GetTf(), _shift, (ENUM_BWMFI_BUFFER)_mode, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ VOLUME_TICK /*]*/, diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index c85064f30..f57d94355 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -159,7 +159,7 @@ class Indi_BWZT : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 80accbdd2..36ec12abd 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -240,14 +240,14 @@ class Indi_Bands : public Indicator { * Note that in MQL5 Applied Price must be passed as the last parameter * (before mode and shift). */ - double GetValue(ENUM_BANDS_LINE _mode, int _shift = 0) { + virtual double GetValue(int _mode = BAND_BASE, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_Bands::iBands(GetSymbol(), GetTf(), GetPeriod(), GetDeviation(), GetBandsShift(), - GetAppliedPrice(), _mode, _shift, THIS_PTR); + GetAppliedPrice(), (ENUM_BANDS_LINE)_mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, /* [ */ GetPeriod(), @@ -256,7 +256,7 @@ class Indi_Bands : public Indicator { case IDATA_INDICATOR: // Calculating bands value from specified indicator. _value = Indi_Bands::iBandsOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), GetDeviation(), - GetBandsShift(), _mode, _shift, THIS_PTR); + GetBandsShift(), (ENUM_BANDS_LINE)_mode, _shift, THIS_PTR); break; } istate.is_changed = false; @@ -264,29 +264,6 @@ class Indi_Bands : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue((ENUM_BANDS_LINE)_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index 9a3be5ea3..1732a0c90 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -103,7 +103,7 @@ class Indi_BearsPower : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index e905c8114..c1cf5ac9a 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -103,7 +103,7 @@ class Indi_BullsPower : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index b7f59c045..27a0cb14a 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -168,7 +168,7 @@ class Indi_CCI : public Indicator { * Note that in MQL5 Applied Price must be passed as the last parameter * (before mode and shift). */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 0e3a3b421..18a54a404 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -166,7 +166,7 @@ class Indi_CHO : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 035fce96a..2a903b142 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -162,7 +162,7 @@ class Indi_CHV : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 10098517a..9ec6677dc 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -112,7 +112,7 @@ class Indi_ColorBars : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index a83d64091..001c6e518 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -109,7 +109,7 @@ class Indi_ColorCandlesDaily : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 4d81bde62..2b154bf0c 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -171,7 +171,7 @@ class Indi_ColorLine : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index a8520dc45..78f9114c6 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -66,7 +66,7 @@ class Indi_CustomMovingAverage : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 26f1ec6b0..e27ef8a1a 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -168,7 +168,7 @@ class Indi_DEMA : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index ba5e682f0..3a63bedc1 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -101,7 +101,7 @@ class Indi_DeMarker : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index 0d0d0ba83..b0a6880a5 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -72,7 +72,7 @@ class Indi_Demo : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { double _value = Indi_Demo::iDemo(GetSymbol(), GetTf(), _shift, THIS_PTR); istate.is_ready = true; istate.is_changed = false; diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 7b888bf3f..d3d9e9b68 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -115,7 +115,7 @@ class Indi_DetrendedPrice : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index fee405272..ad16647bf 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -169,7 +169,7 @@ class Indi_Drawer : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index bd5439826..de7ac1da7 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -196,7 +196,7 @@ class Indi_Envelopes : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index a4a87e93f..1b69fa76e 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -117,7 +117,7 @@ class Indi_Force : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 715357c65..e47f56aa7 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -133,7 +133,7 @@ class Indi_FrAMA : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index b84f2c0c9..87e5e097e 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -101,13 +101,13 @@ class Indi_Fractals : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_LO_UP_LINE _mode, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = _value = Indi_Fractals::iFractals(GetSymbol(), GetTf(), _mode, _shift, THIS_PTR); + _value = _value = Indi_Fractals::iFractals(GetSymbol(), GetTf(), (ENUM_LO_UP_LINE)_mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, _shift); diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index 4984d1ca7..78f74fc98 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -169,7 +169,7 @@ class Indi_Gator : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_GATOR_HISTOGRAM _mode, int _shift = 0) { + virtual double GetValue(int _mode, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { @@ -177,7 +177,7 @@ class Indi_Gator : public Indicator { istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_Gator::iGator(GetSymbol(), GetTf(), GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), GetAppliedPrice(), - _mode, _shift, THIS_PTR); + (ENUM_GATOR_HISTOGRAM)_mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /**/ diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index df4236589..eb6e18b06 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -195,7 +195,7 @@ class Indi_HeikenAshi : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_HA_MODE _mode, int _shift = 0) { + virtual double GetValue(int _mode = HA_OPEN, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index c303cf214..b2a70f6de 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -141,7 +141,7 @@ class Indi_Ichimoku : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_ICHIMOKU_LINE _mode, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index 3b439255d..12888ee03 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -627,7 +627,7 @@ class Indi_MA : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index 8bc246a89..56c718d88 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -114,14 +114,14 @@ class Indi_MACD : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_SIGNAL_LINE _mode = LINE_MAIN, int _shift = 0) { + virtual double GetValue(int _mode = LINE_MAIN, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_MACD::iMACD(GetSymbol(), GetTf(), GetEmaFastPeriod(), GetEmaSlowPeriod(), GetSignalPeriod(), - GetAppliedPrice(), _mode, _shift, THIS_PTR); + GetAppliedPrice(), (ENUM_SIGNAL_LINE)_mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index 1b4995e62..a4bc99d6f 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -111,7 +111,7 @@ class Indi_MFI : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index 4d84ec872..0dc8e32e1 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -152,7 +152,7 @@ class Indi_MassIndex : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 02c51401a..7fe181e88 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -140,7 +140,7 @@ class Indi_Momentum : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 6740e8630..fa6568bb6 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -116,7 +116,7 @@ class Indi_OBV : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index c215c6589..09f64e4d3 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -111,7 +111,7 @@ class Indi_OsMA : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Price.mqh b/Indicators/Indi_Price.mqh index b73b0f8b1..e63781147 100644 --- a/Indicators/Indi_Price.mqh +++ b/Indicators/Indi_Price.mqh @@ -75,8 +75,8 @@ class Indi_Price : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_APPLIED_PRICE _ap, int _shift = 0) { - double _value = ChartStatic::iPrice(_ap, GetSymbol(), GetTf(), _shift); + virtual double GetValue(int _mode = PRICE_TYPICAL, int _shift = 0) { + double _value = ChartStatic::iPrice((ENUM_APPLIED_PRICE)_mode, GetSymbol(), GetTf(), _shift); istate.is_ready = true; istate.is_changed = false; return _value; diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index 8f87a7996..5d9e497d6 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -56,7 +56,7 @@ class Indi_PriceChannel : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index ffb341cfa..ea078ffcb 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -75,7 +75,7 @@ class Indi_PriceFeeder : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_APPLIED_PRICE _ap, int _shift = 0) { + virtual double GetValue(ENUM_APPLIED_PRICE _ap, int _shift = 0) { int data_size = ArraySize(iparams.price_data); if (_shift >= data_size || _shift < 0) return DBL_MIN; diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index 5dd2d502b..b8c9efcac 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -120,7 +120,7 @@ class Indi_PriceVolumeTrend : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index a1b9c815a..800b9ef84 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -79,7 +79,7 @@ class Indi_RS : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index d4c520a3c..84453e216 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -310,7 +310,7 @@ class Indi_RSI : public Indicator { * Note that in MQL5 Applied Price must be passed as the last parameter * (before mode and shift). */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index abf3373a8..419385ddf 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -103,13 +103,13 @@ class Indi_RVI : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_SIGNAL_LINE _mode = LINE_MAIN, int _shift = 0) { + virtual double GetValue(int _mode = LINE_MAIN, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { case IDATA_BUILTIN: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; - _value = Indi_RVI::iRVI(GetSymbol(), GetTf(), GetPeriod(), _mode, _shift, THIS_PTR); + _value = Indi_RVI::iRVI(GetSymbol(), GetTf(), GetPeriod(), (ENUM_SIGNAL_LINE)_mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/, @@ -123,29 +123,6 @@ class Indi_RVI : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue((ENUM_SIGNAL_LINE)_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - /** * Returns the indicator's entry value. */ diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index 8b31c29c6..95f6208b3 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -109,7 +109,7 @@ class Indi_RateOfChange : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 7c6b5b3ef..8ee26d8c2 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -102,7 +102,7 @@ class Indi_SAR : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index b2669b811..6ab6024fc 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -212,7 +212,7 @@ class Indi_StdDev : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 90c45f4dd..fe6d8972b 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -119,7 +119,7 @@ class Indi_Stochastic : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_SIGNAL_LINE _mode = LINE_MAIN, int _shift = 0) { + virtual double GetValue(int _mode = LINE_MAIN, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { @@ -140,38 +140,6 @@ class Indi_Stochastic : public Indicator { return _value; } - /** - * Returns the indicator's struct value. - */ - IndicatorDataEntry GetEntry(int _shift = 0) { - long _bar_time = GetBarTime(_shift); - unsigned int _position; - IndicatorDataEntry _entry(iparams.GetMaxModes()); - if (idata.KeyExists(_bar_time, _position)) { - _entry = idata.GetByPos(_position); - } else { - _entry.timestamp = GetBarTime(_shift); - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - _entry.values[_mode] = GetValue((ENUM_SIGNAL_LINE)_mode, _shift); - } - _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry)); - if (_entry.IsValid()) { - _entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType())); - idata.Add(_entry, _bar_time); - } - } - return _entry; - } - - /** - * Returns the indicator's entry value. - */ - MqlParam GetEntryValue(int _shift = 0, int _mode = 0) { - MqlParam _param = {TYPE_DOUBLE}; - GetEntry(_shift).values[_mode].Get(_param.double_value); - return _param; - } - /** * Checks if indicator entry values are valid. */ diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index 3c1708cbc..8d49fbfcf 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -126,7 +126,7 @@ class Indi_TEMA : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index 44095d48d..0f67564b7 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -127,7 +127,7 @@ class Indi_TRIX : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 462eb4f17..eb891c964 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -208,7 +208,7 @@ class Indi_UltimateOscillator : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index c8a91b4cf..b2a54fcfb 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -147,7 +147,7 @@ class Indi_VIDYA : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index d8c99ca10..b6ff5f053 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -130,7 +130,7 @@ class Indi_VROC : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 812facaab..5862fecde 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -124,7 +124,7 @@ class Indi_Volumes : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index a6d72aebf..d478065f7 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -100,7 +100,7 @@ class Indi_WPR : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index b7f36749d..5b553f2d4 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -123,7 +123,7 @@ class Indi_WilliamsAD : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index a44040012..dccdf6070 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -335,18 +335,18 @@ class Indi_ZigZag : public Indicator { /** * Returns the indicator's value. */ - double GetValue(ENUM_ZIGZAG_LINE _mode, int _shift = 0) { + virtual double GetValue(int _mode, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { case IDATA_BUILTIN: - _value = Indi_ZigZag::iZigZag(GetSymbol(), GetTf(), GetDepth(), GetDeviation(), GetBackstep(), _mode, _shift, - THIS_PTR); + _value = Indi_ZigZag::iZigZag(GetSymbol(), GetTf(), GetDepth(), GetDeviation(), GetBackstep(), + (ENUM_ZIGZAG_LINE)_mode, _shift, THIS_PTR); break; case IDATA_ICUSTOM: istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle; _value = Indi_ZigZag::iCustomZigZag(GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), GetDepth(), - GetDeviation(), GetBackstep(), _mode, _shift, THIS_PTR); + GetDeviation(), GetBackstep(), (ENUM_ZIGZAG_LINE)_mode, _shift, THIS_PTR); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 9b6ba986d..0b8825bc2 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -62,7 +62,7 @@ class Indi_ZigZagColor : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) { diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 5aa0f7a6e..faba5f773 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -91,7 +91,7 @@ class Indi_Math : public Indicator { /** * Returns the indicator's value. */ - double GetValue(int _mode = 0, int _shift = 0) { + virtual double GetValue(int _mode = 0, int _shift = 0) { ResetLastError(); double _value = EMPTY_VALUE; switch (iparams.idstype) {