Skip to content

Commit

Permalink
Merge pull request #543 from EA31337/dev
Browse files Browse the repository at this point in the history
Development enhancements
  • Loading branch information
kenorb authored Aug 18, 2021
2 parents 24d7652 + 73d8154 commit 550c858
Show file tree
Hide file tree
Showing 44 changed files with 150 additions and 80 deletions.
3 changes: 2 additions & 1 deletion Bar.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Serializer;
/* Struct for storing OHLC values. */
struct BarOHLC
#ifndef __MQL__
: public ISerializable
: public ISerializable
#endif
{
datetime time;
Expand Down Expand Up @@ -221,6 +221,7 @@ struct BarOHLC
// State checkers.
bool IsBear() const { return open > close; }
bool IsBull() const { return open < close; }
bool IsValid() const { return high >= low && fmin(open, close) > 0; }
// Serializers.
SerializerNodeType Serialize(Serializer &s);
// Converters.
Expand Down
9 changes: 5 additions & 4 deletions Indicator.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,17 @@ enum ENUM_INDICATOR_TYPE {

/* Defines type of source data for indicator. */
enum ENUM_IDATA_SOURCE_TYPE {
IDATA_BUILTIN, // Use builtin function.
IDATA_ICUSTOM, // Use custom indicator file (iCustom).
IDATA_INDICATOR, // Use indicator class as source of data with custom calculation.
IDATA_MATH // Use Math-based indicator over Price indicator.
IDATA_BUILTIN, // Platform built-in
IDATA_ICUSTOM, // Custom indicator file (iCustom)
IDATA_INDICATOR, // Another indicator as a source of data
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.
Expand Down
21 changes: 16 additions & 5 deletions Indicator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,22 @@ class Indicator : public Chart {

/* Getters */

/**
* Gets an indicator's chart parameter value.
*/
template <typename T>
T Get(ENUM_CHART_PARAM _param) {
return Chart::Get<T>(_param);
}

/**
* Gets an indicator's state property value.
*/
template <typename T>
T Get(STRUCT_ENUM(IndicatorState, ENUM_INDICATOR_STATE_PROP) _prop) {
return istate.Get<T>(_prop);
}

/**
* Gets an indicator property flag.
*/
Expand Down Expand Up @@ -856,11 +872,6 @@ class Indicator : public Chart {
return name + ")";
}

/**
* Get indicator's state.
*/
IndicatorState GetState() { return istate; }

/* Setters */

/**
Expand Down
23 changes: 22 additions & 1 deletion Indicator.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,34 @@ struct IndicatorParams {

/* Structure for indicator state. */
struct IndicatorState {
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.
int GetHandle() { return handle; }
template <typename T>
#ifdef __MQL4__
T Get(ENUM_INDICATOR_STATE_PROP _prop) {
#else
T Get(IndicatorState::ENUM_INDICATOR_STATE_PROP _prop) {
#endif
switch (_prop) {
case INDICATOR_STATE_PROP_HANDLE:
return (T)handle;
case INDICATOR_STATE_PROP_IS_CHANGED:
return (T)is_changed;
case INDICATOR_STATE_PROP_IS_READY:
return (T)is_ready;
}
SetUserError(ERR_INVALID_PARAMETER);
return (T)WRONG_VALUE;
}
// State checkers.
bool IsChanged() { return is_changed; }
bool IsReady() { return is_ready; }
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_AC.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Indi_AC : public Indicator {
#ifdef __MQL4__
return ::iAC(_symbol, _tf, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_AD.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Indi_AD : public Indicator {
#ifdef __MQL4__
return ::iAD(_symbol, _tf, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_ADX.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Indi_ADX : public Indicator {
#ifdef __MQL4__
return ::iADX(_symbol, _tf, _period, _applied_price, _mode, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_AO.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Indi_AO : public Indicator {
// Note: In MQL4 _mode is not supported.
return ::iAO(_symbol, _tf, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_ATR.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Indi_ATR : public Indicator {
#ifdef __MQL4__
return ::iATR(_symbol, _tf, _period, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Alligator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Indi_Alligator : public Indicator {
return ::iAlligator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift,
_ma_method, _applied_price, _mode, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_BWMFI.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Indi_BWMFI : public Indicator {
_shift++;
return ::iBWMFI(_symbol, _tf, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Bands.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Indi_Bands : public Indicator {
#ifdef __MQL4__
return ::iBands(_symbol, _tf, _period, _deviation, _bands_shift, _applied_price, _mode, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_BearsPower.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Indi_BearsPower : public Indicator {
#ifdef __MQL4__
return ::iBearsPower(_symbol, _tf, _period, _applied_price, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_BullsPower.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Indi_BullsPower : public Indicator {
#ifdef __MQL4__
return ::iBullsPower(_symbol, _tf, _period, _applied_price, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_CCI.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Indi_CCI : public Indicator {
#ifdef __MQL4__
return ::iCCI(_symbol, _tf, _period, _applied_price, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_DEMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Indi_DEMA : public Indicator {
ENUM_APPLIED_PRICE _applied_price, int _shift = 0, int _mode = 0, Indicator *_obj = NULL) {
ResetLastError();
#ifdef __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_DeMarker.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Indi_DeMarker : public Indicator {
#ifdef __MQL4__
return ::iDeMarker(_symbol, _tf, _period, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Envelopes.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Indi_Envelopes : public Indicator {
_mode = 1;
break;
}
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Force.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Indi_Force : public Indicator {
#ifdef __MQL4__
return ::iForce(_symbol, _tf, _period, _ma_method, _applied_price, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Fractals.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Indi_Fractals : public Indicator {
#ifdef __MQL4__
return ::iFractals(_symbol, _tf, _mode, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Gator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Indi_Gator : public Indicator {
return ::iGator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift,
_ma_method, _applied_price, _mode, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_HeikenAshi.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Indi_HeikenAshi : public Indicator {
}
return ::iCustom(_symbol, _tf, "Heiken Ashi", _mode, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Ichimoku.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Indi_Ichimoku : public Indicator {
#ifdef __MQL4__
return ::iIchimoku(_symbol, _tf, _tenkan_sen, _kijun_sen, _senkou_span_b, _mode, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_MA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Indi_MA : public Indicator {
#ifdef __MQL4__
return ::iMA(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_price, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_MACD.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Indi_MACD : public Indicator {
#ifdef __MQL4__
return ::iMACD(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price, _mode, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_MFI.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Indi_MFI : public Indicator {
#ifdef __MQL4__
return ::iMFI(_symbol, _tf, _period, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Momentum.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Indi_Momentum : public Indicator {
#ifdef __MQL4__
return ::iMomentum(_symbol, _tf, _period, _ap, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_OBV.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Indi_OBV : public Indicator {
#ifdef __MQL4__
return ::iOBV(_symbol, _tf, _applied, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_OsMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Indi_OsMA : public Indicator {
#ifdef __MQL4__
return ::iOsMA(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price, _shift);
#else // __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.GetState().GetHandle() : NULL;
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
ResetLastError();
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand Down
Loading

0 comments on commit 550c858

Please sign in to comment.