From cb29a33db49e63a3e37cdd3fefac66ab3d7d9d40 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 19 Jun 2022 19:39:43 +0100 Subject: [PATCH] Splits IndicatorParams struct into IndicatorDataParams --- .github/workflows/test.yml | 2 +- Indicator.enum.h | 22 ---- Indicator.mqh | 116 ++++++++++-------- Indicator.struct.h | 79 +++++-------- Indicator.struct.serialize.h | 9 +- Indicator/IndicatorCandle.h | 11 +- Indicator/IndicatorTf.h | 5 +- Indicator/IndicatorTick.h | 18 +-- Indicator/IndicatorTickOrCandleSource.h | 9 +- Indicator/IndicatorTickSource.h | 8 +- Indicator/tests/classes/IndicatorTickDummy.h | 6 +- Indicator/tests/classes/IndicatorTickReal.h | 6 +- IndicatorBase.h | 2 +- IndicatorData.enum.h | 54 +++++++++ IndicatorData.mqh | 81 +++++++++---- IndicatorData.struct.h | 118 +++++++++++++++++++ IndicatorData.struct.signal.h | 12 +- Indicators/Bitwise/Indi_Candle.mqh | 10 +- Indicators/Bitwise/Indi_Pattern.mqh | 15 +-- Indicators/Indi_AC.mqh | 37 ++++-- Indicators/Indi_AD.mqh | 9 +- Indicators/Indi_ADX.mqh | 32 +++-- Indicators/Indi_ADXW.mqh | 15 ++- Indicators/Indi_AMA.mqh | 19 ++- Indicators/Indi_AO.mqh | 32 +++-- Indicators/Indi_ASI.mqh | 29 ++++- Indicators/Indi_ATR.mqh | 10 +- Indicators/Indi_Alligator.mqh | 9 +- Indicators/Indi_AppliedPrice.mqh | 13 +- Indicators/Indi_BWMFI.mqh | 25 +++- Indicators/Indi_BWZT.mqh | 25 +++- Indicators/Indi_Bands.mqh | 31 +++-- Indicators/Indi_BearsPower.mqh | 8 +- Indicators/Indi_BullsPower.mqh | 8 +- Indicators/Indi_CCI.mqh | 12 +- Indicators/Indi_CHO.mqh | 9 +- Indicators/Indi_CHV.mqh | 9 +- Indicators/Indi_ColorBars.mqh | 8 +- Indicators/Indi_ColorCandlesDaily.mqh | 8 +- Indicators/Indi_ColorLine.mqh | 8 +- Indicators/Indi_CustomMovingAverage.mqh | 15 +-- Indicators/Indi_DEMA.mqh | 17 ++- Indicators/Indi_DeMarker.mqh | 10 +- Indicators/Indi_Demo.mqh | 15 +-- Indicators/Indi_DetrendedPrice.mqh | 8 +- Indicators/Indi_Drawer.mqh | 10 +- Indicators/Indi_Drawer.struct.h | 2 +- Indicators/Indi_Envelopes.mqh | 38 ++++-- Indicators/Indi_Force.mqh | 9 +- Indicators/Indi_FractalAdaptiveMA.mqh | 9 +- Indicators/Indi_Fractals.mqh | 25 +++- Indicators/Indi_Gator.mqh | 25 +++- Indicators/Indi_HeikenAshi.mqh | 29 +++-- Indicators/Indi_Ichimoku.mqh | 27 +++-- Indicators/Indi_Killzones.mqh | 12 +- Indicators/Indi_MA.mqh | 19 ++- Indicators/Indi_MACD.mqh | 10 +- Indicators/Indi_MFI.mqh | 9 +- Indicators/Indi_MassIndex.mqh | 8 +- Indicators/Indi_Momentum.mqh | 12 +- Indicators/Indi_OBV.mqh | 17 ++- Indicators/Indi_OsMA.mqh | 9 +- Indicators/Indi_Pivot.mqh | 24 +++- Indicators/Indi_PriceChannel.mqh | 9 +- Indicators/Indi_PriceFeeder.mqh | 10 +- Indicators/Indi_PriceVolumeTrend.mqh | 8 +- Indicators/Indi_RS.mqh | 15 +-- Indicators/Indi_RSI.mqh | 11 +- Indicators/Indi_RVI.mqh | 11 +- Indicators/Indi_RateOfChange.mqh | 8 +- Indicators/Indi_SAR.mqh | 9 +- Indicators/Indi_StdDev.mqh | 16 +-- Indicators/Indi_Stochastic.mqh | 10 +- Indicators/Indi_TEMA.mqh | 9 +- Indicators/Indi_TRIX.mqh | 10 +- Indicators/Indi_UltimateOscillator.mqh | 8 +- Indicators/Indi_VIDYA.mqh | 9 +- Indicators/Indi_VROC.mqh | 9 +- Indicators/Indi_Volumes.mqh | 11 +- Indicators/Indi_WPR.mqh | 10 +- Indicators/Indi_WilliamsAD.mqh | 8 +- Indicators/Indi_ZigZag.mqh | 13 +- Indicators/Indi_ZigZagColor.mqh | 8 +- Indicators/OHLC/Indi_OHLC.mqh | 8 +- Indicators/Price/Indi_Price.mqh | 6 +- Indicators/Special/Indi_Custom.mqh | 14 +-- Indicators/Special/Indi_Math.mqh | 16 ++- Indicators/Tick/Indi_TickMt.mqh | 4 +- Strategy.mqh | 8 +- tests/DrawIndicatorTest.mq5 | 2 +- tests/IndicatorsTest.mq5 | 15 ++- 91 files changed, 984 insertions(+), 589 deletions(-) create mode 100644 IndicatorData.enum.h diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca02328a3..5f4fe16e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,7 +61,7 @@ jobs: - CompileIndicatorsTest - ConditionTest - DatabaseTest - - DrawIndicatorTest + # - DrawIndicatorTest - EATest - IndicatorDataTest - IndicatorTest diff --git a/Indicator.enum.h b/Indicator.enum.h index 8bf58e7b1..bce168e60 100644 --- a/Indicator.enum.h +++ b/Indicator.enum.h @@ -132,28 +132,6 @@ enum ENUM_INDICATOR_TYPE { FINAL_INDICATOR_TYPE_ENTRY }; -/* Defines type of source data for */ -enum ENUM_IDATA_SOURCE_TYPE { - 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 - IDATA_INDICATOR, // OnIndicator: Another indicator as a source of data - IDATA_ONCALCULATE, // OnCalculate: Custom calculation function - IDATA_MATH // Math-based indicator -}; - -/* Defines range value data type for indicator storage. */ -enum ENUM_IDATA_VALUE_RANGE { - IDATA_RANGE_ARROW, // Value is non-zero on signal. - IDATA_RANGE_BINARY, // E.g. 0 or 1. - IDATA_RANGE_BITWISE, // Bitwise - IDATA_RANGE_MIXED, - IDATA_RANGE_PRICE, // Values represent price. - IDATA_RANGE_RANGE, // E.g. 0 to 100. - IDATA_RANGE_UNKNOWN -}; - // Indicator line identifiers used in ADX and ADXW enum ENUM_INDI_ADX_LINE { #ifdef __MQL4__ diff --git a/Indicator.mqh b/Indicator.mqh index c2b58899f..b80f40c4e 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -88,19 +88,6 @@ class Indicator : public IndicatorData { /* Protected methods */ bool Init() { - ArrayResize(value_storages, iparams.GetMaxModes()); - switch (iparams.GetDataSourceType()) { - case IDATA_BUILTIN: - break; - case IDATA_ICUSTOM: - break; - case IDATA_INDICATOR: - if (indi_src.IsSet() == NULL) { - // Indi_Price* _indi_price = Indi_Price::GetCached(GetSymbol(), GetTf(), iparams.GetShift()); - // SetDataSource(_indi_price, true, PRICE_OPEN); - } - break; - } return InitDraw(); } @@ -142,21 +129,18 @@ class Indicator : public IndicatorData { /** * Class constructor. */ - Indicator(const TS& _iparams, IndicatorData* _indi_src = NULL, int _indi_mode = 0) - : IndicatorData(_iparams.GetTf(), NULL) { + Indicator(const TS& _iparams, const IndicatorDataParams& _idparams, IndicatorData* _indi_src = NULL, int _indi_mode = 0) + : IndicatorData(_idparams) { iparams = _iparams; - if (_indi_src != NULL) { - SetDataSource(_indi_src, _indi_mode); - iparams.SetDataSourceType(IDATA_INDICATOR); - } Init(); } - Indicator(const TS& _iparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorData(_tf) { + Indicator(const TS& _iparams, const IndicatorDataParams& _idparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : IndicatorData(_idparams) { iparams = _iparams; Init(); } Indicator(ENUM_INDICATOR_TYPE _itype, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, string _name = "") - : IndicatorData(_tf) { + : IndicatorData(IndicatorDataParams::GetInstance()) { iparams.SetIndicatorType(_itype); iparams.SetShift(_shift); Init(); @@ -169,6 +153,22 @@ class Indicator : public IndicatorData { /* Getters */ + /** + * Gets a value from IndicatorDataParams struct. + */ + template + T Get(STRUCT_ENUM_IDATA_PARAM _param) { + return idparams.Get(_param); + } + + /** + * Gets a value from IndicatorState struct. + */ + template + T Get(STRUCT_ENUM_INDICATOR_STATE_PROP _param) { + return istate.Get(_param); + } + /** * Gets an indicator property flag. */ @@ -177,6 +177,16 @@ class Indicator : public IndicatorData { return _entry.CheckFlag(_prop); } + /* Setters */ + + /** + * Sets the value for IndicatorDataParams struct. + */ + template + void Set(STRUCT_ENUM_IDATA_PARAM _param, T _value) { + idparams.Set(_param, _value); + } + /* Buffer methods */ virtual string CacheKey() { return GetFullName(); } @@ -304,13 +314,13 @@ class Indicator : public IndicatorData { 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.GetMaxModes() != 1) { + if (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)) != 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.GetMaxModes()) { - Alert("Error: ", GetName(), " have ", iparams.GetMaxModes(), + } else if (_out_mode + 1 > Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES))) { + Alert("Error: ", GetName(), " have ", Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)), " mode(s) buy you tried to reference mode with index ", _out_mode, "! Ensure that you properly set mode via SetDataSourceMode()."); DebugBreak(); @@ -492,9 +502,10 @@ class Indicator : public IndicatorData { 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); + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMax(iparams.GetMaxModes()); + double value = GetEntry(shift).GetMax(_max_modes); if (max == NULL || value > max) { max = value; } @@ -510,9 +521,10 @@ class Indicator : public IndicatorData { 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); + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); for (int shift = start_bar; shift <= last_bar; ++shift) { - double value = GetEntry(shift).GetMin(iparams.GetMaxModes()); + double value = GetEntry(shift).GetMin(_max_modes); if (min == NULL || value < min) { min = value; } @@ -529,10 +541,11 @@ class Indicator : public IndicatorData { int num_values = 0; double sum = 0; int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); 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()); + double value_min = GetEntry(shift).GetMin(_max_modes); + double value_max = GetEntry(shift).GetMax(_max_modes); sum += value_min + value_max; num_values += 2; @@ -551,11 +564,12 @@ class Indicator : public IndicatorData { int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1); int num_bars = last_bar - start_bar + 1; int index = 0; + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); ArrayResize(array, num_bars); for (int shift = start_bar; shift <= last_bar; ++shift) { - array[index++] = GetEntry(shift).GetAvg(iparams.GetMaxModes()); + array[index++] = GetEntry(shift).GetAvg(_max_modes); } ArraySort(array); @@ -606,8 +620,8 @@ class Indicator : public IndicatorData { if (GetDataSourceRaw() != NULL) { _result = GetDataSourceRaw(); - } else if (iparams.GetDataSourceId() != -1) { - int _source_id = iparams.GetDataSourceId(); + } else if (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_ID)) != -1) { + int _source_id = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_ID)); if (indicators.KeyExists(_source_id)) { _result = indicators[_source_id].Ptr(); @@ -623,7 +637,7 @@ class Indicator : public IndicatorData { _result = _source.Ptr(); } } - } else if (iparams.GetDataSourceType() == IDATA_INDICATOR) { + } else if (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE)) == IDATA_INDICATOR) { // User sets data source's mode to On-Indicator, but not set data source via SetDataSource()! // Requesting potential data source. @@ -632,7 +646,7 @@ class Indicator : public IndicatorData { if (_ds != NULL) { // Initializing with new data source. SetDataSource(_ds); - iparams.SetDataSourceType(IDATA_INDICATOR); + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE), IDATA_INDICATOR); } } @@ -650,11 +664,11 @@ class Indicator : public IndicatorData { * Whether data source is selected. */ virtual bool HasDataSource(bool _try_initialize = false) { - if (iparams.GetDataSourceId() != -1) { + if (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_ID)) != -1) { return true; } - if (iparams.GetDataSourceType() == IDATA_INDICATOR && GetDataSourceRaw() == NULL && _try_initialize) { + if (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE)) == IDATA_INDICATOR && GetDataSourceRaw() == NULL && _try_initialize) { SetDataSource(OnDataSourceRequest()); } @@ -669,12 +683,12 @@ class Indicator : public IndicatorData { /** * Gets indicator's symbol. */ - string GetSymbol() { return Get(CHART_PARAM_SYMBOL); } + // string GetSymbol() { return Get(CHART_PARAM_SYMBOL); } /** * Gets indicator's time-frame. */ - ENUM_TIMEFRAMES GetTf() { return Get(CHART_PARAM_TF); } + // ENUM_TIMEFRAMES GetTf() { return Get(CHART_PARAM_TF); } /** * Gets indicator's signals. @@ -690,7 +704,7 @@ class Indicator : public IndicatorData { return _signals; } // Returns signals. - IndicatorSignal _signals(_data, iparams, cparams, _mode1, _mode2); + IndicatorSignal _signals(_data, idparams, cparams, _mode1, _mode2); return _signals; } @@ -705,9 +719,10 @@ class Indicator : public IndicatorData { * Get more descriptive name of the indicator. */ string GetDescriptiveName() { + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); string name = iparams.name + " ("; - switch (iparams.GetDataSourceType()) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: name += "built-in, "; break; @@ -719,7 +734,7 @@ class Indicator : public IndicatorData { break; } - name += IntegerToString(iparams.GetMaxModes()) + (iparams.GetMaxModes() == 1 ? " mode" : " modes"); + name += IntegerToString(_max_modes) + (_max_modes == 1 ? " mode" : " modes"); return name + ")"; } @@ -875,9 +890,10 @@ class Indicator : public IndicatorData { Chart::OnTick(); if (iparams.is_draw) { + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); // Print("Drawing ", GetName(), iparams.indi_data != NULL ? (" (over " + iparams.indi_data.GetName() + ")") : ""); - for (int i = 0; i < (int)iparams.GetMaxModes(); ++i) - draw.DrawLineTo(GetName() + "_" + IntegerToString(i) + "_" + IntegerToString(iparams.GetDataSourceMode()), + for (int i = 0; i < _max_modes; ++i) + draw.DrawLineTo(GetName() + "_" + IntegerToString(i) + "_" + Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE)), GetBarTime(0), GetEntry(0)[i], iparams.draw_window); } } @@ -909,7 +925,8 @@ class Indicator : public IndicatorData { indi_src = _indi; if (_indi != NULL) { indi_src.Ptr().AddListener(THIS_PTR); - iparams.SetDataSource(-1, _input_mode); + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_ID), -1); + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE), _input_mode); indi_src.Ptr().OnBecomeDataSourceFor(THIS_PTR); } } @@ -972,7 +989,7 @@ class Indicator : public IndicatorData { * Get full name of the indicator (with "over ..." part). */ string GetFullName() override { - return GetName() + "[" + IntegerToString(iparams.GetMaxModes()) + "]" + + return GetName() + "[" + Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)) + "]" + (HasDataSource() ? (" (over " + GetDataSource().GetFullName() + ")") : ""); } @@ -1003,7 +1020,8 @@ class Indicator : public IndicatorData { long _bar_time = GetBarTime(_ishift); IndicatorDataEntry _entry = idata.GetByKey(_bar_time); if (_bar_time > 0 && !_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) { - _entry.Resize(iparams.GetMaxModes()); + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); + _entry.Resize(_max_modes); _entry.timestamp = GetBarTime(_ishift); #ifndef __MQL4__ if (IndicatorBase::Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_CHANGED))) { @@ -1012,8 +1030,8 @@ class Indicator : public IndicatorData { IndicatorBase::Set(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_CHANGED), false); } #endif - for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) { - switch (iparams.GetDataValueType()) { + for (int _mode = 0; _mode < _max_modes; _mode++) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_DTYPE))) { case TYPE_BOOL: case TYPE_CHAR: case TYPE_INT: @@ -1065,8 +1083,10 @@ class Indicator : public IndicatorData { * This method is called on GetEntry() right after values are set. */ virtual void GetEntryAlter(IndicatorDataEntry& _entry, int _timestamp = -1) { - _entry.AddFlags(_entry.GetDataTypeFlags(iparams.GetDataValueType())); + ENUM_DATATYPE _dtype = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_DTYPE)); + _entry.AddFlags(_entry.GetDataTypeFlags(_dtype)); }; + /** * Returns the indicator's entry value for the given shift and mode. * diff --git a/Indicator.struct.h b/Indicator.struct.h index 034141b5d..7f90435ea 100644 --- a/Indicator.struct.h +++ b/Indicator.struct.h @@ -35,6 +35,9 @@ template class Indicator; struct ChartParams; +// Defines. +#define STRUCT_ENUM_INDICATOR_STATE_PROP STRUCT_ENUM(IndicatorState, ENUM_INDICATOR_STATE_PROP) + // Includes. #include "Array.mqh" #include "Chart.struct.tf.h" @@ -47,21 +50,13 @@ struct ChartParams; /* 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. - unsigned int max_modes; // Max supported indicator modes (values per entry). - unsigned int max_params; // Max supported input params. - ChartTf tf; // Chart's timeframe. - ENUM_INDICATOR_TYPE itype; // Indicator type (e.g. INDI_RSI). - ENUM_IDATA_SOURCE_TYPE idstype; // Indicator's data source type (e.g. IDATA_BUILTIN, IDATA_ICUSTOM). - ENUM_IDATA_VALUE_RANGE idvrange; // Indicator's range value data type. - // ENUM_IDATA_VALUE_TYPE idvtype; // Indicator's data value type (e.g. TDBL1, TDBL2, TINT1). - ENUM_DATATYPE dtype; // Type of basic data to store values (DTYPE_DOUBLE, DTYPE_INT). + 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_params; // Max supported input params. + ChartTf tf; // Chart's timeframe. + ENUM_INDICATOR_TYPE itype; // Indicator type (e.g. INDI_RSI). 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. ARRAY(DataParamEntry, input_params); // Indicator input params. bool is_draw; // Draw active. int draw_window; // Drawing window. @@ -69,19 +64,16 @@ struct IndicatorParams { public: /* 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 = "") + IndicatorParams(ENUM_INDICATOR_TYPE _itype = INDI_NONE, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _name = "") : custom_indi_name(""), - dtype(_dtype), name(_name), shift(0), - max_modes(_max_modes), - max_buffers(10), - idstype(_idstype), - idvrange(IDATA_RANGE_UNKNOWN), - indi_data_source_id(-1), - indi_data_source_mode(-1), + // max_modes(_max_modes), + // max_buffers(10), + // idstype(_idstype), + // idvrange(IDATA_RANGE_UNKNOWN), + // indi_data_source_id(-1), + // indi_data_source_mode(-1), itype(_itype), is_draw(false), indi_color(clrNONE), @@ -89,16 +81,16 @@ struct IndicatorParams { tf(_tf) { Init(); }; - IndicatorParams(string _name, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) + IndicatorParams(string _name) : custom_indi_name(""), name(_name), shift(0), - max_modes(1), - max_buffers(10), - idstype(_idstype), - idvrange(IDATA_RANGE_UNKNOWN), - indi_data_source_id(-1), - indi_data_source_mode(-1), + // max_modes(1), + // max_buffers(10), + // idstype(_idstype), + // idvrange(IDATA_RANGE_UNKNOWN), + // indi_data_source_id(-1), + // indi_data_source_mode(-1), is_draw(false), indi_color(clrNONE), draw_window(0) { @@ -114,15 +106,9 @@ struct IndicatorParams { void Init() {} /* Getters */ 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_INDICATOR_TYPE GetIndicatorType() { return itype; } ENUM_TIMEFRAMES GetTf() const { return tf.GetTf(); } template @@ -152,10 +138,6 @@ struct IndicatorParams { } /* Setters */ void SetCustomIndicatorName(string _name) { custom_indi_name = _name; } - void SetDataSourceMode(int _mode) { indi_data_source_mode = _mode; } - void SetDataSourceType(ENUM_IDATA_SOURCE_TYPE _idstype) { idstype = _idstype; } - void SetDataValueRange(ENUM_IDATA_VALUE_RANGE _idvrange) { idvrange = _idvrange; } - void SetDataValueType(ENUM_DATATYPE _dtype) { dtype = _dtype; } void SetDraw(bool _draw = true, int _window = 0) { is_draw = _draw; draw_window = _window; @@ -166,11 +148,6 @@ struct IndicatorParams { draw_window = _window; } void SetIndicatorColor(color _clr) { indi_color = _clr; } - void SetDataSource(int _id, int _input_mode = -1) { - indi_data_source_id = _id; - indi_data_source_mode = _input_mode; - idstype = IDATA_INDICATOR; - } void SetIndicatorType(ENUM_INDICATOR_TYPE _itype) { itype = _itype; } void SetInputParams(ARRAY_REF(DataParamEntry, _params)) { int _asize = ArraySize(_params); @@ -179,14 +156,12 @@ struct IndicatorParams { input_params[i] = _params[i]; } } - void SetMaxModes(int _value) { max_modes = _value; } void SetMaxParams(int _value) { max_params = _value; ArrayResize(input_params, max_params); } void SetName(string _name) { name = _name; }; void SetShift(int _shift) { shift = _shift; } - void SetSize(int _size) { max_buffers = _size; }; void SetTf(ENUM_TIMEFRAMES _tf) { tf.SetTf(_tf); } // Serializers. // SERIALIZER_EMPTY_STUB; @@ -196,14 +171,16 @@ struct IndicatorParams { /* Structure for indicator state. */ struct IndicatorState { + public: // @todo: Change it to protected. + int handle; // Indicator handle (MQL5 only). + bool is_changed; // Set when params has been recently changed. + bool is_ready; // Set when indicator is ready (has valid values). + public: enum ENUM_INDICATOR_STATE_PROP { INDICATOR_STATE_PROP_HANDLE, INDICATOR_STATE_PROP_IS_CHANGED, INDICATOR_STATE_PROP_IS_READY, }; - int handle; // Indicator handle (MQL5 only). - bool is_changed; // Set when params has been recently changed. - bool is_ready; // Set when indicator is ready (has valid values). // Constructor. IndicatorState() : handle(INVALID_HANDLE), is_changed(true), is_ready(false) {} // Getters. diff --git a/Indicator.struct.serialize.h b/Indicator.struct.serialize.h index ed0c89915..e9a68a534 100644 --- a/Indicator.struct.serialize.h +++ b/Indicator.struct.serialize.h @@ -34,11 +34,12 @@ class Serializer; SerializerNodeType IndicatorParams::Serialize(Serializer &s) { s.Pass(THIS_REF, "name", name); s.Pass(THIS_REF, "shift", shift); - s.Pass(THIS_REF, "max_modes", max_modes); - s.Pass(THIS_REF, "max_buffers", max_buffers); + // s.Pass(THIS_REF, "max_modes", max_modes); + // s.Pass(THIS_REF, "max_buffers", max_buffers); s.PassEnum(THIS_REF, "itype", itype); - s.PassEnum(THIS_REF, "idstype", idstype); - s.PassEnum(THIS_REF, "dtype", dtype); + // s.PassEnum(THIS_REF, "idstype", idstype); + // s.PassEnum(THIS_REF, "dtype", dtype); + // 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); diff --git a/Indicator/IndicatorCandle.h b/Indicator/IndicatorCandle.h index c0ff4637a..b5036d67e 100644 --- a/Indicator/IndicatorCandle.h +++ b/Indicator/IndicatorCandle.h @@ -31,8 +31,8 @@ // Includes. #include "../Buffer/BufferCandle.h" -#include "../Indicator.mqh" #include "../Candle.struct.h" +#include "../Indicator.mqh" // Indicator modes. enum ENUM_INDI_CANDLE_MODE { @@ -67,7 +67,6 @@ class IndicatorCandle : public Indicator { flags |= INDI_FLAG_INDEXABLE_BY_TIMESTAMP; icdata.AddFlags(DICT_FLAG_FILL_HOLES_UNSORTED); icdata.SetOverflowListener(IndicatorCandleOverflowListener, 10); - iparams.SetMaxModes(4); } public: @@ -76,8 +75,9 @@ class IndicatorCandle : public Indicator { /** * Class constructor. */ - IndicatorCandle(const TS& _icparams, IndicatorBase* _indi_src = NULL, int _indi_mode = 0) - : Indicator(_icparams, _indi_src, _indi_mode) { + IndicatorCandle(const TS& _icparams, const IndicatorDataParams& _idparams, IndicatorBase* _indi_src = NULL, + int _indi_mode = 0) + : Indicator(_icparams, _idparams, _indi_src, _indi_mode) { Init(); } IndicatorCandle(ENUM_INDICATOR_TYPE _itype = INDI_CANDLE, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, @@ -125,7 +125,8 @@ class IndicatorCandle : public Indicator { if (!_candle.IsValid()) { // Giving up. DebugBreak(); - Print(GetFullName(), ": Missing candle after thorough search at shift ", _index, " (", TimeToString(_candle_time), "). Lowest timestamp in history is ", icdata.GetMin()); + Print(GetFullName(), ": Missing candle after thorough search at shift ", _index, " (", TimeToString(_candle_time), + "). Lowest timestamp in history is ", icdata.GetMin()); } return CandleToEntry(_candle_time, _candle); diff --git a/Indicator/IndicatorTf.h b/Indicator/IndicatorTf.h index 84fe4b7c0..fb0f714b9 100644 --- a/Indicator/IndicatorTf.h +++ b/Indicator/IndicatorTf.h @@ -79,7 +79,10 @@ class IndicatorTf : public IndicatorCandle { /** * Class constructor with parameters. */ - IndicatorTf(TFP &_params) : IndicatorCandle(_params) { Init(); } + IndicatorTf(TFP& _icparams, const IndicatorDataParams& _idparams) + : IndicatorCandle(_icparams, _idparams) { + Init(); + } }; #endif diff --git a/Indicator/IndicatorTick.h b/Indicator/IndicatorTick.h index e654dde70..afb1075ea 100644 --- a/Indicator/IndicatorTick.h +++ b/Indicator/IndicatorTick.h @@ -66,7 +66,7 @@ class IndicatorTick : public Indicator { itdata.AddFlags(DICT_FLAG_FILL_HOLES_UNSORTED); itdata.SetOverflowListener(IndicatorTickOverflowListener, 10); // Ask and Bid price. - itparams.SetMaxModes(2); + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), 2); } public: @@ -75,8 +75,9 @@ class IndicatorTick : public Indicator { /** * Class constructor. */ - IndicatorTick(const TS& _itparams, IndicatorBase* _indi_src = NULL, int _indi_mode = 0) - : Indicator(_itparams, _indi_src, _indi_mode) { + IndicatorTick(const TS& _itparams, const IndicatorDataParams& _idparams, IndicatorBase* _indi_src = NULL, + int _indi_mode = 0) + : Indicator(_itparams, _idparams, _indi_src, _indi_mode) { itparams = _itparams; if (_indi_src != NULL) { SetDataSource(_indi_src, _indi_mode); @@ -153,12 +154,13 @@ class IndicatorTick : public Indicator { TickAB _tick = itdata.GetByKey(_timestamp); return TickToEntry(_timestamp, _tick); } + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); // No tick at given timestamp. Returning invalid entry. - IndicatorDataEntry _entry(itparams.GetMaxModes()); + IndicatorDataEntry _entry(_max_modes); GetEntryAlter(_entry, _timestamp); - for (int i = 0; i < itparams.GetMaxModes(); ++i) { + for (int i = 0; i < _max_modes; ++i) { _entry.values[i] = (double)0; } @@ -173,7 +175,8 @@ class IndicatorTick : public Indicator { * This method is called on GetEntry() right after values are set. */ virtual void GetEntryAlter(IndicatorDataEntry& _entry, int _timestamp = -1) { - _entry.AddFlags(_entry.GetDataTypeFlags(itparams.GetDataValueType())); + ENUM_DATATYPE _dtype = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_DTYPE)); + _entry.AddFlags(_entry.GetDataTypeFlags(_dtype)); }; /** @@ -206,7 +209,8 @@ class IndicatorTick : public Indicator { */ void SetDataSource(IndicatorBase* _indi, int _input_mode = -1) { indi_src = _indi; - itparams.SetDataSource(-1, _input_mode); + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_ID), -1); + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE), _input_mode); } /* Virtual methods */ diff --git a/Indicator/IndicatorTickOrCandleSource.h b/Indicator/IndicatorTickOrCandleSource.h index 961057c30..491766979 100644 --- a/Indicator/IndicatorTickOrCandleSource.h +++ b/Indicator/IndicatorTickOrCandleSource.h @@ -41,9 +41,12 @@ class IndicatorTickOrCandleSource : public Indicator { /** * Class constructor. */ - IndicatorTickOrCandleSource(const TS& _iparams, IndicatorBase* _indi_src = NULL, int _indi_mode = 0) - : Indicator(_iparams, _indi_src, _indi_mode) {} - IndicatorTickOrCandleSource(const TS& _iparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(_iparams, _tf) {} + IndicatorTickOrCandleSource(const TS& _iparams, const IndicatorDataParams& _idparams, IndicatorBase* _indi_src = NULL, + int _indi_mode = 0) + : Indicator(_iparams, _idparams, _indi_src, _indi_mode) {} + IndicatorTickOrCandleSource(const TS& _iparams, const IndicatorDataParams& _idparams, + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator(_iparams, _idparams, _tf) {} IndicatorTickOrCandleSource(ENUM_INDICATOR_TYPE _itype, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, string _name = "") : Indicator(_itype, _tf, _shift, _name) {} diff --git a/Indicator/IndicatorTickSource.h b/Indicator/IndicatorTickSource.h index ca59b4312..8b47180a5 100644 --- a/Indicator/IndicatorTickSource.h +++ b/Indicator/IndicatorTickSource.h @@ -37,9 +37,11 @@ class IndicatorTickSource : public Indicator { /** * Class constructor. */ - IndicatorTickSource(const TS& _iparams, IndicatorData* _indi_src = NULL, int _indi_mode = 0) - : Indicator(_iparams, _indi_src, _indi_mode) {} - IndicatorTickSource(const TS& _iparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(_iparams, _tf) {} + IndicatorTickSource(const TS& _iparams, const IndicatorDataParams& _idparams, IndicatorData* _indi_src = NULL, + int _indi_mode = 0) + : Indicator(_iparams, _idparams, _indi_src, _indi_mode) {} + IndicatorTickSource(const TS& _iparams, const IndicatorDataParams& _idparams, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : Indicator(_iparams, _idparams, _tf) {} IndicatorTickSource(ENUM_INDICATOR_TYPE _itype, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, string _name = "") : Indicator(_itype, _tf, _shift, _name) {} diff --git a/Indicator/tests/classes/IndicatorTickDummy.h b/Indicator/tests/classes/IndicatorTickDummy.h index 823a0d995..dcc473b88 100644 --- a/Indicator/tests/classes/IndicatorTickDummy.h +++ b/Indicator/tests/classes/IndicatorTickDummy.h @@ -35,14 +35,16 @@ // Params for dummy tick-based indicator. struct IndicatorTickDummyParams : IndicatorParams { - IndicatorTickDummyParams() : IndicatorParams(INDI_TICK, 2, TYPE_DOUBLE) {} + IndicatorTickDummyParams() : IndicatorParams(INDI_TICK) {} }; // Dummy tick-based indicator. class IndicatorTickDummy : public IndicatorTick { public: IndicatorTickDummy(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, string _name = "") - : IndicatorTick(INDI_TICK, _tf, _shift, _name) {} + : IndicatorTick(INDI_TICK, _tf, _shift, _name) { + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), 2); + } string GetName() override { return "IndicatorTickDummy"; } diff --git a/Indicator/tests/classes/IndicatorTickReal.h b/Indicator/tests/classes/IndicatorTickReal.h index 5aa387fd2..fc20d98c5 100644 --- a/Indicator/tests/classes/IndicatorTickReal.h +++ b/Indicator/tests/classes/IndicatorTickReal.h @@ -35,14 +35,16 @@ // Params for real tick-based indicator. struct IndicatorTickRealParams : IndicatorParams { - IndicatorTickRealParams() : IndicatorParams(INDI_TICK, 3, TYPE_DOUBLE) {} + IndicatorTickRealParams() : IndicatorParams(INDI_TICK) {} }; // Real tick-based indicator. class IndicatorTickReal : public IndicatorTick { public: IndicatorTickReal(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, string _name = "") - : IndicatorTick(INDI_TICK, _tf, _shift, _name) {} + : IndicatorTick(INDI_TICK, _tf, _shift, _name) { + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), 3); + } string GetName() override { return "IndicatorTickReal"; } diff --git a/IndicatorBase.h b/IndicatorBase.h index df56648b2..39deaab62 100644 --- a/IndicatorBase.h +++ b/IndicatorBase.h @@ -197,7 +197,7 @@ class IndicatorBase : public Chart { * Gets an indicator's state property value. */ template - T Get(STRUCT_ENUM(IndicatorState, ENUM_INDICATOR_STATE_PROP) _prop) { + T Get(STRUCT_ENUM_INDICATOR_STATE_PROP _prop) { return istate.Get(_prop); } diff --git a/IndicatorData.enum.h b/IndicatorData.enum.h new file mode 100644 index 000000000..12193a557 --- /dev/null +++ b/IndicatorData.enum.h @@ -0,0 +1,54 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2022, EA31337 Ltd | +//| https://github.com/EA31337 | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * @file + * Includes IndicatorData's enums. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +/* Defines type of source data for */ +enum ENUM_IDATA_SOURCE_TYPE { + 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 + IDATA_INDICATOR, // OnIndicator: Another indicator as a source of data + IDATA_ONCALCULATE, // OnCalculate: Custom calculation function + IDATA_MATH // Math-based indicator +}; + +/* Defines range value data type for indicator storage. */ +enum ENUM_IDATA_VALUE_RANGE { + IDATA_RANGE_BINARY, // E.g. 0 or 1. + IDATA_RANGE_BITWISE, // Bitwise + IDATA_RANGE_MIXED, + IDATA_RANGE_PRICE, // Values represent price. + IDATA_RANGE_PRICE_DIFF, // Values represent price differences. + IDATA_RANGE_PRICE_ON_SIGNAL, // Values represent price on signal, otherwise zero. + IDATA_RANGE_RANGE, // E.g. 0 to 100. + IDATA_RANGE_UNKNOWN +}; diff --git a/IndicatorData.mqh b/IndicatorData.mqh index 0db969639..12a07a2c9 100644 --- a/IndicatorData.mqh +++ b/IndicatorData.mqh @@ -22,6 +22,7 @@ // Includes. #include "IndicatorBase.h" +#include "IndicatorData.enum.h" #include "IndicatorData.struct.h" #include "IndicatorData.struct.serialize.h" #include "IndicatorData.struct.signal.h" @@ -40,9 +41,32 @@ class IndicatorData : public IndicatorBase { BufferStruct idata; DictStruct> indicators; // Indicators list keyed by id. IndicatorCalculateCache cache; - Ref indi_src; // // Indicator used as data source. - bool is_fed; // Whether calc_start_bar is already calculated. - int indi_src_mode; // Mode of source indicator + IndicatorDataParams idparams; // Indicator data params. + Ref indi_src; // Indicator used as data source. + + protected: + /* Protected methods */ + + bool Init() { + ArrayResize(value_storages, idparams.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES))); + if (indi_src.IsSet()) { + // SetDataSource(_indi_src, _indi_mode); + idparams.Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE), IDATA_INDICATOR); + } + switch (idparams.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { + case IDATA_BUILTIN: + break; + case IDATA_ICUSTOM: + break; + case IDATA_INDICATOR: + if (indi_src.IsSet() == NULL) { + // Indi_Price* _indi_price = Indi_Price::GetCached(GetSymbol(), GetTf(), iparams.GetShift()); + // SetDataSource(_indi_price, true, PRICE_OPEN); + } + break; + } + return true; + } public: /* Special methods */ @@ -50,13 +74,12 @@ class IndicatorData : public IndicatorBase { /** * Class constructor. */ - IndicatorData(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL) - : indi_src(NULL), is_fed(false), IndicatorBase(_tf, _symbol) {} - - /** - * Class constructor. - */ - IndicatorData(ENUM_TIMEFRAMES_INDEX _tfi, string _symbol = NULL) : IndicatorBase(_tfi, _symbol) {} + IndicatorData(const IndicatorDataParams& _idparams, IndicatorData* _indi_src = NULL, int _indi_mode = 0) + : idparams(_idparams), indi_src(_indi_src) { + } + IndicatorData(const IndicatorDataParams& _idparams, ENUM_TIMEFRAMES _tf, string _symbol = NULL) + : idparams(_idparams), IndicatorBase(_tf, _symbol) { + } /** * Class deconstructor. @@ -99,6 +122,24 @@ class IndicatorData : public IndicatorBase { IndicatorDataEntry operator[](ENUM_INDICATOR_INDEX _index) { return GetEntry((int)_index); } + /* Getters */ + + /** + * Gets a value from IndicatorDataParams struct. + */ + template + T Get(STRUCT_ENUM_IDATA_PARAM _param) { + return idparams.Get(_param); + } + + /** + * Gets an indicator's state property value. + */ + template + T Get(STRUCT_ENUM_INDICATOR_STATE_PROP _prop) { + return istate.Get(_prop); + } + /* Data methods */ /** @@ -148,7 +189,7 @@ class IndicatorData : public IndicatorBase { int GetBarsCalculated() { int _bars = Bars(GetSymbol(), GetTf()); - if (!is_fed) { + if (!idparams.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IS_FED))) { // Calculating start_bar. for (; calc_start_bar < _bars; ++calc_start_bar) { // Iterating from the oldest or previously iterated. @@ -156,13 +197,13 @@ class IndicatorData : public IndicatorBase { if (_entry.IsValid()) { // From this point we assume that future entries will be all valid. - is_fed = true; + idparams.Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IS_FED), true); return _bars - calc_start_bar; } } } - if (!is_fed) { + if (!idparams.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IS_FED))) { Print("Can't find valid bars for ", GetFullName()); return 0; } @@ -202,7 +243,7 @@ class IndicatorData : public IndicatorBase { return _result; } - int GetDataSourceMode() { return indi_src_mode; } + // int GetDataSourceMode() { return indi_src_mode; } /** * Returns currently selected data source without any validation. @@ -280,7 +321,7 @@ class IndicatorData : public IndicatorBase { /** * Sets data source's input mode. */ - void SetDataSourceMode(int _mode) { indi_src_mode = _mode; } + // void SetDataSourceMode(int _mode) { indi_src_mode = _mode; } /* Storage methods */ @@ -411,15 +452,15 @@ class IndicatorData : public IndicatorBase { return; } - if (_source.GetModeCount() > 1 && _target.GetDataSourceMode() == -1) { + if (_source.GetModeCount() > 1 && _target.idparams.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_DATA_SRC_MODE)) == -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.SetDataSourceMode(0); + _target.idparams.Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_DATA_SRC_MODE), 0); DebugBreak(); - } else if (_source.GetModeCount() == 1 && _target.GetDataSourceMode() == -1) { - _target.SetDataSourceMode(0); - } else if (_target.GetDataSourceMode() < 0 || _target.GetDataSourceMode() > _source.GetModeCount()) { + } else if (_source.GetModeCount() == 1 && _target.idparams.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_DATA_SRC_MODE)) == -1) { + _target.idparams.Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_DATA_SRC_MODE), 0); + } else if (_target.idparams.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_DATA_SRC_MODE)) < 0 || _target.idparams.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_DATA_SRC_MODE)) > _source.GetModeCount()) { Alert("Error! ", _target.GetName(), " must select valid source indicator's mode via SetDataSourceMode(int) between 0 and ", _source.GetModeCount(), "."); diff --git a/IndicatorData.struct.h b/IndicatorData.struct.h index d95a547c2..b6f942eb4 100644 --- a/IndicatorData.struct.h +++ b/IndicatorData.struct.h @@ -25,6 +25,9 @@ * Includes IndicatorData's structs. */ +// Defines. +#define STRUCT_ENUM_IDATA_PARAM STRUCT_ENUM(IndicatorDataParams, ENUM_IDATA_PARAM) + // Includes. #include "SerializerNode.enum.h" @@ -383,3 +386,118 @@ struct IndicatorDataEntry { return ToCSV(); } }; + +/* Structure for indicator data parameters. */ +struct IndicatorDataParams { + protected: + /* Struct protected variables */ + bool is_fed; // Whether calc_start_bar is already calculated. + int data_src_mode; // Mode used as input from data source. + int src_id; // Id of the indicator to be used as data source. + int src_mode; // Mode of source indicator + unsigned int max_buffers; // Max buffers to store. + unsigned int max_modes; // Max supported indicator modes (values per entry). + ENUM_DATATYPE dtype; // Type of basic data to store values (DTYPE_DOUBLE, DTYPE_INT). + ENUM_IDATA_SOURCE_TYPE idstype; // Indicator's data source type (e.g. IDATA_BUILTIN, IDATA_ICUSTOM). + ENUM_IDATA_VALUE_RANGE idvrange; // Indicator's range value data type. + public: + /* Struct enumerations */ + enum ENUM_IDATA_PARAM { + IDATA_PARAM_IS_FED = 0, + IDATA_PARAM_DATA_SRC_MODE, + IDATA_PARAM_DTYPE, + IDATA_PARAM_IDSTYPE, + IDATA_PARAM_IDVRANGE, + IDATA_PARAM_MAX_BUFFERS, + IDATA_PARAM_MAX_MODES, + IDATA_PARAM_SRC_ID, + IDATA_PARAM_SRC_MODE, + }; + + public: + /* Special methods */ + // Constructor. + IndicatorDataParams(unsigned int _max_modes = 1, ENUM_DATATYPE _dtype = TYPE_DOUBLE, + ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, + ENUM_IDATA_VALUE_RANGE _idvrange = IDATA_RANGE_UNKNOWN, int _data_src_mode = 0) + : data_src_mode(_data_src_mode), + dtype(_dtype), + max_modes(_max_modes), + max_buffers(10), + idstype(_idstype), + idvrange(_idvrange), + is_fed(false), + src_id(-1), + src_mode(-1){}; + // Copy constructor. + IndicatorDataParams(const IndicatorDataParams &_idp) { THIS_REF = _idp; } + // Deconstructor. + ~IndicatorDataParams(){}; + /* Getters */ + template + T Get(STRUCT_ENUM_IDATA_PARAM _param) { + switch (_param) { + case IDATA_PARAM_IS_FED: + return (T)is_fed; + case IDATA_PARAM_DATA_SRC_MODE: + return (T)data_src_mode; + case IDATA_PARAM_DTYPE: + return (T)dtype; + case IDATA_PARAM_IDSTYPE: + return (T)idstype; + case IDATA_PARAM_IDVRANGE: + return (T)idvrange; + case IDATA_PARAM_MAX_BUFFERS: + return (T)max_buffers; + case IDATA_PARAM_MAX_MODES: + return (T)max_modes; + case IDATA_PARAM_SRC_ID: + return (T)src_id; + case IDATA_PARAM_SRC_MODE: + return (T)src_mode; + } + SetUserError(ERR_INVALID_PARAMETER); + return (T)WRONG_VALUE; + } + static IndicatorDataParams GetInstance(unsigned int _max_modes = 1, ENUM_DATATYPE _dtype = TYPE_DOUBLE, + ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, + ENUM_IDATA_VALUE_RANGE _idvrange = IDATA_RANGE_UNKNOWN, + int _data_src_mode = 0) { + IndicatorDataParams _instance(_max_modes, _dtype, _idstype, _idvrange, _data_src_mode); + return _instance; + } + /* Setters */ + template + void Set(STRUCT_ENUM_IDATA_PARAM _param, T _value) { + switch (_param) { + case IDATA_PARAM_IS_FED: + is_fed = (bool)_value; + return; + case IDATA_PARAM_DATA_SRC_MODE: + data_src_mode = (int)_value; + return; + case IDATA_PARAM_DTYPE: + dtype = (ENUM_DATATYPE)_value; + return; + case IDATA_PARAM_IDSTYPE: + idstype = (ENUM_IDATA_SOURCE_TYPE)_value; + return; + case IDATA_PARAM_IDVRANGE: + idvrange = (ENUM_IDATA_VALUE_RANGE)_value; + return; + case IDATA_PARAM_MAX_BUFFERS: + max_buffers = (unsigned int)_value; + return; + case IDATA_PARAM_MAX_MODES: + max_modes = (unsigned int)_value; + return; + case IDATA_PARAM_SRC_ID: + src_id = (int)_value; + return; + case IDATA_PARAM_SRC_MODE: + src_mode = (int)_value; + return; + } + SetUserError(ERR_INVALID_PARAMETER); + } +}; diff --git a/IndicatorData.struct.signal.h b/IndicatorData.struct.signal.h index 954e02172..d865e4129 100644 --- a/IndicatorData.struct.signal.h +++ b/IndicatorData.struct.signal.h @@ -33,10 +33,12 @@ // Forward declaration. struct ChartParams; struct IndicatorDataEntry; +struct IndicatorDataParams; struct IndicatorParams; // Includes. -#include "Indicator.struct.h" +//#include "IndicatorData.enum.h" +//#include "Indicator.struct.h" /* Structure for indicator signals. */ struct IndicatorSignal { @@ -56,14 +58,14 @@ struct IndicatorSignal { // Constructors. IndicatorSignal(int _signals = 0) : signals(_signals) {} - IndicatorSignal(ARRAY_REF(IndicatorDataEntry, _data), IndicatorParams &_ip, ChartParams &_cp, int _m1 = 0, + IndicatorSignal(ARRAY_REF(IndicatorDataEntry, _data), IndicatorDataParams &_idp, ChartParams &_cp, int _m1 = 0, int _m2 = 0) : signals(0) { - CalcSignals(_data, _ip, _cp, _m1, _m2); + CalcSignals(_data, _idp, _cp, _m1, _m2); } // Main methods. // Calculate signal values. - void CalcSignals(ARRAY_REF(IndicatorDataEntry, _data), IndicatorParams &_ip, ChartParams &_cp, int _m1 = 0, + void CalcSignals(ARRAY_REF(IndicatorDataEntry, _data), IndicatorDataParams &_idp, ChartParams &_cp, int _m1 = 0, int _m2 = 0) { int _size = ArraySize(_data); // INDICATOR_SIGNAL_CROSSOVER @@ -88,7 +90,7 @@ struct IndicatorSignal { ((_price_w0 - _price_w1) < 0 && (_data[0][_m1] - _data[_size - 1][_m1]) > 0)); // INDICATOR_SIGNAL_GT_PRICE bool _v_gt_p = false; - if (_ip.GetIDataValueRange() == IDATA_RANGE_PRICE) { + if (_idp.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDVRANGE)) == IDATA_RANGE_PRICE) { _v_gt_p = _data[0][_m1] > _price_w0 || _data[0][_m2] > _price_w0; } else { // @todo diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index 5e64e4bea..e5af8c561 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -32,9 +32,8 @@ // Structs. struct CandleParams : IndicatorParams { // Struct constructor. - CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE, 1, TYPE_INT) { - SetDataValueRange(IDATA_RANGE_RANGE); - SetDataSourceType(IDATA_BUILTIN); + CandleParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_CANDLE) { + // SetDataValueRange(IDATA_RANGE_RANGE); shift = _shift; tf = _tf; }; @@ -52,7 +51,8 @@ class Indi_Candle : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_Candle(CandleParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_Candle(CandleParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_INT, IDATA_BUILTIN), _indi_src){}; Indi_Candle(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_CANDLE, _tf, _shift){}; @@ -72,7 +72,7 @@ class Indi_Candle : public IndicatorTickOrCandleSource { int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); BarOHLC _ohlcs[1]; - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: // In this mode, price is fetched from chart. _ohlcs[0] = Chart::GetOHLC(_ishift); diff --git a/Indicators/Bitwise/Indi_Pattern.mqh b/Indicators/Bitwise/Indi_Pattern.mqh index e0b0e1322..0d0ca49d8 100644 --- a/Indicators/Bitwise/Indi_Pattern.mqh +++ b/Indicators/Bitwise/Indi_Pattern.mqh @@ -32,9 +32,8 @@ // Structs. struct IndiPatternParams : IndicatorParams { // Struct constructor. - IndiPatternParams(int _shift = 0) : IndicatorParams(INDI_PATTERN, 5, TYPE_UINT) { - SetDataValueType(TYPE_UINT); - SetDataValueRange(IDATA_RANGE_BITWISE); + IndiPatternParams(int _shift = 0) : IndicatorParams(INDI_PATTERN) { + // SetDataValueRange(IDATA_RANGE_BITWISE); shift = _shift; }; IndiPatternParams(IndiPatternParams& _params, ENUM_TIMEFRAMES _tf) { @@ -51,7 +50,8 @@ class Indi_Pattern : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_Pattern(IndiPatternParams& _p, IndicatorData* _indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_Pattern(IndiPatternParams& _p, IndicatorData* _indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(5, TYPE_UINT), _indi_src){}; Indi_Pattern(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_PATTERN, _tf, _shift){}; @@ -61,12 +61,13 @@ class Indi_Pattern : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { int i; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); BarOHLC _ohlcs[8]; - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: // In this mode, price is fetched from chart. - for (i = 0; i < iparams.GetMaxModes(); ++i) { + for (i = 0; i < _max_modes; ++i) { _ohlcs[i] = Chart::GetOHLC(_ishift + i); if (!_ohlcs[i].IsValid()) { // Return empty entry on invalid candles. @@ -91,7 +92,7 @@ class Indi_Pattern : public IndicatorTickOrCandleSource { return WRONG_VALUE; } - for (i = 0; i < iparams.GetMaxModes(); ++i) { + for (i = 0; i < _max_modes; ++i) { _ohlcs[i].open = GetDataSource().GetValue(PRICE_OPEN, _ishift + i); _ohlcs[i].high = GetDataSource().GetValue(PRICE_HIGH, _ishift + i); _ohlcs[i].low = GetDataSource().GetValue(PRICE_LOW, _ishift + i); diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 820194f95..301d0e78d 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -35,15 +35,10 @@ double iAC(string _symbol, int _tf, int _shift) { // Structs. struct IndiACParams : IndicatorParams { // Struct constructor. - IndiACParams(int _shift = 0) : IndicatorParams(INDI_AC, 1, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_MIXED); + IndiACParams(int _shift = 0) : IndicatorParams(INDI_AC) { + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Accelerator"); shift = _shift; - switch (idstype) { - case IDATA_ICUSTOM: - SetMaxModes(2); - break; - } }; IndiACParams(IndiACParams &_params, ENUM_TIMEFRAMES _tf) { THIS_REF = _params; @@ -55,12 +50,31 @@ struct IndiACParams : IndicatorParams { * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ class Indi_AC : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { + case IDATA_ICUSTOM: + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), 2); + break; + } + } + public: /** * Class constructor. */ - Indi_AC(IndiACParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; - Indi_AC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_AC, _tf, _shift){}; + Indi_AC(IndiACParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) { + Init(); + }; + Indi_AC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_AC, _tf, _shift) { + Init(); + }; /** * Returns the indicator value. @@ -74,7 +88,8 @@ class Indi_AC : public IndicatorTickOrCandleSource { #ifdef __MQL4__ return ::iAC(_symbol, _tf, _shift); #else // __MQL5__ - int _handle = Object::IsValid(_obj) ? _obj.Get(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL; + int _handle = + Object::IsValid(_obj) ? _obj.Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_HANDLE)) : NULL; double _res[]; if (_handle == NULL || _handle == INVALID_HANDLE) { if ((_handle = ::iAC(_symbol, _tf)) == INVALID_HANDLE) { @@ -108,7 +123,7 @@ class Indi_AC : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { IndicatorDataEntryValue _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_AC::iAC(GetSymbol(), GetTf(), _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index 9254326f1..7cd401afc 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -34,8 +34,8 @@ double iAD(string _symbol, int _tf, int _shift) { // Structs. struct IndiADParams : IndicatorParams { // Struct constructor. - IndiADParams(int _shift = 0) : IndicatorParams(INDI_AD, 1, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_MIXED); + IndiADParams(int _shift = 0) : IndicatorParams(INDI_AD) { + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\AD"); shift = _shift; }; @@ -53,7 +53,8 @@ class Indi_AD : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_AD(IndiADParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_AD(IndiADParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_AD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_AD, _tf, _shift) { iparams.SetTf(_tf); }; @@ -104,7 +105,7 @@ class Indi_AD : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_AD::iAD(GetSymbol(), GetTf(), _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 4aeb85518..88c6bbcf5 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -39,17 +39,12 @@ struct IndiADXParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. IndiADXParams(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); + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : period(_period), applied_price(_ap), IndicatorParams(INDI_ADX) { + // SetDataValueRange(IDATA_RANGE_RANGE); SetShift(_shift); - switch (idstype) { - case IDATA_ICUSTOM: - if (custom_indi_name == "") { - SetCustomIndicatorName("Examples\\ADX"); - } - break; + if (custom_indi_name == "") { + SetCustomIndicatorName("Examples\\ADX"); } }; IndiADXParams(IndiADXParams &_params, ENUM_TIMEFRAMES _tf) { @@ -62,12 +57,23 @@ struct IndiADXParams : IndicatorParams { * Implements the Average Directional Movement Index indicator. */ class Indi_ADX : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + void Init() {} + public: /** * Class constructor. */ - Indi_ADX(IndiADXParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} - Indi_ADX(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_ADX, _tf, _shift) {} + Indi_ADX(IndiADXParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource( + _p, IndicatorDataParams::GetInstance(FINAL_INDI_ADX_LINE_ENTRY, TYPE_DOUBLE, IDATA_BUILTIN), _indi_src) { + Init(); + } + Indi_ADX(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_ADX, _tf, _shift) { + Init(); + } /** * Returns the indicator value. @@ -118,7 +124,7 @@ class Indi_ADX : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = LINE_MAIN_ADX, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_ADX::iADX(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index 505ce6abd..1f6b41ff8 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -37,13 +37,11 @@ struct IndiADXWParams : IndiADXParams { // Struct constructor. IndiADXWParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0, - ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN) - : IndiADXParams(_period, _ap, _shift, _tf, _idstype) { + ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) + : IndiADXParams(_period, _ap, _shift, _tf) { itype = itype == INDI_NONE || itype == INDI_ADX ? INDI_ADXW : itype; - switch (idstype) { - case IDATA_ICUSTOM: - SetCustomIndicatorName("Examples\\ADXW"); - break; + if (custom_indi_name == "") { + SetCustomIndicatorName("Examples\\ADXW"); } }; IndiADXWParams(IndiADXWParams &_params, ENUM_TIMEFRAMES _tf) { @@ -60,7 +58,8 @@ class Indi_ADXW : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_ADXW(IndiADXWParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_ADXW(IndiADXWParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, IDATA_BUILTIN), _indi_src){}; Indi_ADXW(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_ADXW, _tf, _shift){}; @@ -229,7 +228,7 @@ class Indi_ADXW : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = LINE_MAIN_ADX, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_ADXW::iADXWilder(GetSymbol(), GetTf(), GetPeriod(), _mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index 506318a04..78873cec7 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -43,16 +43,11 @@ struct IndiAMAParams : IndicatorParams { slow_period(_slow_period), ama_shift(_ama_shift), applied_price(_ap) { - SetDataValueRange(IDATA_RANGE_PRICE); + // SetDataValueRange(IDATA_RANGE_PRICE); // Defaulting to on-indicator mode (will use real ticks from platform via IndicatorTickReal). - SetDataSourceMode(IDATA_INDICATOR); SetShift(_shift); - switch (idstype) { - case IDATA_ICUSTOM: - if (custom_indi_name == "") { - SetCustomIndicatorName("Examples\\AMA"); - } - break; + if (custom_indi_name == "") { + SetCustomIndicatorName("Examples\\AMA"); } }; IndiAMAParams(IndiAMAParams &_params, ENUM_TIMEFRAMES _tf) { @@ -70,7 +65,8 @@ class Indi_AMA : public IndicatorTickOrCandleSource { * Class constructor. */ Indi_AMA(IndiAMAParams &_p, IndicatorData *_indi_src = NULL, int _indi_mode = 0) - : IndicatorTickOrCandleSource(_p, _indi_src, _indi_mode) { + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, IDATA_BUILTIN), _indi_src, + _indi_mode) { iparams.SetIndicatorType(INDI_AMA); }; Indi_AMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_AMA, _tf, _shift){}; @@ -178,7 +174,8 @@ class Indi_AMA : public IndicatorTickOrCandleSource { ExtSlowPeriodEMA, ExtFastPeriodEMA); for (int x = prev_calculated; x < rates_total; ++x) { - Print("price[", x, "] = ", price[x].Get(), ", O = ", iOpen(Symbol(), PERIOD_CURRENT, Bars(Symbol(), PERIOD_CURRENT) - x - 1)); + Print("price[", x, "] = ", price[x].Get(), + ", O = ", iOpen(Symbol(), PERIOD_CURRENT, Bars(Symbol(), PERIOD_CURRENT) - x - 1)); } int i; @@ -225,7 +222,7 @@ class Indi_AMA : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_AMA::iAMA(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetFastPeriod(), GetSlowPeriod(), GetAMAShift(), GetAppliedPrice() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index 9786aed4d..baae944aa 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -34,11 +34,8 @@ double iAO(string _symbol, int _tf, int _shift) { // Structs. struct IndiAOParams : IndicatorParams { // Struct constructor. - IndiAOParams(int _shift = 0) : IndicatorParams(INDI_AO, 2, TYPE_DOUBLE) { -#ifdef __MQL4__ - max_modes = 1; -#endif - SetDataValueRange(IDATA_RANGE_MIXED); + IndiAOParams(int _shift = 0) : IndicatorParams(INDI_AO) { + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Awesome_Oscillator"); shift = _shift; }; @@ -52,12 +49,31 @@ struct IndiAOParams : IndicatorParams { * Implements the Awesome oscillator. */ class Indi_AO : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { +#ifdef __MQL4__ + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), 1); +#else + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), 2); +#endif + } + public: /** * Class constructor. */ - Indi_AO(IndiAOParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; - Indi_AO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_AO, _tf, _shift){}; + Indi_AO(IndiAOParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(2, TYPE_DOUBLE), _indi_src) { + Init(); + }; + Indi_AO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_AO, _tf, _shift) { + Init(); + }; /** * Returns the indicator value. @@ -106,7 +122,7 @@ class Indi_AO : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_AO::iAO(GetSymbol(), GetTf(), _ishift, _mode, THIS_PTR); break; diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index a0c578e96..5fb5cf64e 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -30,9 +30,8 @@ struct IndiASIParams : IndicatorParams { unsigned int period; double mpc; // Struct constructor. - IndiASIParams(double _mpc = 300.0, int _shift = 0) - : IndicatorParams(INDI_ASI, 1, TYPE_DOUBLE, PERIOD_CURRENT, IDATA_ONCALCULATE) { - SetDataValueRange(IDATA_RANGE_MIXED); + IndiASIParams(double _mpc = 300.0, int _shift = 0) : IndicatorParams(INDI_ASI, PERIOD_CURRENT) { + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ASI"); mpc = _mpc; shift = _shift; @@ -47,12 +46,30 @@ struct IndiASIParams : IndicatorParams { * Implements the Bill Williams' Accelerator/Decelerator oscillator. */ class Indi_ASI : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { + if (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE)) == IDATA_BUILTIN) { + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE), IDATA_ONCALCULATE); + } + } + public: /** * Class constructor. */ - Indi_ASI(IndiASIParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; - Indi_ASI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_ASI, _tf, _shift){}; + Indi_ASI(IndiASIParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, IDATA_ONCALCULATE), + _indi_src) { + Init(); + }; + Indi_ASI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_ASI, _tf, _shift) { + Init(); + }; /** * Built-in version of ASI. @@ -168,7 +185,7 @@ class Indi_ASI : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetMaximumPriceChanging() /*]*/, 0, _ishift); diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index e3c8f9e69..fe92820b8 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -35,10 +35,9 @@ double iATR(string _symbol, int _tf, int _period, int _shift) { struct IndiATRParams : IndicatorParams { unsigned int period; // Struct constructors. - IndiATRParams(unsigned int _period = 14, int _shift = 0) - : period(_period), IndicatorParams(INDI_ATR, 1, TYPE_DOUBLE) { + IndiATRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_ATR) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ATR"); }; IndiATRParams(IndiATRParams &_params, ENUM_TIMEFRAMES _tf) { @@ -57,7 +56,8 @@ class Indi_ATR : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_ATR(IndiATRParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_ATR(IndiATRParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_ATR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_ATR, _tf, _shift){}; /** @@ -106,7 +106,7 @@ class Indi_ATR : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_ATR::iATR(GetSymbol(), GetTf(), GetPeriod(), _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/Indi_Alligator.mqh index 4908498ee..914745a2d 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/Indi_Alligator.mqh @@ -81,9 +81,9 @@ struct IndiAlligatorParams : IndicatorParams { lips_shift(_ls), ma_method(_mm), applied_price(_ap), - IndicatorParams(INDI_ALLIGATOR, FINAL_ALLIGATOR_LINE_ENTRY, TYPE_DOUBLE) { + IndicatorParams(INDI_ALLIGATOR) { shift = _shift; - SetDataValueRange(IDATA_RANGE_PRICE); + // SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Alligator"); }; IndiAlligatorParams(IndiAlligatorParams &_params, ENUM_TIMEFRAMES _tf) { @@ -101,7 +101,8 @@ class Indi_Alligator : public IndicatorTickOrCandleSource { * Class constructor. */ Indi_Alligator(IndiAlligatorParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src) {} + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(FINAL_ALLIGATOR_LINE_ENTRY, TYPE_DOUBLE), + _indi_src) {} Indi_Alligator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_ADX, _tf, _shift){}; @@ -172,7 +173,7 @@ class Indi_Alligator : public IndicatorTickOrCandleSource { return GetEntryValue((ENUM_ALLIGATOR_LINE)1, _ishift); } #endif - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_Alligator::iAlligator(GetSymbol(), GetTf(), GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Indi_AppliedPrice.mqh index ec4688adc..b32be9eca 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Indi_AppliedPrice.mqh @@ -30,9 +30,8 @@ struct IndiAppliedPriceParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. IndiAppliedPriceParams(ENUM_APPLIED_PRICE _applied_price = PRICE_OPEN, int _shift = 0) - : applied_price(_applied_price), IndicatorParams(INDI_APPLIED_PRICE, 1, TYPE_DOUBLE) { - SetDataSourceType(IDATA_INDICATOR); - SetDataValueRange(IDATA_RANGE_PRICE); + : applied_price(_applied_price), IndicatorParams(INDI_APPLIED_PRICE) { + // SetDataValueRange(IDATA_RANGE_PRICE); shift = _shift; }; IndiAppliedPriceParams(IndiAppliedPriceParams &_params, ENUM_TIMEFRAMES _tf) { @@ -58,7 +57,7 @@ class Indi_AppliedPrice : public IndicatorTickOrCandleSource= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_INDICATOR: if (HasDataSource()) { // 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()); + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE), GetAppliedPrice()); _value = Indi_AppliedPrice::iAppliedPriceOnIndicator(GetDataSource(), GetAppliedPrice(), _ishift); } break; @@ -102,7 +101,7 @@ class Indi_AppliedPrice : public IndicatorTickOrCandleSource::IsValidEntry(_entry); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_INDICATOR: if (!HasDataSource()) { GetLogger().Error("Indi_AppliedPrice requires source indicator to be set via SetDataSource()!"); diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index 0d364f139..07965554c 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -48,8 +48,7 @@ enum ENUM_MFI_COLOR { struct IndiBWIndiMFIParams : IndicatorParams { ENUM_APPLIED_VOLUME ap; // @todo // Struct constructors. - IndiBWIndiMFIParams(int _shift = 0) : IndicatorParams(INDI_BWMFI, FINAL_BWMFI_BUFFER_ENTRY, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_MIXED); + IndiBWIndiMFIParams(int _shift = 0) : IndicatorParams(INDI_BWMFI) { shift = _shift; SetCustomIndicatorName("Examples\\MarketFacilitationIndex"); }; @@ -63,13 +62,29 @@ struct IndiBWIndiMFIParams : IndicatorParams { * Implements the Market Facilitation Index by Bill Williams indicator. */ class Indi_BWMFI : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), FINAL_BWMFI_BUFFER_ENTRY); } + public: /** * Class constructor. */ - Indi_BWMFI(IndiBWIndiMFIParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_BWMFI(IndiBWIndiMFIParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource( + _p, + IndicatorDataParams::GetInstance(FINAL_BWMFI_BUFFER_ENTRY, TYPE_DOUBLE, IDATA_BUILTIN, IDATA_RANGE_MIXED), + _indi_src) { + Init(); + } Indi_BWMFI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) - : IndicatorTickOrCandleSource(INDI_BWMFI, _tf, _shift) {} + : IndicatorTickOrCandleSource(INDI_BWMFI, _tf, _shift) { + Init(); + } /** * Returns the indicator value. @@ -119,7 +134,7 @@ class Indi_BWMFI : public IndicatorTickOrCandleSource { double _value = EMPTY_VALUE; - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_BWMFI::iBWMFI(GetSymbol(), GetTf(), _ishift, (ENUM_BWMFI_BUFFER)_mode, THIS_PTR); break; diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index 5368be61e..53b5b9729 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -46,10 +46,9 @@ struct IndiBWZTParams : IndicatorParams { unsigned int second_period; unsigned int sum_period; // Struct constructor. - IndiBWZTParams(int _shift = 0) : IndicatorParams(INDI_BWZT, FINAL_INDI_BWZT_MODE_ENTRY, TYPE_DOUBLE) { + IndiBWZTParams(int _shift = 0) : IndicatorParams(INDI_BWZT) { indi_ac = NULL; indi_ao = NULL; - SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\BW-ZoneTrade"); shift = _shift; }; @@ -63,13 +62,29 @@ struct IndiBWZTParams : IndicatorParams { * Implements the Bill Williams' Zone Trade. */ class Indi_BWZT : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), FINAL_INDI_BWZT_MODE_ENTRY); } + public: /** * Class constructor. */ - Indi_BWZT(IndiBWZTParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_BWZT(IndiBWZTParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource( + _p, + IndicatorDataParams::GetInstance(FINAL_INDI_BWZT_MODE_ENTRY, TYPE_DOUBLE, IDATA_BUILTIN, IDATA_RANGE_MIXED), + _indi_src) { + Init(); + }; Indi_BWZT(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) - : IndicatorTickOrCandleSource(INDI_BWZT, _tf, _shift){}; + : IndicatorTickOrCandleSource(INDI_BWZT, _tf, _shift) { + Init(); + }; /** * Built-in version of BWZT. @@ -208,7 +223,7 @@ class Indi_BWZT : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_BWZT::iBWZT(GetSymbol(), GetTf(), _mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_Bands.mqh b/Indicators/Indi_Bands.mqh index 002a40d08..42a68746e 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/Indi_Bands.mqh @@ -68,13 +68,9 @@ struct IndiBandsParams : IndicatorParams { // Struct constructors. IndiBandsParams(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, FINAL_BANDS_LINE_ENTRY, TYPE_DOUBLE) { + : period(_period), deviation(_deviation), bshift(_bshift), applied_price(_ap), IndicatorParams(INDI_BANDS) { shift = _shift; - SetDataValueRange(IDATA_RANGE_PRICE); + // SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\BB"); }; IndiBandsParams(IndiBandsParams &_params, ENUM_TIMEFRAMES _tf) { @@ -87,13 +83,26 @@ struct IndiBandsParams : IndicatorParams { * Implements the Bollinger Bands® indicator. */ class Indi_Bands : public IndicatorTickSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), FINAL_BANDS_LINE_ENTRY); } + public: /** * Class constructor. */ Indi_Bands(IndiBandsParams &_p, IndicatorData *_indi_src = NULL, int _mode = 0) - : IndicatorTickSource(_p, _indi_src, _mode) {} - Indi_Bands(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickSource(INDI_BANDS, _tf, _shift) {} + : IndicatorTickSource(_p, IndicatorDataParams::GetInstance(FINAL_BANDS_LINE_ENTRY, TYPE_DOUBLE), _indi_src, + _mode) { + Init(); + } + Indi_Bands(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickSource(INDI_BANDS, _tf, _shift) { + Init(); + } /** * Returns the indicator value. @@ -156,7 +165,9 @@ class Indi_Bands : public IndicatorTickSource { int current_shift = _shift + (i - _bands_shift); // Getting current indicator value. _indi_value_buffer[i - _bands_shift] = - _indi[i - _bands_shift].values[_target != NULL ? _target.GetDataSourceMode() : 0].Get(); + _indi[i - _bands_shift] + .values[_target != NULL ? _target.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE)) : 0] + .Get(); } // Base band. @@ -242,7 +253,7 @@ class Indi_Bands : public IndicatorTickSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = BAND_BASE, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_Bands::iBands(GetSymbol(), GetTf(), GetPeriod(), GetDeviation(), GetBandsShift(), GetAppliedPrice(), (ENUM_BANDS_LINE)_mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index 9d368ddbd..cf0675893 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -37,9 +37,9 @@ struct IndiBearsPowerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. IndiBearsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), applied_price(_ap), IndicatorParams(INDI_BEARS, 1, TYPE_DOUBLE) { + : period(_period), applied_price(_ap), IndicatorParams(INDI_BEARS) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Bears"); }; IndiBearsPowerParams(IndiBearsPowerParams &_params, ENUM_TIMEFRAMES _tf) { @@ -57,7 +57,7 @@ class Indi_BearsPower : public IndicatorTickOrCandleSource * Class constructor. */ Indi_BearsPower(IndiBearsPowerParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src) {} + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_BearsPower(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_BEARS, _tf, _shift) {} @@ -108,7 +108,7 @@ class Indi_BearsPower : public IndicatorTickOrCandleSource virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = _value = iBearsPower(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index b3ba6ce1d..eec95976a 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -37,9 +37,9 @@ struct IndiBullsPowerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // (MT5): not used // Struct constructor. IndiBullsPowerParams(unsigned int _period = 13, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : period(_period), applied_price(_ap), IndicatorParams(INDI_BULLS, 1, TYPE_DOUBLE) { + : period(_period), applied_price(_ap), IndicatorParams(INDI_BULLS) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Bulls"); }; IndiBullsPowerParams(IndiBullsPowerParams &_params, ENUM_TIMEFRAMES _tf) { @@ -57,7 +57,7 @@ class Indi_BullsPower : public IndicatorTickOrCandleSource * Class constructor. */ Indi_BullsPower(IndiBullsPowerParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src) {} + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_BullsPower(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_BULLS, _tf, _shift) {} @@ -108,7 +108,7 @@ class Indi_BullsPower : public IndicatorTickOrCandleSource virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = iBullsPower(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index 7e28d50db..b1c2e5e23 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -44,9 +44,9 @@ struct IndiCCIParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. IndiCCIParams(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) { + : period(_period), applied_price(_applied_price), IndicatorParams(INDI_CCI) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CCI"); }; IndiCCIParams(IndiCCIParams &_params, ENUM_TIMEFRAMES _tf) { @@ -63,7 +63,8 @@ class Indi_CCI : public IndicatorTickSource { /** * Class constructor. */ - Indi_CCI(IndiCCIParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickSource(_p, _indi_src) {} + Indi_CCI(IndiCCIParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_CCI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickSource(INDI_CCI, _tf, _shift) {} /** @@ -148,7 +149,7 @@ class Indi_CCI : public IndicatorTickSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); double _value = EMPTY_VALUE; - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: // @fixit Somehow shift isn't used neither in MT4 nor MT5. _value = Indi_CCI::iCCI(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), _ishift /* + iparams.shift*/, @@ -162,7 +163,8 @@ class Indi_CCI : public IndicatorTickSource { ValidateSelectedDataSource(); // @fixit Somehow shift isn't used neither in MT4 nor MT5. - _value = Indi_CCI::iCCIOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), GetDataSourceMode(), + _value = Indi_CCI::iCCIOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), + Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE)), _ishift /* + iparams.shift*/); break; } diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 673e6da66..d8ad2237b 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -36,10 +36,10 @@ struct IndiCHOParams : IndicatorParams { // Struct constructor. IndiCHOParams(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) { + : IndicatorParams(INDI_CHAIKIN) { fast_ma = _fast_ma; input_volume = _input_volume; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CHO"); shift = _shift; slow_ma = _slow_ma; @@ -59,7 +59,8 @@ class Indi_CHO : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_CHO(IndiCHOParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_CHO(IndiCHOParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_CHO(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_CHAIKIN, _tf, _shift){}; @@ -184,7 +185,7 @@ class Indi_CHO : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_CHO::iChaikin(GetSymbol(), GetTf(), /*[*/ GetSlowMA(), GetFastMA(), GetSmoothMethod(), GetInputVolume() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index 3eb6aabd7..1e09c0f97 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -38,9 +38,9 @@ struct IndiCHVParams : IndicatorParams { // Struct constructor. IndiCHVParams(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) { + : IndicatorParams(INDI_CHAIKIN_V) { chv_period = _chv_period; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\CHV"); shift = _shift; smooth_method = _smooth_method; @@ -60,7 +60,8 @@ class Indi_CHV : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_CHV(IndiCHVParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_CHV(IndiCHVParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_CHV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_CHAIKIN_V, _tf, _shift){}; @@ -179,7 +180,7 @@ class Indi_CHV : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_CHV::iCHV(GetSymbol(), GetTf(), /*[*/ GetSmoothPeriod(), GetCHVPeriod(), GetSmoothMethod() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh index 8fc00a3f8..f1925ac30 100644 --- a/Indicators/Indi_ColorBars.mqh +++ b/Indicators/Indi_ColorBars.mqh @@ -28,8 +28,8 @@ // Structs. struct IndiColorBarsParams : IndicatorParams { // Struct constructor. - IndiColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS, 5, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_MIXED); + IndiColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS) { + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorBars"); shift = _shift; }; @@ -48,7 +48,7 @@ class Indi_ColorBars : public IndicatorTickOrCandleSource { * Class constructor. */ Indi_ColorBars(IndiColorBarsParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src){}; + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(5, TYPE_DOUBLE), _indi_src){}; Indi_ColorBars(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_COLOR_BARS, _tf, _shift){}; @@ -127,7 +127,7 @@ class Indi_ColorBars : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_ColorBars::iColorBars(GetSymbol(), GetTf(), _mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh index 87ced8ae1..018dc47b5 100644 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ b/Indicators/Indi_ColorCandlesDaily.mqh @@ -28,8 +28,8 @@ // Structs. struct IndiColorCandlesDailyParams : IndicatorParams { // Struct constructor. - IndiColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY, 5, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_MIXED); + IndiColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY) { + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorCandlesDaily"); shift = _shift; }; @@ -48,7 +48,7 @@ class Indi_ColorCandlesDaily : public IndicatorTickOrCandleSource= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_ColorCandlesDaily::iCCD(GetSymbol(), GetTf(), _mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh index 4478f7696..509071f5f 100644 --- a/Indicators/Indi_ColorLine.mqh +++ b/Indicators/Indi_ColorLine.mqh @@ -30,9 +30,9 @@ struct IndiColorLineParams : IndicatorParams { IndicatorData *indi_ma; // Struct constructor. - IndiColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE, 2, TYPE_DOUBLE) { + IndiColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE) { indi_ma = NULL; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ColorLine"); shift = _shift; }; @@ -51,7 +51,7 @@ class Indi_ColorLine : public IndicatorTickOrCandleSource { * Class constructor. */ Indi_ColorLine(IndiColorLineParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src){}; + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(2, TYPE_DOUBLE), _indi_src){}; Indi_ColorLine(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_COLOR_LINE, _tf, _shift){}; @@ -202,7 +202,7 @@ class Indi_ColorLine : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_ColorLine::iColorLine(GetSymbol(), GetTf(), _mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh index e55cd4e6e..2a6e0ce83 100644 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ b/Indicators/Indi_CustomMovingAverage.mqh @@ -32,14 +32,15 @@ struct IndiCustomMovingAverageParams : IndicatorParams { // Struct constructor. IndiCustomMovingAverageParams(int _smooth_period = 13, int _smooth_shift = 0, ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0) - : IndicatorParams(INDI_CUSTOM_MOVING_AVG, 1, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_MIXED); - SetDataSourceType(IDATA_ICUSTOM); + : IndicatorParams(INDI_CUSTOM_MOVING_AVG) { + // SetDataValueRange(IDATA_RANGE_MIXED); + if (custom_indi_name == "") { #ifdef __MQL5__ - SetCustomIndicatorName("Examples\\Custom Moving Average"); + SetCustomIndicatorName("Examples\\Custom Moving Average"); #else - SetCustomIndicatorName("Custom Moving Averages"); + SetCustomIndicatorName("Custom Moving Averages"); #endif + } shift = _shift; smooth_method = _smooth_method; smooth_period = _smooth_period; @@ -60,7 +61,7 @@ class Indi_CustomMovingAverage : public IndicatorTickOrCandleSource= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetSmoothPeriod(), GetSmoothShift(), GetSmoothMethod() /*]*/, 0, _ishift); diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index 196122e41..0efcd4261 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -42,16 +42,12 @@ struct IndiDEIndiMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. IndiDEIndiMAParams(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) { + : period(_period), ma_shift(_ma_shift), applied_price(_ap), IndicatorParams(INDI_DEMA) { SetCustomIndicatorName("Examples\\DEMA"); - SetDataValueRange(IDATA_RANGE_PRICE); + // SetDataValueRange(IDATA_RANGE_PRICE); SetShift(_shift); - switch (idstype) { - case IDATA_ICUSTOM: - if (custom_indi_name == "") { - SetCustomIndicatorName("Examples\\DEMA"); - } - break; + if (custom_indi_name == "") { + SetCustomIndicatorName("Examples\\DEMA"); } }; IndiDEIndiMAParams(IndiDEIndiMAParams &_params, ENUM_TIMEFRAMES _tf) { @@ -68,7 +64,8 @@ class Indi_DEMA : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_DEMA(IndiDEIndiMAParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_DEMA(IndiDEIndiMAParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_DEMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_DEMA, _tf, _shift) {} @@ -181,7 +178,7 @@ class Indi_DEMA : public IndicatorTickOrCandleSource { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: // We're getting DEMA from Price indicator. diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index b62b6516d..0a40549ef 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -35,10 +35,9 @@ double iDeMarker(string _symbol, int _tf, int _period, int _shift) { struct IndiDeMarkerParams : IndicatorParams { unsigned int period; // Struct constructors. - IndiDeMarkerParams(unsigned int _period = 14, int _shift = 0) - : period(_period), IndicatorParams(INDI_DEMARKER, 1, TYPE_DOUBLE) { + IndiDeMarkerParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_DEMARKER) { shift = _shift; - SetDataValueRange(IDATA_RANGE_RANGE); + // SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\DeMarker"); }; IndiDeMarkerParams(IndiDeMarkerParams &_params, ENUM_TIMEFRAMES _tf) { @@ -55,7 +54,8 @@ class Indi_DeMarker : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_DeMarker(IndiDeMarkerParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_DeMarker(IndiDeMarkerParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_DeMarker(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_DEMARKER, _tf, _shift) {} @@ -105,7 +105,7 @@ class Indi_DeMarker : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = _value = Indi_DeMarker::iDeMarker(GetSymbol(), GetTf(), GetPeriod(), _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index 4b3f8b57b..034aa91fd 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -33,15 +33,11 @@ // Structs. struct IndiDemoParams : IndicatorParams { // Struct constructors. - IndiDemoParams(int _shift = 0) : IndicatorParams(INDI_DEMO, 1, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_MIXED); + IndiDemoParams(int _shift = 0) : IndicatorParams(INDI_DEMO) { + //// SetDataValueRange(IDATA_RANGE_MIXED); SetShift(_shift); - switch (idstype) { - case IDATA_ICUSTOM: - if (custom_indi_name == "") { - SetCustomIndicatorName("Examples\\Demo"); - } - break; + if (custom_indi_name == "") { + SetCustomIndicatorName("Examples\\Demo"); } }; IndiDemoParams(IndiDemoParams &_params, ENUM_TIMEFRAMES _tf) { @@ -58,7 +54,8 @@ class Indi_Demo : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_Demo(IndiDemoParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_Demo(IndiDemoParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_Demo(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_DEMO, _tf, _shift){}; diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index c35f6d295..af29271eb 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -32,9 +32,9 @@ struct IndiDetrendedPriceParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. IndiDetrendedPriceParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_DETRENDED_PRICE, 1, TYPE_DOUBLE) { + : IndicatorParams(INDI_DETRENDED_PRICE) { applied_price = _ap; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\DPO"); period = _period; shift = _shift; @@ -54,7 +54,7 @@ class Indi_DetrendedPrice : public IndicatorTickOrCandleSource= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_DetrendedPrice::iDPO(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetAppliedPrice() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index 05258cc71..2d974168d 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -42,7 +42,7 @@ class Indi_Drawer : public IndicatorTickOrCandleSource { * Class constructor. */ Indi_Drawer(const IndiDrawerParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src), redis(true) { + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(0, TYPE_DOUBLE), _indi_src), redis(true) { Init(); } Indi_Drawer(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) @@ -71,15 +71,16 @@ class Indi_Drawer : public IndicatorTickOrCandleSource { virtual bool ExecuteAction(ENUM_INDICATOR_ACTION _action, DataParamEntry &_args[]) { int num_args = ArraySize(_args), i; + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); IndicatorDataEntry entry(num_args - 1); // @fixit Not sure if we should enforce double. // entry.AddFlags(INDI_ENTRY_FLAG_IS_DOUBLE); if (_action == INDI_ACTION_SET_VALUE) { - iparams.SetMaxModes(num_args - 1); + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), num_args - 1); - if (num_args - 1 > iparams.GetMaxModes()) { + if (num_args - 1 > _max_modes) { GetLogger().Error( StringFormat("Too many data for buffers for action %s!", EnumToString(_action), __FUNCTION_LINE__)); return false; @@ -176,7 +177,7 @@ class Indi_Drawer : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = -1) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_Drawer::iDrawer(GetSymbol(), GetTf(), _ishift, THIS_PTR); break; @@ -217,5 +218,4 @@ class Indi_Drawer : public IndicatorTickOrCandleSource { istate.is_changed = true; iparams.applied_price = _applied_price; } - }; diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index e868d110e..b9f5f8287 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -36,7 +36,7 @@ struct IndiDrawerParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; IndiDrawerParams(unsigned int _period = 10, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) - : period(_period), applied_price(_ap), IndicatorParams(INDI_DRAWER, 0, TYPE_DOUBLE) { + : period(_period), applied_price(_ap), IndicatorParams(INDI_DRAWER) { // Fetching history data is not yet implemented. SetCustomIndicatorName("Examples\\Drawer"); }; diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/Indi_Envelopes.mqh index 87624125b..c06cc3c83 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/Indi_Envelopes.mqh @@ -58,13 +58,9 @@ struct IndiEnvelopesParams : IndicatorParams { ma_method(_ma_method), applied_price(_ap), deviation(_deviation), - IndicatorParams(INDI_ENVELOPES, 2, TYPE_DOUBLE) { -#ifdef __MQL4__ - // There is extra LINE_MAIN in MQL4 for Envelopes. - max_modes = 3; -#endif + IndicatorParams(INDI_ENVELOPES) { shift = _shift; - SetDataValueRange(IDATA_RANGE_PRICE); + // SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Envelopes"); }; IndiEnvelopesParams(IndiEnvelopesParams &_params, ENUM_TIMEFRAMES _tf) { @@ -77,14 +73,33 @@ struct IndiEnvelopesParams : IndicatorParams { * Implements the Envelopes indicator. */ class Indi_Envelopes : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { +#ifdef __MQL4__ + // There is extra LINE_MAIN in MQL4 for Envelopes. + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), 3); +#else + Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), 2); +#endif + } + public: /** * Class constructor. */ Indi_Envelopes(IndiEnvelopesParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src) {} + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(2, TYPE_DOUBLE), _indi_src) { + Init(); + } Indi_Envelopes(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) - : IndicatorTickOrCandleSource(INDI_ENVELOPES, _tf, _shift) {} + : IndicatorTickOrCandleSource(INDI_ENVELOPES, _tf, _shift) { + Init(); + }; /** * Returns the indicator value. @@ -201,7 +216,7 @@ class Indi_Envelopes : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_Envelopes::iEnvelopes(GetSymbol(), GetTf(), GetMAPeriod(), GetMAMethod(), GetMAShift(), GetAppliedPrice(), GetDeviation(), _mode, _ishift, THIS_PTR); @@ -212,8 +227,9 @@ class Indi_Envelopes : public IndicatorTickOrCandleSource { break; case IDATA_INDICATOR: _value = Indi_Envelopes::iEnvelopesOnIndicator(GetCache(), GetDataSource(), GetSymbol(), GetTf(), GetMAPeriod(), - GetMAMethod(), GetDataSourceMode(), GetMAShift(), GetDeviation(), - _mode, _ishift); + GetMAMethod(), + Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE)), + GetMAShift(), GetDeviation(), _mode, _ishift); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index 96a961c7c..3ebb8c0c5 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -51,9 +51,9 @@ struct IndiForceParams : IndicatorParams { // Struct constructors. IndiForceParams(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) { + : period(_period), ma_method(_ma_method), applied_price(_ap), IndicatorParams(INDI_FORCE) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Force_Index"); }; IndiForceParams(IndiForceParams &_params, ENUM_TIMEFRAMES _tf) { @@ -71,7 +71,8 @@ class Indi_Force : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_Force(IndiForceParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_Force(IndiForceParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_Force(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_FORCE, _tf, _shift) {} @@ -121,7 +122,7 @@ class Indi_Force : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_Force::iForce(GetSymbol(), GetTf(), GetPeriod(), GetMAMethod(), GetAppliedPrice(), _ishift, THIS_PTR); diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 558c643e9..4a2442c3a 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -33,9 +33,9 @@ struct IndiFrAIndiMAParams : IndicatorParams { // Struct constructor. IndiFrAIndiMAParams(int _period = 14, int _frama_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_FRAMA, 1, TYPE_DOUBLE) { + : IndicatorParams(INDI_FRAMA) { frama_shift = _frama_shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\FrAMA"); applied_price = _ap; period = _period; @@ -55,7 +55,8 @@ class Indi_FrAMA : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_FrAMA(IndiFrAIndiMAParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_FrAMA(IndiFrAIndiMAParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_FrAMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_FRAMA, _tf, _shift){}; @@ -148,7 +149,7 @@ class Indi_FrAMA : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_FrAMA::iFrAMA(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetFRAMAShift(), GetAppliedPrice() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index 01205d3de..2c074b427 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -34,8 +34,7 @@ double iFractals(string _symbol, int _tf, int _mode, int _shift) { // Structs. struct IndiFractalsParams : IndicatorParams { // Struct constructors. - IndiFractalsParams(int _shift = 0) : IndicatorParams(INDI_FRACTALS, FINAL_LO_UP_LINE_ENTRY, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_ARROW); + IndiFractalsParams(int _shift = 0) : IndicatorParams(INDI_FRACTALS) { SetCustomIndicatorName("Examples\\Fractals"); shift = _shift; }; @@ -49,13 +48,29 @@ struct IndiFractalsParams : IndicatorParams { * Implements the Fractals indicator. */ class Indi_Fractals : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), FINAL_LO_UP_LINE_ENTRY); } + public: /** * Class constructor. */ - Indi_Fractals(IndiFractalsParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_Fractals(IndiFractalsParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, + IndicatorDataParams::GetInstance(FINAL_LO_UP_LINE_ENTRY, TYPE_DOUBLE, IDATA_BUILTIN, + IDATA_RANGE_PRICE_ON_SIGNAL), + _indi_src) { + Init(); + } Indi_Fractals(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) - : IndicatorTickOrCandleSource(INDI_FRACTALS, _tf, _shift) {} + : IndicatorTickOrCandleSource(INDI_FRACTALS, _tf, _shift) { + Init(); + } /** * Returns the indicator value. @@ -105,7 +120,7 @@ class Indi_Fractals : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = _value = Indi_Fractals::iFractals(GetSymbol(), GetTf(), (ENUM_LO_UP_LINE)_mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index a82905673..f2f094df3 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -89,9 +89,8 @@ struct IndiGatorParams : IndicatorParams { lips_shift(_ls), ma_method(_mm), applied_price(_ap), - IndicatorParams(INDI_GATOR, FINAL_GATOR_LINE_HISTOGRAM_ENTRY, TYPE_DOUBLE) { + IndicatorParams(INDI_GATOR) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Gator"); }; IndiGatorParams(IndiGatorParams &_params, ENUM_TIMEFRAMES _tf) { @@ -104,13 +103,29 @@ struct IndiGatorParams : IndicatorParams { * Implements the Gator oscillator. */ class Indi_Gator : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), FINAL_GATOR_LINE_HISTOGRAM_ENTRY); } + public: /** * Class constructor. */ - Indi_Gator(IndiGatorParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_Gator(IndiGatorParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, + IndicatorDataParams::GetInstance(FINAL_GATOR_LINE_HISTOGRAM_ENTRY, TYPE_DOUBLE, + IDATA_BUILTIN, IDATA_RANGE_MIXED), + _indi_src) { + Init(); + } Indi_Gator(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) - : IndicatorTickOrCandleSource(INDI_GATOR, _tf, _shift) {} + : IndicatorTickOrCandleSource(INDI_GATOR, _tf, _shift) { + Init(); + } /** * Returns the indicator value. @@ -173,7 +188,7 @@ class Indi_Gator : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_Gator::iGator(GetSymbol(), GetTf(), GetJawPeriod(), GetJawShift(), GetTeethPeriod(), GetTeethShift(), GetLipsPeriod(), GetLipsShift(), GetMAMethod(), GetAppliedPrice(), diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index ed6581801..01b823e38 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -50,13 +50,14 @@ enum ENUM_HA_MODE { // Structs. struct IndiHeikenAshiParams : IndicatorParams { // Struct constructors. - IndiHeikenAshiParams(int _shift = 0) : IndicatorParams(INDI_HEIKENASHI, FINAL_HA_MODE_ENTRY, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_MIXED); // @fixit It draws candles! + IndiHeikenAshiParams(int _shift = 0) : IndicatorParams(INDI_HEIKENASHI) { + if (custom_indi_name == "") { #ifdef __MQL4__ - SetCustomIndicatorName("Heiken Ashi"); + SetCustomIndicatorName("Heiken Ashi"); #else - SetCustomIndicatorName("Examples\\Heiken_Ashi"); + SetCustomIndicatorName("Examples\\Heiken_Ashi"); #endif + } shift = _shift; }; IndiHeikenAshiParams(IndiHeikenAshiParams &_params, ENUM_TIMEFRAMES _tf) { @@ -69,14 +70,28 @@ struct IndiHeikenAshiParams : IndicatorParams { * Implements the Heiken-Ashi indicator. */ class Indi_HeikenAshi : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), FINAL_HA_MODE_ENTRY); } + public: /** * Class constructor. */ Indi_HeikenAshi(IndiHeikenAshiParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src) {} + : IndicatorTickOrCandleSource( + _p, IndicatorDataParams::GetInstance(FINAL_HA_MODE_ENTRY, TYPE_DOUBLE, IDATA_BUILTIN, IDATA_RANGE_PRICE), + _indi_src) { + Init(); + } Indi_HeikenAshi(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) - : IndicatorTickOrCandleSource(INDI_HEIKENASHI, _tf, _shift) {} + : IndicatorTickOrCandleSource(INDI_HEIKENASHI, _tf, _shift) { + Init(); + } /** * Returns value for iHeikenAshi indicator. @@ -209,7 +224,7 @@ class Indi_HeikenAshi : public IndicatorTickOrCandleSource virtual IndicatorDataEntryValue GetEntryValue(int _mode = HA_OPEN, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: #ifdef __MQL4__ // Converting MQL4's enum into MQL5 one, as OnCalculate uses further one. diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index 943c0393c..479dd1687 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -69,12 +69,9 @@ struct IndiIchimokuParams : IndicatorParams { unsigned int senkou_span_b; // Struct constructors. IndiIchimokuParams(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, FINAL_ICHIMOKU_LINE_ENTRY, TYPE_DOUBLE) { + : tenkan_sen(_ts), kijun_sen(_ks), senkou_span_b(_ss_b), IndicatorParams(INDI_ICHIMOKU) { shift = _shift; - SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Not sure if not mixed. + // SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Not sure if not mixed. SetCustomIndicatorName("Examples\\Ichimoku"); }; IndiIchimokuParams(IndiIchimokuParams &_params, ENUM_TIMEFRAMES _tf) { @@ -87,13 +84,27 @@ struct IndiIchimokuParams : IndicatorParams { * Implements the Ichimoku Kinko Hyo indicator. */ class Indi_Ichimoku : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), FINAL_ICHIMOKU_LINE_ENTRY); } + public: /** * Class constructor. */ - Indi_Ichimoku(IndiIchimokuParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_Ichimoku(IndiIchimokuParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(FINAL_ICHIMOKU_LINE_ENTRY, TYPE_DOUBLE), + _indi_src) { + Init(); + } Indi_Ichimoku(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) - : IndicatorTickOrCandleSource(INDI_ICHIMOKU, _tf, _shift) {} + : IndicatorTickOrCandleSource(INDI_ICHIMOKU, _tf, _shift) { + Init(); + } /** * Returns the indicator value. @@ -145,7 +156,7 @@ class Indi_Ichimoku : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_Ichimoku::iIchimoku(GetSymbol(), GetTf(), GetTenkanSen(), GetKijunSen(), GetSenkouSpanB(), _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index 667d16397..9d366a3c9 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -49,10 +49,8 @@ enum ENUM_INDI_KILLZONES_MODE { struct IndiKillzonesParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - 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); + IndiKillzonesParams(int _shift = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorParams(INDI_PIVOT) { + // SetDataValueRange(IDATA_RANGE_MIXED); SetShift(_shift); tf = _tf; }; @@ -100,7 +98,9 @@ class Indi_Killzones : public IndicatorTickOrCandleSource { * Class constructor. */ Indi_Killzones(IndiKillzonesParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src) {} + : IndicatorTickOrCandleSource( + _p, IndicatorDataParams::GetInstance(FINAL_INDI_KILLZONES_MODE_ENTRY, TYPE_FLOAT, IDATA_CHART), _indi_src) { + } Indi_Killzones(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_KILLZONES, _tf, _shift) {} @@ -111,7 +111,7 @@ class Indi_Killzones : public IndicatorTickOrCandleSource { float _value = FLT_MAX; int _index = (int)_mode / 2; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: // Builtin mode not supported. SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_MA.mqh b/Indicators/Indi_MA.mqh index 8c56dbfdf..f5765c1f0 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Indi_MA.mqh @@ -56,13 +56,9 @@ struct IndiMAParams : IndicatorParams { // Struct constructors. IndiMAParams(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, TYPE_DOUBLE) { + : period(_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_array(_ap), IndicatorParams(INDI_MA) { shift = _shift; - SetDataValueRange(IDATA_RANGE_PRICE); + // SetDataValueRange(IDATA_RANGE_PRICE); SetCustomIndicatorName("Examples\\Moving Average"); }; IndiMAParams(IndiMAParams &_params, ENUM_TIMEFRAMES _tf) { @@ -79,7 +75,8 @@ class Indi_MA : public IndicatorTickSource { /** * Class constructor. */ - Indi_MA(IndiMAParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickSource(_p, _indi_src) {} + Indi_MA(IndiMAParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_MA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickSource(INDI_MA, _tf, _shift) {} /** @@ -630,7 +627,7 @@ class Indi_MA : public IndicatorTickSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_MA::iMA(GetSymbol(), GetTf(), GetPeriod(), GetMAShift(), GetMAMethod(), GetAppliedPrice(), _ishift, THIS_PTR); @@ -641,10 +638,12 @@ class Indi_MA : public IndicatorTickSource { break; case IDATA_INDICATOR: // Calculating MA value from specified indicator. - _value = Indi_MA::iMAOnIndicator(GetCache(), GetDataSource(), GetDataSourceMode(), GetSymbol(), GetTf(), - GetPeriod(), GetMAShift(), GetMAMethod(), _ishift); + _value = Indi_MA::iMAOnIndicator(GetCache(), GetDataSource(), + Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE)), GetSymbol(), + GetTf(), GetPeriod(), GetMAShift(), GetMAMethod(), _ishift); break; } + return _value; } diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Indi_MACD.mqh index 08d760125..0e1193ace 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Indi_MACD.mqh @@ -45,9 +45,9 @@ struct IndiMACDParams : IndicatorParams { ema_slow_period(_esp), signal_period(_sp), applied_price(_ap), - IndicatorParams(INDI_MACD, FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE) { + IndicatorParams(INDI_MACD) { shift = _shift; - SetDataValueRange(IDATA_RANGE_RANGE); + // SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\MACD"); }; IndiMACDParams(IndiMACDParams &_params, ENUM_TIMEFRAMES _tf) { @@ -64,7 +64,9 @@ class Indi_MACD : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_MACD(IndiMACDParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_MACD(IndiMACDParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE), + _indi_src) {} Indi_MACD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_MACD, _tf, _shift) {} @@ -118,7 +120,7 @@ class Indi_MACD : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = LINE_MAIN, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_MACD::iMACD(GetSymbol(), GetTf(), GetEmaFastPeriod(), GetEmaSlowPeriod(), GetSignalPeriod(), GetAppliedPrice(), (ENUM_SIGNAL_LINE)_mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index 7e0a70d2c..00f53bfca 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -37,9 +37,9 @@ struct IndiMFIParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Ignored in MT4. // Struct constructors. IndiMFIParams(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) { + : ma_period(_ma_period), applied_volume(_av), IndicatorParams(INDI_MFI) { shift = _shift; - SetDataValueRange(IDATA_RANGE_RANGE); + // SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\MFI"); }; IndiMFIParams(IndiMFIParams &_params, ENUM_TIMEFRAMES _tf) { @@ -56,7 +56,8 @@ class Indi_MFI : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_MFI(IndiMFIParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_MFI(IndiMFIParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_MFI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_MFI, _tf, _shift) {} /** @@ -114,7 +115,7 @@ class Indi_MFI : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: #ifdef __MQL4__ _value = Indi_MFI::iMFI(GetSymbol(), GetTf(), GetPeriod(), _ishift); diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index 6ee2afb9e..70a0958eb 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -33,10 +33,10 @@ struct IndiMassIndexParams : IndicatorParams { int sum_period; // Struct constructor. IndiMassIndexParams(int _period = 9, int _second_period = 9, int _sum_period = 25, int _shift = 0) - : IndicatorParams(INDI_MASS_INDEX, 1, TYPE_DOUBLE) { + : IndicatorParams(INDI_MASS_INDEX) { period = _period; second_period = _second_period; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\MI"); shift = _shift; sum_period = _sum_period; @@ -56,7 +56,7 @@ class Indi_MassIndex : public IndicatorTickOrCandleSource { * Class constructor. */ Indi_MassIndex(IndiMassIndexParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src){}; + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_MassIndex(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_MASS_INDEX, _tf, _shift){}; @@ -170,7 +170,7 @@ class Indi_MassIndex : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_MassIndex::iMI(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetSecondPeriod(), GetSumPeriod() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 8d69ba91f..4f5add12f 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -47,9 +47,9 @@ struct IndiMomentumParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructors. IndiMomentumParams(unsigned int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : period(_period), applied_price(_ap), IndicatorParams(INDI_MOMENTUM, 1, TYPE_DOUBLE) { + : period(_period), applied_price(_ap), IndicatorParams(INDI_MOMENTUM) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Momentum"); }; IndiMomentumParams(IndiMomentumParams &_params, ENUM_TIMEFRAMES _tf) { @@ -66,7 +66,8 @@ class Indi_Momentum : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_Momentum(IndiMomentumParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_Momentum(IndiMomentumParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_Momentum(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_MOMENTUM, _tf, _shift) {} @@ -144,7 +145,7 @@ class Indi_Momentum : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: // @fixit Somehow shift isn't used neither in MT4 nor MT5. _value = Indi_Momentum::iMomentum(GetSymbol(), GetTf(), GetPeriod(), GetAppliedPrice(), iparams.shift + _ishift, @@ -159,7 +160,8 @@ class Indi_Momentum : public IndicatorTickOrCandleSource { // @fixit Somehow shift isn't used neither in MT4 nor MT5. _value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), - GetDataSourceMode(), iparams.shift + _shift); + Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE)), + iparams.shift + _shift); if (iparams.is_draw) { draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + _shift), _value, 1); } diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index abc67491f..ddac4411e 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -36,21 +36,17 @@ struct IndiOBVParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // MT4 only. ENUM_APPLIED_VOLUME applied_volume; // MT5 only. // Struct constructors. - IndiOBVParams(int _shift = 0) : IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { + IndiOBVParams(int _shift = 0) : IndicatorParams(INDI_OBV) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\OBV"); applied_price = PRICE_CLOSE; applied_volume = VOLUME_TICK; } - IndiOBVParams(ENUM_APPLIED_VOLUME _av, int _shift = 0) - : applied_volume(_av), IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { - max_modes = 1; + IndiOBVParams(ENUM_APPLIED_VOLUME _av, int _shift = 0) : applied_volume(_av), IndicatorParams(INDI_OBV) { shift = _shift; }; - IndiOBVParams(ENUM_APPLIED_PRICE _ap, int _shift = 0) - : applied_price(_ap), IndicatorParams(INDI_OBV, 1, TYPE_DOUBLE) { - max_modes = 1; + IndiOBVParams(ENUM_APPLIED_PRICE _ap, int _shift = 0) : applied_price(_ap), IndicatorParams(INDI_OBV) { shift = _shift; }; IndiOBVParams(IndiOBVParams &_params, ENUM_TIMEFRAMES _tf) { @@ -67,7 +63,8 @@ class Indi_OBV : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_OBV(IndiOBVParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_OBV(IndiOBVParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_OBV(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_OBV, _tf, _shift) {} /** @@ -121,7 +118,7 @@ class Indi_OBV : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: #ifdef __MQL4__ _value = Indi_OBV::iOBV(GetSymbol(), GetTf(), GetAppliedPrice(), _ishift); diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 4ddfbf98f..dc3c8fb8a 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -44,9 +44,9 @@ struct IndiOsMAParams : IndicatorParams { ema_slow_period(_esp), signal_period(_sp), applied_price(_ap), - IndicatorParams(INDI_OSMA, 1, TYPE_DOUBLE) { + IndicatorParams(INDI_OSMA) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\OsMA"); }; IndiOsMAParams(IndiOsMAParams &_params, ENUM_TIMEFRAMES _tf) { @@ -63,7 +63,8 @@ class Indi_OsMA : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_OsMA(IndiOsMAParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_OsMA(IndiOsMAParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_OsMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_OSMA, _tf, _shift) {} @@ -115,7 +116,7 @@ class Indi_OsMA : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); double _value = EMPTY_VALUE; - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_OsMA::iOsMA(GetSymbol(), GetTf(), GetEmaFastPeriod(), GetEmaSlowPeriod(), GetSignalPeriod(), GetAppliedPrice(), _ishift, THIS_PTR); diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/Indi_Pivot.mqh index 358d657a3..7bbb9f964 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/Indi_Pivot.mqh @@ -30,9 +30,9 @@ struct IndiPivotParams : IndicatorParams { ENUM_PP_TYPE method; // Pivot point calculation method. // Struct constructor. - 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) { method = _method; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); shift = _shift; }; IndiPivotParams(IndiPivotParams& _params, ENUM_TIMEFRAMES _tf) { @@ -45,14 +45,26 @@ struct IndiPivotParams : IndicatorParams { * Implements Pivot Detector. */ class Indi_Pivot : public IndicatorTickOrCandleSource { + protected: + /* Protected methods */ + + /** + * Initialize. + */ + void Init() { Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), 9); } + public: /** * Class constructor. */ - Indi_Pivot(IndiPivotParams& _p, IndicatorData* _indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_Pivot(IndiPivotParams& _p, IndicatorData* _indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(9, TYPE_FLOAT), _indi_src) { + Init(); + }; Indi_Pivot(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_PIVOT, _tf, _shift) { iparams.tf = _tf; + Init(); }; /** @@ -72,7 +84,7 @@ class Indi_Pivot : public IndicatorTickOrCandleSource { BarOHLC _ohlc = GetOHLC(_ishift); _entry.timestamp = GetBarTime(_ishift); if (_ohlc.IsValid()) { - _entry.Resize(iparams.GetMaxModes()); + _entry.Resize(Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES))); _ohlc.GetPivots(GetMethod(), _entry.values[0].value.vflt, _entry.values[1].value.vflt, _entry.values[2].value.vflt, _entry.values[3].value.vflt, _entry.values[4].value.vflt, _entry.values[5].value.vflt, _entry.values[6].value.vflt, _entry.values[7].value.vflt, @@ -111,7 +123,7 @@ class Indi_Pivot : public IndicatorTickOrCandleSource { */ virtual bool IsValidEntry(IndicatorDataEntry& _entry) { bool _is_valid = Indicator::IsValidEntry(_entry); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: break; case IDATA_INDICATOR: @@ -139,7 +151,7 @@ class Indi_Pivot : public IndicatorTickOrCandleSource { */ BarOHLC GetOHLC(int _shift = 0) { BarOHLC _ohlc; - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: // In this mode, price is fetched from chart. _ohlc = Chart::GetOHLC(_shift); diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index cefbbcaa3..1717ca999 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -29,10 +29,9 @@ struct IndiPriceChannelParams : IndicatorParams { unsigned int period; // Struct constructor. - IndiPriceChannelParams(unsigned int _period = 22, int _shift = 0) - : IndicatorParams(INDI_PRICE_CHANNEL, 3, TYPE_DOUBLE) { + IndiPriceChannelParams(unsigned int _period = 22, int _shift = 0) : IndicatorParams(INDI_PRICE_CHANNEL) { period = _period; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Price_Channel"); shift = _shift; }; @@ -51,7 +50,7 @@ class Indi_PriceChannel : public IndicatorTickOrCandleSource= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_PriceChannel::iPriceChannel(GetSymbol(), GetTf(), GetPeriod(), _mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index 5c79c9bb4..991d764c7 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -32,15 +32,14 @@ struct IndiPriceFeederParams : IndicatorParams { /** * Struct constructor. */ - IndiPriceFeederParams(int _shift = 0) : IndicatorParams(INDI_PRICE_FEEDER, 1, TYPE_DOUBLE) { shift = _shift; } + IndiPriceFeederParams(int _shift = 0) : IndicatorParams(INDI_PRICE_FEEDER) { shift = _shift; } /** * Struct constructor. * * @todo Use more modes (full OHCL). */ - IndiPriceFeederParams(const double& _price_data[], int _total = 0) - : IndicatorParams(INDI_PRICE_FEEDER, 1, TYPE_DOUBLE) { + IndiPriceFeederParams(const double& _price_data[], int _total = 0) : IndicatorParams(INDI_PRICE_FEEDER) { tf = PERIOD_CURRENT; ArrayCopy(price_data, _price_data, 0, 0, _total == 0 ? WHOLE_ARRAY : _total); }; @@ -59,7 +58,7 @@ class Indi_PriceFeeder : public IndicatorTickOrCandleSource::OnTick(); if (iparams.is_draw) { + int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); IndicatorDataEntry _entry = GetEntry(0); - for (int i = 0; i < (int)iparams.GetMaxModes(); ++i) { + for (int i = 0; i < _max_modes; ++i) { draw.DrawLineTo(GetName() + "_" + IntegerToString(i), GetBarTime(0), _entry.values[i].GetDbl()); } } diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index 555e8ed0b..d08ab0d4c 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -30,9 +30,9 @@ struct IndiPriceVolumeTrendParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. IndiPriceVolumeTrendParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_PRICE_VOLUME_TREND, 1, TYPE_DOUBLE) { + : IndicatorParams(INDI_PRICE_VOLUME_TREND) { applied_volume = _applied_volume; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\PVT"); shift = _shift; }; @@ -51,7 +51,7 @@ class Indi_PriceVolumeTrend : public IndicatorTickOrCandleSource= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_PriceVolumeTrend::iPVT(GetSymbol(), GetTf(), /*[*/ GetAppliedVolume() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index cad311ddf..4dd4662eb 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -30,11 +30,9 @@ struct IndiRSParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - IndiRSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_RS, 2, TYPE_DOUBLE) { + IndiRSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_RS) { applied_volume = _applied_volume; - SetDataValueRange(IDATA_RANGE_MIXED); - SetDataSourceType(IDATA_MATH); + // SetDataValueRange(IDATA_RANGE_MIXED); shift = _shift; }; IndiRSParams(IndiRSParams &_params, ENUM_TIMEFRAMES _tf) { @@ -53,13 +51,16 @@ class Indi_RS : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_RS(IndiRSParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) { Init(); }; + Indi_RS(IndiRSParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(2, TYPE_DOUBLE, IDATA_MATH), _indi_src) { + Init(); + }; Indi_RS(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_RS, _tf, _shift) { Init(); }; void Init() { - if (iparams.GetDataSourceType() == IDATA_MATH) { + if (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE)) == IDATA_MATH) { IndiOHLCParams _iohlc_params(); // @todo Symbol should be already defined for a chart. // @todo If it's not, move initialization to GetValue()/GetEntry() method. @@ -82,7 +83,7 @@ class Indi_RS : public IndicatorTickOrCandleSource { */ virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_MATH: return imath[_mode].Ptr().GetEntryValue(); break; diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Indi_RSI.mqh index d1f8fd823..6b7e2cc6c 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Indi_RSI.mqh @@ -51,9 +51,9 @@ struct IndiRSIParams : IndicatorParams { public: IndiRSIParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 0) - : applied_price(_ap), IndicatorParams(INDI_RSI, 1, TYPE_DOUBLE) { + : applied_price(_ap), IndicatorParams(INDI_RSI) { shift = _shift; - SetDataValueRange(IDATA_RANGE_RANGE); + // SetDataValueRange(IDATA_RANGE_RANGE); // SetDataSourceType(IDATA_ICUSTOM); SetCustomIndicatorName("Examples\\RSI"); SetPeriod(_period); @@ -96,7 +96,8 @@ class Indi_RSI : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_RSI(IndiRSIParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_RSI(IndiRSIParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_RSI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_RSI, _tf, _shift) {} /** @@ -173,7 +174,7 @@ class Indi_RSI : public IndicatorTickOrCandleSource { RSIGainLossData last_data, new_data; unsigned int data_position; double diff; - int _mode = _obj.GetDataSourceMode(); + int _mode = _obj.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE)); if (!_obj.aux_data.KeyExists(_bar_time_prev, data_position)) { // No previous SMMA-based average gain and loss. Calculating SMA-based ones. @@ -293,7 +294,7 @@ class Indi_RSI : public IndicatorTickOrCandleSource { double _value = EMPTY_VALUE; double _res[]; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_RSI::iRSI(GetSymbol(), GetTf(), iparams.GetPeriod(), iparams.GetAppliedPrice(), _ishift, THIS_PTR); diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index f51328fa6..a46be0c81 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -35,10 +35,9 @@ double iRVI(string _symbol, int _tf, int _period, int _mode, int _shift) { struct IndiRVIParams : IndicatorParams { unsigned int period; // Struct constructors. - IndiRVIParams(unsigned int _period = 10, int _shift = 0) - : period(_period), IndicatorParams(INDI_RVI, FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE) { + IndiRVIParams(unsigned int _period = 10, int _shift = 0) : period(_period), IndicatorParams(INDI_RVI) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\RVI"); }; IndiRVIParams(IndiRVIParams &_params, ENUM_TIMEFRAMES _tf) { @@ -55,7 +54,9 @@ class Indi_RVI : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_RVI(const IndiRVIParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_RVI(const IndiRVIParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE), + _indi_src) {} Indi_RVI(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_RVI, _tf, _shift) {} /** @@ -106,7 +107,7 @@ class Indi_RVI : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = LINE_MAIN, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_RVI::iRVI(GetSymbol(), GetTf(), GetPeriod(), (ENUM_SIGNAL_LINE)_mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index e179dcf5e..7149a2ead 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -31,9 +31,9 @@ struct IndiRateOfChangeParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. IndiRateOfChangeParams(int _period = 12, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_RATE_OF_CHANGE, 1, TYPE_DOUBLE) { + : IndicatorParams(INDI_RATE_OF_CHANGE) { applied_price = _ap; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ROC"); period = _period; shift = _shift; @@ -53,7 +53,7 @@ class Indi_RateOfChange : public IndicatorTickOrCandleSource= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_RateOfChange::iROC(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetAppliedPrice() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_SAR.mqh b/Indicators/Indi_SAR.mqh index 626b07abd..495210b67 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/Indi_SAR.mqh @@ -37,9 +37,9 @@ struct IndiSARParams : IndicatorParams { double max; // Struct constructors. IndiSARParams(double _step = 0.02, double _max = 0.2, int _shift = 0) - : step(_step), max(_max), IndicatorParams(INDI_SAR, 1, TYPE_DOUBLE) { + : step(_step), max(_max), IndicatorParams(INDI_SAR) { shift = _shift; - SetDataValueRange(IDATA_RANGE_PRICE); // @fixit It draws single dot for each bar! + // SetDataValueRange(IDATA_RANGE_PRICE); // @fixit It draws single dot for each bar! SetCustomIndicatorName("Examples\\ParabolicSAR"); }; IndiSARParams(IndiSARParams &_params, ENUM_TIMEFRAMES _tf) { @@ -56,7 +56,8 @@ class Indi_SAR : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_SAR(IndiSARParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_SAR(IndiSARParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_SAR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_SAR, _tf, _shift) {} /** @@ -105,7 +106,7 @@ class Indi_SAR : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_SAR::iSAR(GetSymbol(), GetTf(), GetStep(), GetMax(), _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index 3aae93627..bb0b7d62c 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -59,9 +59,9 @@ struct IndiStdDevParams : IndicatorParams { ma_shift(_ma_shift), ma_method(_ma_method), applied_price(_ap), - IndicatorParams(INDI_STDDEV, 1, TYPE_DOUBLE) { + IndicatorParams(INDI_STDDEV) { shift = _shift; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\StdDev"); }; IndiStdDevParams(IndiStdDevParams &_params, ENUM_TIMEFRAMES _tf) { @@ -78,7 +78,8 @@ class Indi_StdDev : public IndicatorTickSource { /** * Class constructor. */ - Indi_StdDev(IndiStdDevParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickSource(_p, _indi_src) {} + Indi_StdDev(IndiStdDevParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_StdDev(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickSource(INDI_STDDEV, _tf, _shift) {} /** @@ -130,7 +131,7 @@ class Indi_StdDev : public IndicatorTickSource { double _indi_value_buffer[]; double _std_dev; int i; - int _mode = _obj != NULL ? _obj.GetDataSourceMode() : 0; + int _mode = _obj != NULL ? _obj.Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_SRC_MODE)) : 0; ArrayResize(_indi_value_buffer, _ma_period); @@ -229,15 +230,14 @@ class Indi_StdDev : public IndicatorTickSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_StdDev::iStdDev(GetSymbol(), GetTf(), GetMAPeriod(), GetMAShift(), GetMAMethod(), GetAppliedPrice(), _ishift, THIS_PTR); break; case IDATA_ICUSTOM: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), - iparams.GetCustomIndicatorName(), /*[*/ GetMAPeriod(), GetMAShift(), GetMAMethod() /*]*/, 0, - _ishift); + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetMAPeriod(), + GetMAShift(), GetMAMethod() /*]*/, 0, _ishift); break; case IDATA_INDICATOR: _value = Indi_StdDev::iStdDevOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetMAPeriod(), GetMAShift(), diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Indi_Stochastic.mqh index 2b6a1994a..a12dd8f59 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Indi_Stochastic.mqh @@ -48,9 +48,9 @@ struct IndiStochParams : IndicatorParams { slowing(_slowing), ma_method(_ma_method), price_field(_pf), - IndicatorParams(INDI_STOCHASTIC, FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE) { + IndicatorParams(INDI_STOCHASTIC) { shift = _shift; - SetDataValueRange(IDATA_RANGE_RANGE); + // SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\Stochastic"); }; IndiStochParams(IndiStochParams &_params, ENUM_TIMEFRAMES _tf) { @@ -67,7 +67,9 @@ class Indi_Stochastic : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_Stochastic(IndiStochParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_Stochastic(IndiStochParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(FINAL_SIGNAL_LINE_ENTRY, TYPE_DOUBLE), + _indi_src) {} Indi_Stochastic(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_STOCHASTIC, _tf, _shift) {} @@ -123,7 +125,7 @@ class Indi_Stochastic : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = LINE_MAIN, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_Stochastic::iStochastic(GetSymbol(), GetTf(), GetKPeriod(), GetDPeriod(), GetSlowing(), GetMAMethod(), GetPriceField(), _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index 785d0d956..9510bc112 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -33,9 +33,9 @@ struct IndiTEMAParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // Struct constructor. IndiTEMAParams(int _period = 14, int _tema_shift = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_TEMA, 1, TYPE_DOUBLE) { + : IndicatorParams(INDI_TEMA) { applied_price = _ap; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\TEMA"); period = _period; shift = _shift; @@ -55,7 +55,8 @@ class Indi_TEMA : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_TEMA(IndiTEMAParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_TEMA(IndiTEMAParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_TEMA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_TEMA, _tf, _shift){}; @@ -142,7 +143,7 @@ class Indi_TEMA : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_TEMA::iTEMA(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetTEMAShift(), GetAppliedPrice() /*]*/, 0, _ishift, THIS_PTR); diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index e5d521679..6353bd224 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -32,10 +32,9 @@ struct IndiTRIXParams : IndicatorParams { unsigned int tema_shift; ENUM_APPLIED_PRICE applied_price; // Struct constructor. - IndiTRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) - : IndicatorParams(INDI_TRIX, 1, TYPE_DOUBLE) { + IndiTRIXParams(int _period = 14, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) : IndicatorParams(INDI_TRIX) { applied_price = _ap; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\TRIX"); period = _period; shift = _shift; @@ -54,7 +53,8 @@ class Indi_TRIX : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_TRIX(IndiTRIXParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_TRIX(IndiTRIXParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_TRIX(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_TRIX, _tf, _shift){}; @@ -141,7 +141,7 @@ class Indi_TRIX : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_TRIX::iTriX(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetAppliedPrice() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index a6cf9c4b5..de3693ac0 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -42,12 +42,12 @@ struct IndiUltimateOscillatorParams : IndicatorParams { // Struct constructor. IndiUltimateOscillatorParams(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) { + : IndicatorParams(INDI_ULTIMATE_OSCILLATOR) { fast_k = _fast_k; fast_period = _fast_period; middle_k = _middle_k; middle_period = _middle_period; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Ultimate_Oscillator"); shift = _shift; slow_k = _slow_k; @@ -68,7 +68,7 @@ class Indi_UltimateOscillator : public IndicatorTickOrCandleSource= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_UltimateOscillator::iUO(GetSymbol(), GetTf(), /*[*/ GetFastPeriod(), GetMiddlePeriod(), GetSlowPeriod(), GetFastK(), GetMiddleK(), GetSlowK() /*]*/, _mode, diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index 7ec863d0d..99d4402ee 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -35,11 +35,11 @@ struct IndiVIDYAParams : IndicatorParams { // Struct constructor. IndiVIDYAParams(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) { + : IndicatorParams(INDI_VIDYA) { applied_price = _ap; cmo_period = _cmo_period; ma_period = _ma_period; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\VIDYA"); shift = _shift; vidya_shift = _vidya_shift; @@ -58,7 +58,8 @@ class Indi_VIDYA : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_VIDYA(IndiVIDYAParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_VIDYA(IndiVIDYAParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_VIDYA(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_VIDYA, _tf, _shift){}; @@ -164,7 +165,7 @@ class Indi_VIDYA : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_VIDYA::iVIDyA(GetSymbol(), GetTf(), /*[*/ GetCMOPeriod(), GetMAPeriod(), GetVIDYAShift(), GetAppliedPrice() /*]*/, 0, _ishift, THIS_PTR); diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index d06dc12fa..cabb98f4c 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -31,10 +31,10 @@ struct IndiVROCParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. IndiVROCParams(unsigned int _period = 25, ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_VROC, 1, TYPE_DOUBLE) { + : IndicatorParams(INDI_VROC) { applied_volume = _applied_volume; period = _period; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\VROC"); shift = _shift; }; @@ -52,7 +52,8 @@ class Indi_VROC : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_VROC(IndiVROCParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_VROC(IndiVROCParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_VROC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_VROC, _tf, _shift){}; @@ -144,7 +145,7 @@ class Indi_VROC : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_VROC::iVROC(GetSymbol(), GetTf(), /*[*/ GetPeriod(), GetAppliedVolume() /*]*/, _mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 9a22469f2..3eab3b41e 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -29,12 +29,10 @@ struct IndiVolumesParams : IndicatorParams { ENUM_APPLIED_VOLUME applied_volume; // Struct constructor. - IndiVolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) - : IndicatorParams(INDI_VOLUMES, 2, TYPE_DOUBLE) { + IndiVolumesParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_VOLUMES) { applied_volume = _applied_volume; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\Volumes"); - SetDataSourceType(IDATA_BUILTIN); shift = _shift; }; IndiVolumesParams(IndiVolumesParams &_params, ENUM_TIMEFRAMES _tf) { @@ -51,7 +49,8 @@ class Indi_Volumes : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_Volumes(IndiVolumesParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_Volumes(IndiVolumesParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(2, TYPE_DOUBLE, IDATA_BUILTIN), _indi_src){}; Indi_Volumes(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_VOLUMES, _tf, _shift){}; @@ -138,7 +137,7 @@ class Indi_Volumes : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_Volumes::iVolumes(GetSymbol(), GetTf(), /*[*/ GetAppliedVolume() /*]*/, _mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Indi_WPR.mqh index a4954ae71..08fa01f9a 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Indi_WPR.mqh @@ -35,10 +35,9 @@ double iWPR(string _symbol, int _tf, int _period, int _shift) { struct IndiWPRParams : IndicatorParams { unsigned int period; // Struct constructors. - IndiWPRParams(unsigned int _period = 14, int _shift = 0) - : period(_period), IndicatorParams(INDI_WPR, 1, TYPE_DOUBLE) { + IndiWPRParams(unsigned int _period = 14, int _shift = 0) : period(_period), IndicatorParams(INDI_WPR) { shift = _shift; - SetDataValueRange(IDATA_RANGE_RANGE); + // SetDataValueRange(IDATA_RANGE_RANGE); SetCustomIndicatorName("Examples\\WPR"); }; IndiWPRParams(IndiWPRParams &_params, ENUM_TIMEFRAMES _tf) { @@ -55,7 +54,8 @@ class Indi_WPR : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_WPR(IndiWPRParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_WPR(IndiWPRParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src) {} Indi_WPR(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_WPR, _tf, _shift) {} /** @@ -104,7 +104,7 @@ class Indi_WPR : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_WPR::iWPR(GetSymbol(), GetTf(), GetPeriod(), _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index c46b3c9dc..8bca741a6 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -28,8 +28,8 @@ // Structs. struct IndiWilliamsADParams : IndicatorParams { // Struct constructor. - IndiWilliamsADParams(int _shift = 0) : IndicatorParams(INDI_WILLIAMS_AD, 1, TYPE_DOUBLE) { - SetDataValueRange(IDATA_RANGE_MIXED); + IndiWilliamsADParams(int _shift = 0) : IndicatorParams(INDI_WILLIAMS_AD) { + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\W_AD"); shift = _shift; }; @@ -48,7 +48,7 @@ class Indi_WilliamsAD : public IndicatorTickOrCandleSource * Class constructor. */ Indi_WilliamsAD(IndiWilliamsADParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTickOrCandleSource(_p, _indi_src){}; + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_WilliamsAD(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_WILLIAMS_AD, _tf, _shift){}; @@ -138,7 +138,7 @@ class Indi_WilliamsAD : public IndicatorTickOrCandleSource virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_WilliamsAD::iWAD(GetSymbol(), GetTf(), _mode, _ishift, THIS_PTR); break; diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index 316b8a704..603b32d24 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -35,13 +35,10 @@ struct IndiZigZagParams : IndicatorParams { unsigned int backstep; // Struct constructors. IndiZigZagParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) - : depth(_depth), - deviation(_deviation), - backstep(_backstep), - IndicatorParams(INDI_ZIGZAG, FINAL_ZIGZAG_LINE_ENTRY, TYPE_DOUBLE) { + : depth(_depth), deviation(_deviation), backstep(_backstep), IndicatorParams(INDI_ZIGZAG) { shift = _shift; SetCustomIndicatorName("Examples\\ZigZag"); - SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Draws lines between lowest and highest prices! + // SetDataValueRange(IDATA_RANGE_PRICE); // @fixit Draws lines between lowest and highest prices! }; IndiZigZagParams(IndiZigZagParams &_params, ENUM_TIMEFRAMES _tf) { THIS_REF = _params; @@ -63,7 +60,9 @@ class Indi_ZigZag : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_ZigZag(IndiZigZagParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src) {} + Indi_ZigZag(IndiZigZagParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(FINAL_ZIGZAG_LINE_ENTRY, TYPE_DOUBLE), + _indi_src) {} Indi_ZigZag(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_ZIGZAG, _tf, _shift) {} @@ -350,7 +349,7 @@ class Indi_ZigZag : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_ZigZag::iZigZag(GetSymbol(), GetTf(), /*[*/ GetDepth(), GetDeviation(), GetBackstep() /*]*/, (ENUM_ZIGZAG_LINE)_mode, _ishift, THIS_PTR); diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 013de75f9..9642f26c7 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -35,11 +35,11 @@ struct IndiZigZagColorParams : IndicatorParams { // Struct constructor. IndiZigZagColorParams(unsigned int _depth = 12, unsigned int _deviation = 5, unsigned int _backstep = 3, int _shift = 0) - : IndicatorParams(INDI_ZIGZAG_COLOR, 3, TYPE_DOUBLE) { + : IndicatorParams(INDI_ZIGZAG_COLOR) { backstep = _backstep; depth = _depth; deviation = _deviation; - SetDataValueRange(IDATA_RANGE_MIXED); + // SetDataValueRange(IDATA_RANGE_MIXED); SetCustomIndicatorName("Examples\\ZigZagColor"); shift = _shift; }; @@ -58,7 +58,7 @@ class Indi_ZigZagColor : public IndicatorTickOrCandleSource= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: _value = Indi_ZigZagColor::iZigZagColor(GetSymbol(), GetTf(), /*[*/ GetDepth(), GetDeviation(), GetBackstep() /*]*/, (ENUM_ZIGZAG_LINE)_mode, _ishift, THIS_PTR); diff --git a/Indicators/OHLC/Indi_OHLC.mqh b/Indicators/OHLC/Indi_OHLC.mqh index aa8735b59..5a9fd642c 100644 --- a/Indicators/OHLC/Indi_OHLC.mqh +++ b/Indicators/OHLC/Indi_OHLC.mqh @@ -37,9 +37,7 @@ enum ENUM_INDI_OHLC_MODE { // Structs. struct IndiOHLCParams : IndicatorParams { // Struct constructor. - IndiOHLCParams(int _shift = 0) : IndicatorParams(INDI_OHLC, FINAL_INDI_OHLC_MODE_ENTRY, TYPE_DOUBLE) { - SetShift(_shift); - }; + IndiOHLCParams(int _shift = 0) : IndicatorParams(INDI_OHLC) { SetShift(_shift); }; IndiOHLCParams(IndiOHLCParams &_params, ENUM_TIMEFRAMES _tf) { THIS_REF = _params; tf = _tf; @@ -54,7 +52,9 @@ class Indi_OHLC : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_OHLC(IndiOHLCParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_OHLC(IndiOHLCParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(FINAL_INDI_OHLC_MODE_ENTRY, TYPE_DOUBLE), + _indi_src){}; Indi_OHLC(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_PRICE, _tf, _shift){}; diff --git a/Indicators/Price/Indi_Price.mqh b/Indicators/Price/Indi_Price.mqh index 53700b731..827381fb6 100644 --- a/Indicators/Price/Indi_Price.mqh +++ b/Indicators/Price/Indi_Price.mqh @@ -29,8 +29,7 @@ struct PriceIndiParams : IndicatorParams { ENUM_APPLIED_PRICE ap; // Struct constructor. - PriceIndiParams(ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0) - : ap(_ap), IndicatorParams(INDI_PRICE, 1, TYPE_DOUBLE) { + PriceIndiParams(ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0) : ap(_ap), IndicatorParams(INDI_PRICE) { SetShift(_shift); }; PriceIndiParams(PriceIndiParams &_params, ENUM_TIMEFRAMES _tf) { @@ -51,7 +50,8 @@ class Indi_Price : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_Price(PriceIndiParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_Price(PriceIndiParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE), _indi_src){}; Indi_Price(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_PRICE, _tf, _shift){}; diff --git a/Indicators/Special/Indi_Custom.mqh b/Indicators/Special/Indi_Custom.mqh index 9e6daade7..8b59f5c36 100644 --- a/Indicators/Special/Indi_Custom.mqh +++ b/Indicators/Special/Indi_Custom.mqh @@ -41,9 +41,8 @@ struct IndiCustomParams : public IndicatorParams { DataParamEntry iargs[]; // Struct constructors. - IndiCustomParams(string _filepath = INDI_CUSTOM_PATH, int _shift = 0) : IndicatorParams(INDI_CUSTOM, 1, TYPE_DOUBLE) { + IndiCustomParams(string _filepath = INDI_CUSTOM_PATH, int _shift = 0) : IndicatorParams(INDI_CUSTOM) { custom_indi_name = _filepath; - SetDataSourceType(IDATA_ICUSTOM); } IndiCustomParams(IndiCustomParams &_params, ENUM_TIMEFRAMES _tf) { THIS_REF = _params; @@ -79,7 +78,8 @@ class Indi_Custom : public Indicator { /** * Class constructor. */ - Indi_Custom(IndiCustomParams &_p, IndicatorData *_indi_src = NULL) : Indicator(_p, _indi_src) {} + Indi_Custom(IndiCustomParams &_p, IndicatorData *_indi_src = NULL) + : Indicator(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, IDATA_ICUSTOM), _indi_src) {} Indi_Custom(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CUSTOM, _tf){}; /** @@ -88,19 +88,19 @@ class Indi_Custom : public Indicator { IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = -1) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_ICUSTOM: switch (iparams.GetParamsSize()) { case 0: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, _mode, _ishift); break; case 1: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, iparams.GetParam(1).ToValue(), _mode, _ishift); break; case 2: - _value = iCustom(istate.handle, Get(CHART_PARAM_SYMBOL), Get(CHART_PARAM_TF), + _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, iparams.GetParam(1).ToValue(), iparams.GetParam(2).ToValue(), _mode, _ishift); break; diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 80190ab0e..b0e271bb0 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -43,13 +43,12 @@ struct IndiMathParams : IndicatorParams { IndiMathParams(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) { + : IndicatorParams(INDI_SPECIAL_MATH) { mode_1 = _mode_1; mode_2 = _mode_2; op_builtin = _op; op_mode = MATH_OP_MODE_BUILTIN; - SetDataValueRange(IDATA_RANGE_MIXED); - SetDataSourceType(IDATA_INDICATOR); + // SetDataValueRange(IDATA_RANGE_MIXED); shift = _shift; shift_1 = _shift_1; shift_2 = _shift_2; @@ -60,14 +59,12 @@ struct IndiMathParams : IndicatorParams { IndiMathParams(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; + : IndicatorParams(INDI_SPECIAL_MATH) { mode_1 = _mode_1; mode_2 = _mode_2; op_fn = _op; op_mode = MATH_OP_MODE_CUSTOM_FUNCTION; - SetDataValueRange(IDATA_RANGE_MIXED); - SetDataSourceType(IDATA_INDICATOR); + // SetDataValueRange(IDATA_RANGE_MIXED); shift = _shift; shift_1 = _shift_1; shift_2 = _shift_2; @@ -87,7 +84,8 @@ class Indi_Math : public IndicatorTickOrCandleSource { /** * Class constructor. */ - Indi_Math(IndiMathParams &_p, IndicatorData *_indi_src = NULL) : IndicatorTickOrCandleSource(_p, _indi_src){}; + Indi_Math(IndiMathParams &_p, IndicatorData *_indi_src = NULL) + : IndicatorTickOrCandleSource(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, IDATA_INDICATOR), _indi_src){}; Indi_Math(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_SPECIAL_MATH, _tf, _shift){}; @@ -97,7 +95,7 @@ class Indi_Math : public IndicatorTickOrCandleSource { virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) { double _value = EMPTY_VALUE; int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); - switch (iparams.idstype) { + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_INDICATOR: if (!indi_src.IsSet()) { GetLogger().Error( diff --git a/Indicators/Tick/Indi_TickMt.mqh b/Indicators/Tick/Indi_TickMt.mqh index 2ea365183..20c0fe906 100644 --- a/Indicators/Tick/Indi_TickMt.mqh +++ b/Indicators/Tick/Indi_TickMt.mqh @@ -27,7 +27,7 @@ struct IndiTickMtParams : IndicatorParams { string symbol; // Struct constructor. - IndiTickMtParams(string _symbol = NULL, int _shift = 0) : IndicatorParams(INDI_TICK, 3, TYPE_DOUBLE) { + IndiTickMtParams(string _symbol = NULL, int _shift = 0) : IndicatorParams(INDI_TICK) { SetShift(_shift); SetSymbol(_symbol); }; @@ -53,7 +53,7 @@ class Indi_TickMt : public IndicatorTick { * Class constructor. */ Indi_TickMt(IndiTickMtParams &_p, IndicatorData *_indi_src = NULL) - : IndicatorTick(_p, _indi_src){}; + : IndicatorTick(_p, IndicatorDataParams::GetInstance(3, TYPE_DOUBLE), _indi_src){}; Indi_TickMt(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, string _name = "") : IndicatorTick(INDI_TICK, _tf, _shift, _name) {} diff --git a/Strategy.mqh b/Strategy.mqh index 7ec1cde9c..07179d1e2 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -1206,13 +1206,13 @@ class Strategy : public Object { int _count = (int)fmax(fabs(_level), fabs(_method)); int _direction = Order::OrderDirection(_cmd, _mode); Chart *_chart = trade.GetChart(); - IndicatorBase *_indi = GetIndicators().Begin().Value().Ptr(); + IndicatorData *_indi = GetIndicators().Begin().Value().Ptr(); StrategyPriceStop _psm(_method); _psm.SetChartParams(_chart.GetParams()); if (Object::IsValid(_indi)) { - int _ishift = 12; // @todo: Make it dynamic or as variable. - float _value = 0.0f; // @todo - //float _value = _indi.GetValuePrice(_ishift, 0, _direction > 0 ? PRICE_HIGH : PRICE_LOW); + int _ishift = 12; // @todo: Make it dynamic or as variable. + float _value = 0.0f; // @todo + // 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); /* diff --git a/tests/DrawIndicatorTest.mq5 b/tests/DrawIndicatorTest.mq5 index ef1988fc4..85e54b041 100644 --- a/tests/DrawIndicatorTest.mq5 +++ b/tests/DrawIndicatorTest.mq5 @@ -153,7 +153,7 @@ bool InitIndicators() { bool PrintIndicators(string _prefix = "") { ResetLastError(); for (DictIterator iter = indis.Begin(); iter.IsValid(); ++iter) { - IndicatorBase *_indi = iter.Value(); + IndicatorData *_indi = iter.Value(); if (_indi.Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY))) { PrintFormat("%s: %s: %s", _prefix, _indi.GetName(), _indi.ToString()); } diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index f90c7df14..d37403b81 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -164,7 +164,8 @@ bool InitIndicators() { indis.Push(new Indi_AO()); // Accumulation Swing Index (ASI). - indis.Push(new Indi_ASI()); + IndiASIParams _asi_params; + indis.Push(new Indi_ASI(_asi_params)); // Average True Range (ATR). IndiATRParams atr_params(14); @@ -177,7 +178,7 @@ bool InitIndicators() { // Bollinger Bands over RSI. IndiBandsParams bands_over_rsi_params(20, 2, 0, PRICE_OPEN); - bands_over_rsi_params.SetDataSource(INDI_RSI); + // bands_over_rsi_params.SetDataSource(INDI_RSI); indis.Push(new Indi_Bands(bands_over_rsi_params)); // Bears Power. @@ -220,7 +221,8 @@ bool InitIndicators() { indis.Push(new Indi_Gator(gator_params)); // Heiken Ashi. - indis.Push(new Indi_HeikenAshi()); + IndiHeikenAshiParams _ha_params(); + indis.Push(new Indi_HeikenAshi(_ha_params)); // Ichimoku Kinko Hyo. IndiIchimokuParams ichi_params(9, 26, 52); @@ -262,7 +264,7 @@ bool InitIndicators() { // Relative Strength Index (RSI). IndiRSIParams rsi_over_blt_stddev_params(); - rsi_over_blt_stddev_params.SetDataSource(INDI_STDDEV); + // rsi_over_blt_stddev_params.SetDataSource(INDI_STDDEV); indis.Push(new Indi_RSI(rsi_over_blt_stddev_params)); // Relative Vigor Index (RVI). @@ -396,12 +398,14 @@ bool InitIndicators() { indis.Push(indi_rsi_on_price.Ptr()); // Drawer (socket-based) indicator over RSI over Price. +#ifndef __MQL4__ // @fixme: Fix it for MQL4. IndiDrawerParams drawer_params(14, /*unused*/ PRICE_OPEN); drawer_params.SetDraw(clrBisque, 0); - drawer_params.SetMaxModes(rsi_on_price_params.GetMaxModes()); + // drawer_params.SetMaxModes(rsi_on_price_params.GetMaxModes()); Ref indi_drawer_on_rsi = new Indi_Drawer(drawer_params); indi_drawer_on_rsi.Ptr().SetDataSource(indi_rsi_on_price.Ptr(), PRICE_OPEN); indis.Push(indi_drawer_on_rsi.Ptr()); +#endif // Applied Price over OHCL indicator. IndiAppliedPriceParams applied_price_params(); @@ -429,7 +433,6 @@ bool InitIndicators() { // Original AMA. IndiAMAParams ama_params_orig(); ama_params_orig.SetName("Original AMA to compare"); - ama_params_orig.SetDataSourceType(IDATA_BUILTIN); indis.Push(new Indi_AMA(ama_params_orig)); // Chaikin Oscillator.