Skip to content

Commit

Permalink
Bar/Indi_Pattern: Extra validation of OHLC
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Aug 18, 2021
1 parent a8668f9 commit 2bf79bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 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
6 changes: 5 additions & 1 deletion Indicators/Indi_Pattern.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class Indi_Pattern : public Indicator {
_ohlcs[i].high = GetDataSource().GetValue<float>(_shift + i, PRICE_HIGH);
_ohlcs[i].low = GetDataSource().GetValue<float>(_shift + i, PRICE_LOW);
_ohlcs[i].close = GetDataSource().GetValue<float>(_shift + i, PRICE_CLOSE);
if (!_ohlcs[i].IsValid()) {
// Return empty entry on invalid candles.
return _entry;
}
}
break;
default:
Expand All @@ -120,7 +124,7 @@ class Indi_Pattern : public Indicator {
}

_entry.SetFlag(INDI_ENTRY_FLAG_IS_BITWISE, true);
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _entry.values[1] > 0);
_entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, _ohlcs[0].IsValid() && _entry.values[1] > 0);

if (_entry.IsValid()) {
istate.is_ready = true;
Expand Down

0 comments on commit 2bf79bb

Please sign in to comment.