Skip to content

Commit

Permalink
Merge branch 'dev-getvalue-refactor' into dev
Browse files Browse the repository at this point in the history
* dev-getvalue-refactor:
  Probably finished IndicatorDataEntry per-value type refactoring.
  In the middle of Indicator::GetValue -> GetMixedValue refactoring.
  Indicators: Data types handling refactor [WIP]
  • Loading branch information
kenorb committed Nov 8, 2021
2 parents bb8e34a + e0a463c commit 23570e9
Show file tree
Hide file tree
Showing 77 changed files with 433 additions and 325 deletions.
13 changes: 6 additions & 7 deletions Indicator.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,11 @@ enum ENUM_APPLIED_VOLUME { VOLUME_TICK = 0, VOLUME_REAL = 1 };
enum INDICATOR_ENTRY_FLAGS {
INDI_ENTRY_FLAG_NONE = 0 << 0,
INDI_ENTRY_FLAG_IS_BITWISE = 1 << 0,
INDI_ENTRY_FLAG_IS_DOUBLE = 1 << 1,
INDI_ENTRY_FLAG_IS_DOUBLED = 1 << 1, // Type is doubled in size (e.g. double or long).
INDI_ENTRY_FLAG_IS_EXPIRED = 1 << 2,
INDI_ENTRY_FLAG_IS_FLOAT = 1 << 3,
INDI_ENTRY_FLAG_IS_INT = 1 << 4,
INDI_ENTRY_FLAG_IS_LONG = 1 << 5,
INDI_ENTRY_FLAG_IS_PRICE = 1 << 6,
INDI_ENTRY_FLAG_IS_VALID = 1 << 7,
INDI_ENTRY_FLAG_INSUFFICIENT_DATA = 1 << 8, // Entry has missing value for that shift and probably won't ever have.
INDI_ENTRY_FLAG_IS_REAL = 1 << 3, // Type is real (float or double).
INDI_ENTRY_FLAG_IS_PRICE = 1 << 4,
INDI_ENTRY_FLAG_IS_UNSIGNED = 1 << 5, // Type is unsigned (uint or ulong).
INDI_ENTRY_FLAG_IS_VALID = 1 << 6,
INDI_ENTRY_FLAG_INSUFFICIENT_DATA = 1 << 7, // Entry has missing value for that shift and probably won't ever have.
};
99 changes: 82 additions & 17 deletions Indicator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -884,15 +884,32 @@ class Indicator : public IndicatorBase {
bool _result = true;
_result &= _entry.timestamp > 0;
_result &= _entry.GetSize() > 0;
if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_DOUBLE)) {
_result &= !_entry.HasValue<double>(DBL_MAX);
_result &= !_entry.HasValue<double>(NULL);
} else if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_FLOAT)) {
_result &= !_entry.HasValue<float>(FLT_MAX);
_result &= !_entry.HasValue<float>(NULL);
} else if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_INT)) {
_result &= !_entry.HasValue<int>(INT_MAX);
_result &= !_entry.HasValue<int>(NULL);
if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_REAL)) {
if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_DOUBLED)) {
_result &= !_entry.HasValue<double>(DBL_MAX);
_result &= !_entry.HasValue<double>(NULL);
} else {
_result &= !_entry.HasValue<float>(FLT_MAX);
_result &= !_entry.HasValue<float>(NULL);
}
} else {
if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_UNSIGNED)) {
if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_DOUBLED)) {
_result &= !_entry.HasValue<ulong>(ULONG_MAX);
_result &= !_entry.HasValue<ulong>(NULL);
} else {
_result &= !_entry.HasValue<uint>(UINT_MAX);
_result &= !_entry.HasValue<uint>(NULL);
}
} else {
if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_DOUBLED)) {
_result &= !_entry.HasValue<long>(LONG_MAX);
_result &= !_entry.HasValue<long>(NULL);
} else {
_result &= !_entry.HasValue<int>(INT_MAX);
_result &= !_entry.HasValue<int>(NULL);
}
}
}
return _result;
}
Expand Down Expand Up @@ -922,7 +939,33 @@ class Indicator : public IndicatorBase {
_entry.Resize(iparams.GetMaxModes());
_entry.timestamp = GetBarTime(_ishift);
for (int _mode = 0; _mode < (int)iparams.GetMaxModes(); _mode++) {
_entry.values[_mode] = GetValue(_mode, _ishift);
switch (iparams.GetDataValueType()) {
case TYPE_BOOL:
case TYPE_CHAR:
case TYPE_INT:
_entry.values[_mode] = GetValue<int>(_mode, _ishift);
break;
case TYPE_LONG:
_entry.values[_mode] = GetValue<long>(_mode, _ishift);
break;
case TYPE_UINT:
_entry.values[_mode] = GetValue<uint>(_mode, _ishift);
break;
case TYPE_ULONG:
_entry.values[_mode] = GetValue<ulong>(_mode, _ishift);
break;
case TYPE_DOUBLE:
_entry.values[_mode] = GetValue<double>(_mode, _ishift);
break;
case TYPE_FLOAT:
_entry.values[_mode] = GetValue<float>(_mode, _ishift);
break;
case TYPE_STRING:
case TYPE_UCHAR:
default:
SetUserError(ERR_INVALID_PARAMETER);
break;
}
}
GetEntryAlter(_entry, _ishift);
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, IsValidEntry(_entry));
Expand All @@ -948,7 +991,7 @@ class Indicator : public IndicatorBase {
* This method is called on GetEntry() right after values are set.
*/
virtual void GetEntryAlter(IndicatorDataEntry& _entry, int _shift = -1) {
_entry.AddFlags(_entry.GetDataTypeFlag(iparams.GetDataValueType()));
_entry.AddFlags(_entry.GetDataTypeFlags(iparams.GetDataValueType()));
};

/**
Expand All @@ -962,25 +1005,47 @@ class Indicator : public IndicatorBase {
virtual DataParamEntry GetEntryValue(int _shift = -1, int _mode = 0) {
IndicatorDataEntry _entry = GetEntry(_shift >= 0 ? _shift : iparams.GetShift());
DataParamEntry _value_entry;
if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_DOUBLE)) {
_value_entry = _entry.GetValue<double>(_mode);
} else if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_FLOAT)) {
_value_entry = _entry.GetValue<float>(_mode);
} else if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_INT)) {
_value_entry = _entry.GetValue<int>(_mode);
switch (iparams.GetDataValueType()) {
case TYPE_BOOL:
case TYPE_CHAR:
case TYPE_INT:
_value_entry = _entry.GetValue<int>(_mode);
break;
case TYPE_LONG:
_value_entry = _entry.GetValue<long>(_mode);
break;
case TYPE_UINT:
_value_entry = _entry.GetValue<uint>(_mode);
break;
case TYPE_ULONG:
_value_entry = _entry.GetValue<ulong>(_mode);
break;
case TYPE_DOUBLE:
_value_entry = _entry.GetValue<double>(_mode);
break;
case TYPE_FLOAT:
_value_entry = _entry.GetValue<float>(_mode);
break;
case TYPE_STRING:
case TYPE_UCHAR:
default:
SetUserError(ERR_INVALID_PARAMETER);
break;
}
return _value_entry;
}

/**
* Returns the indicator's value.
*/
/*
virtual double GetValue(int _shift = -1, int _mode = 0) {
_shift = _shift >= 0 ? _shift : iparams.GetShift();
istate.is_changed = false;
istate.is_ready = false;
return EMPTY_VALUE;
}
*/
};

#endif
Loading

0 comments on commit 23570e9

Please sign in to comment.