Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/EA31337/EA31337-classes into…
Browse files Browse the repository at this point in the history
… dev-c++
  • Loading branch information
nseam committed Jul 20, 2021
2 parents d9307d2 + d1ee8c1 commit 8619ee7
Show file tree
Hide file tree
Showing 82 changed files with 440 additions and 93 deletions.
1 change: 1 addition & 0 deletions Bar.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ struct BarOHLC
}
return _r4 > _r3 && _r3 > _r2 && _r2 > _r1 && _r1 > _pp && _pp > _s1 && _s1 > _s2 && _s2 > _s3 && _s3 > _s4;
}
datetime GetTime() { return time; }
float GetAppliedPrice(ENUM_APPLIED_PRICE _ap) const { return BarOHLC::GetAppliedPrice(_ap, open, high, low, close); }
float GetBody() const { return close - open; }
float GetBodyAbs() const { return fabs(close - open); }
Expand Down
24 changes: 14 additions & 10 deletions BufferStruct.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,21 @@ class BufferStruct : public DictStruct<long, TStruct> {
void Clear(long _dt = 0, bool _older = true) {
min = INT_MAX;
max = INT_MIN;
for (DictStructIterator<long, TStruct> iter(Begin()); iter.IsValid(); ++iter) {
long _time = iter.Key();
if (_older && _time < _dt) {
Unset(iter.Key());
continue;
} else if (!_older && _time > _dt) {
Unset(iter.Key());
continue;
if (_dt > 0) {
for (DictStructIterator<long, TStruct> iter(Begin()); iter.IsValid(); ++iter) {
long _time = iter.Key();
if (_older && _time < _dt) {
Unset(iter.Key());
continue;
} else if (!_older && _time > _dt) {
Unset(iter.Key());
continue;
}
min = _time < min ? _time : min;
max = _time > max ? _time : max;
}
min = _time < min ? _time : min;
max = _time > max ? _time : max;
} else {
DictStruct<long, TStruct>::Clear();
}
}

Expand Down
8 changes: 7 additions & 1 deletion Chart.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ class Chart : public Market {
return _chart_entry;
}

/* State checking */
/**
* Gets copy of params.
*
* @return
* Returns structure for Trade's params.
*/
ChartParams GetParams() const { return cparams; }

/* State checking */

Expand Down
5 changes: 3 additions & 2 deletions Indicator.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ enum ENUM_IDATA_VALUE_RANGE {
IDATA_RANGE_ARROW, // Value is non-zero on signal.
IDATA_RANGE_BINARY, // E.g. 0 or 1.
IDATA_RANGE_MIXED,
IDATA_RANGE_PRICE, // Values represent price.
IDATA_RANGE_RANGE, // E.g. 0 to 100.
IDATA_RANGE_PRICE, // Values represent price.
IDATA_RANGE_RANGE, // E.g. 0 to 100.
IDATA_RANGE_UNKNOWN
};

Expand Down Expand Up @@ -204,4 +204,5 @@ enum INDICATOR_ENTRY_FLAGS {
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 propbably won't ever have.
};
28 changes: 15 additions & 13 deletions Indicator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class Indicator : public Chart {
bool CopyEntries(IndicatorDataEntry& _data[], int _count, int _start_shift = 0) {
bool _is_valid = true;
if (ArraySize(_data) < _count) {
_is_valid &= ArrayResize(_data, _count);
_is_valid &= ArrayResize(_data, _count) > 0;
}
for (int i = 0; i < _count; i++) {
IndicatorDataEntry _entry = GetEntry(_start_shift + i);
Expand All @@ -392,14 +392,15 @@ class Indicator : public Chart {
*/
template <typename T>
bool CopyValues(T& _data[], int _count, int _start_shift = 0, int _mode = 0) {
bool _is_valid = true;
if (ArraySize(_data) < _count) {
bool _is_valid = true;
_is_valid &= ArrayResize(_data, _count);
_count = ArrayResize(_data, _count);
_count = _count > 0 ? _count : ArraySize(_data);
}
for (int i = 0; i < _count; i++) {
IndicatorDataEntry _entry = GetEntry(_start_shift + i);
_is_valid &= _entry.IsValid();
_data[i] = _entry<T>[_mode];
_data[i] = (T)_entry[_mode];
}
return _is_valid;
}
Expand Down Expand Up @@ -622,12 +623,12 @@ class Indicator : public Chart {
template <typename T>
int GetHighest(int count = WHOLE_ARRAY, int start_bar = 0) {
int max_idx = -1;
double max = NULL;
double max = -DBL_MAX;
int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1);

for (int shift = start_bar; shift <= last_bar; ++shift) {
double value = GetEntry(shift).GetMax<T>(iparams.max_modes);
if (max == NULL || value > max) {
if (value > max) {
max = value;
max_idx = shift;
}
Expand All @@ -642,12 +643,12 @@ class Indicator : public Chart {
template <typename T>
int GetLowest(int count = WHOLE_ARRAY, int start_bar = 0) {
int min_idx = -1;
double min = NULL;
double min = DBL_MAX;
int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1);

for (int shift = start_bar; shift <= last_bar; ++shift) {
double value = GetEntry(shift).GetMin<T>(iparams.max_modes);
if (min == NULL || value < min) {
if (value < min) {
min = value;
min_idx = shift;
}
Expand Down Expand Up @@ -1063,13 +1064,13 @@ class Indicator : public Chart {
* Returns price value of the corresponding indicator values.
*/
template <typename T>
T GetValuePrice(int _shift = 0, int _mode = -1, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) {
float GetValuePrice(int _shift = 0, int _mode = 0, ENUM_APPLIED_PRICE _ap = PRICE_CLOSE) {
float _price = 0;
if (iparams.GetIDataValueRange() != IDATA_RANGE_PRICE) {
_price = GetPrice(_ap, _shift);
_price = (float)GetPrice(_ap, _shift);
} else if (iparams.GetIDataValueRange() == IDATA_RANGE_PRICE) {
// When indicator values are the actual prices.
T _values[3];
T _values[4];
if (!CopyValues(_values, 4, _shift, _mode)) {
// When values aren't valid, return 0.
return _price;
Expand Down Expand Up @@ -1172,9 +1173,10 @@ class Indicator : public Chart {
*/
virtual string ToString(int _shift = 0) {
IndicatorDataEntry _entry = GetEntry(_shift);
int _serializer_flags = SERIALIZER_FLAG_SKIP_HIDDEN | SERIALIZER_FLAG_INCLUDE_DYNAMIC;
SerializerConverter _stub_indi =
SerializerConverter::MakeStubObject<IndicatorDataEntry>(SERIALIZER_FLAG_SKIP_HIDDEN, _entry.GetSize());
return SerializerConverter::FromObject(_entry, SERIALIZER_FLAG_SKIP_HIDDEN).ToString<SerializerCsv>(0, &_stub_indi);
SerializerConverter::MakeStubObject<IndicatorDataEntry>(_serializer_flags, _entry.GetSize());
return SerializerConverter::FromObject(_entry, _serializer_flags).ToString<SerializerCsv>(0, &_stub_indi);
}
};
#endif
30 changes: 24 additions & 6 deletions Indicator.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ struct IndicatorCalculateCache {

/* Structure for indicator data entry. */
struct IndicatorDataEntry {
long timestamp; // Timestamp of the entry's bar.
unsigned char flags; // Indicator entry flags.
long timestamp; // Timestamp of the entry's bar.
unsigned short flags; // Indicator entry flags.
union IndicatorDataEntryValue {
double vdbl;
float vflt;
Expand Down Expand Up @@ -375,24 +375,42 @@ struct IndicatorDataEntry {
}
return TYPE_DOUBLE;
}
INDICATOR_ENTRY_FLAGS GetDataTypeFlag(ENUM_DATATYPE _dt) {
switch (_dt) {
case TYPE_DOUBLE:
return INDI_ENTRY_FLAG_IS_DOUBLE;
case TYPE_FLOAT:
return INDI_ENTRY_FLAG_IS_FLOAT;
case TYPE_INT:
return INDI_ENTRY_FLAG_IS_INT;
case TYPE_LONG:
return INDI_ENTRY_FLAG_IS_LONG;
default:
break;
}
return (INDICATOR_ENTRY_FLAGS)0;
}
// Value flag methods for bitwise operations.
bool CheckFlags(unsigned short _flags) { return (flags & _flags) != 0; }
bool CheckFlagsAll(unsigned short _flags) { return (flags & _flags) == _flags; }
void AddFlags(unsigned char _flags) { flags |= _flags; }
void RemoveFlags(unsigned char _flags) { flags &= ~_flags; }
void AddFlags(unsigned short _flags) { flags |= _flags; }
void RemoveFlags(unsigned short _flags) { flags &= ~_flags; }
void SetFlag(INDICATOR_ENTRY_FLAGS _flag, bool _value) {
if (_value) {
AddFlags(_flag);
} else {
RemoveFlags(_flag);
}
}
void SetFlags(unsigned char _flags) { flags = _flags; }
void SetFlags(unsigned short _flags) { flags = _flags; }
// Converters.
// State checkers.
bool IsValid() { return CheckFlags(INDI_ENTRY_FLAG_IS_VALID); }
// Serializers.
void SerializeStub(int _n1 = 1, int _n2 = 1, int _n3 = 1, int _n4 = 1, int _n5 = 1) { ArrayResize(values, _n1); }
void SerializeStub(int _n1 = 1, int _n2 = 1, int _n3 = 1, int _n4 = 1, int _n5 = 1) {
ArrayResize(values, _n1);
AddFlags(INDI_ENTRY_FLAG_IS_DOUBLE);
}
SerializerNodeType Serialize(Serializer &_s);
template <typename T>
string ToCSV() {
Expand Down
1 change: 1 addition & 0 deletions Indicators/Bitwise/Indi_Candle.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class Indi_Candle : public Indicator {
istate.is_ready = true;

if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_AC.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Indi_AC : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_AD.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class Indi_AD : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_ADX.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class Indi_ADX : public Indicator {
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) &&
_entry.IsWithinRange(0.0, 100.0));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_ADXW.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Indi_ADXW : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_AMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Indi_AMA : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_AO.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class Indi_AO : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.values[0].Get<double>() != EMPTY_VALUE);
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_ASI.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Indi_ASI : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_ATR.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Indi_ATR : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_Alligator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class Indi_Alligator : public Indicator {
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID,
!_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE) && _entry.IsGt<double>(0));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
5 changes: 4 additions & 1 deletion Indicators/Indi_BWMFI.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ class Indi_BWMFI : public Indicator {
#endif
_entry.values[BWMFI_HISTCOLOR] = _histcolor;
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.values[BWMFI_BUFFER] != 0 && !_entry.HasValue(EMPTY_VALUE));
if (_entry.IsValid()) idata.Add(_entry, _bar_time);
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
return _entry;
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_BWZT.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Indi_BWZT : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_Bands.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class Indi_Bands : public Indicator {
!_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE) && _entry.IsGt(0) &&
_entry.values[BAND_LOWER].GetDbl() < _entry.values[BAND_UPPER].GetDbl());
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_BearsPower.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class Indi_BearsPower : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue((double)NULL) && !_entry.HasValue(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_BullsPower.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Indi_BullsPower : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_CCI.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class Indi_CCI : public Indicator {
_entry.values[0] = GetValue(0);
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_CHO.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Indi_CHO : public Indicator {
_entry.values[0] = GetValue(_shift);
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_CHV.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Indi_CHV : public Indicator {
_entry.values[0] = GetValue(_shift);
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_ColorBars.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Indi_ColorBars : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_ColorCandlesDaily.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Indi_ColorCandlesDaily : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_ColorLine.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Indi_ColorLine : public Indicator {
}
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions Indicators/Indi_CustomMovingAverage.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Indi_CustomMovingAverage : public Indicator {
_entry.values[0] = GetValue(_shift);
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, !_entry.HasValue<double>(NULL) && !_entry.HasValue<double>(EMPTY_VALUE));
if (_entry.IsValid()) {
_entry.AddFlags(_entry.GetDataTypeFlag(params.GetDataValueType()));
idata.Add(_entry, _bar_time);
}
}
Expand Down
Loading

0 comments on commit 8619ee7

Please sign in to comment.