Skip to content

Commit

Permalink
Pattern: Adds PatternBitwise struct
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed May 1, 2021
1 parent cc4e3fa commit 7674c22
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Indicator.struct.serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ SerializerNodeType IndicatorParams::Serialize(Serializer &s) {
s.Pass(this, "draw_window", draw_window, SERIALIZER_FIELD_FLAG_HIDDEN);
s.Pass(this, "custom_indi_name", custom_indi_name);
return SerializerNodeObject;
}
}
8 changes: 4 additions & 4 deletions Pattern.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

/**
* @file
* Provides functionality for detecting multi-candle patterns.
* Provides functionality for detecting candle patterns.
*/

// Includes.
#include "../Chart.mqh"
#include "Pattern.struct.h"

class Pattern {
private:
Chart *chart;
// Chart *chart;
// BufferStruct<PatternEntry> pattern;

Pattern(Chart *_chart) : chart(_chart) {}
// Pattern(Chart *_chart) : chart(_chart) {}
};
47 changes: 47 additions & 0 deletions Pattern.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,53 @@
#include "Bar.struct.h"
#include "Pattern.enum.h"

// Defines structure for bitwise pattern values.
struct PatternBitwise {
unsigned int v[];
// Operator methods.
unsigned int operator[](const int _index) const { return v[_index]; }
// Adds new value to the end of the array.
bool Add(const unsigned int _value) {
int _new_index = ArrayResize(v, ArraySize(v) + 1) - 1;
v[_new_index] = _value;
return _new_index == ArraySize(v) - 1;
}
/**
* Calculates depth of selected bit.
*
* @param _bi Index of bit to calculate the depth for.
*
* @return
* Returns depth of bit.
* When 0, selected bit was not active across all values.
* When positive, bit is active for X number of values.
* When negative, bit is no longer active since X number of past values.
*/
short GetBitDepth(int _bi) {
// Initialize counter.
short _depth = (short)((v[0] & (1 << _bi)) != 0);
int _size = ArraySize(v);
for (int _ic = 1; _ic < _size; _ic++) {
short _vcurr = (short)((v[_ic] & (1 << _bi)) != 0);
if (_ic == _depth) {
if (_vcurr == 0) {
// When bit stopped being activated, break the loop.
break;
}
_depth = _depth + _vcurr;
} else if (_vcurr > 0) {
// Calculates the negative depth.
// Which is how far back bit was activated.
_depth = (short)-_ic;
break;
}
}
// Returns depth.
return _depth;
}
};

// Defines structure for pattern entry.
struct PatternEntry {
unsigned int pattern[8];
// Struct constructor.
Expand Down
1 change: 0 additions & 1 deletion Serializer.define.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@
#define SERIALIZER_EMPTY_STUB \
template <> \
void SerializeStub(int _n1 = 1, int _n2 = 1, int _n3 = 1, int _n4 = 1, int _n5 = 1) {}

0 comments on commit 7674c22

Please sign in to comment.