Skip to content

Commit

Permalink
Just some WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Nov 19, 2021
1 parent 0b2e66f commit 112a998
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Candle.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Serializer;
#include "SerializerNode.enum.h"
#include "Std.h"

/* Structore for storing OHLC values. */
/* Structure for storing OHLC values. */
template <typename T>
struct CandleOHLC
#ifndef __MQL__
Expand Down
1 change: 1 addition & 0 deletions Indicator.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ enum ENUM_INDICATOR_TYPE {
INDI_STOCHASTIC, // Stochastic Oscillator
INDI_SVE_BB, // SVE Bollinger Bands
INDI_TEMA, // Triple Exponential Moving Average
INDI_TF, // Timeframe
INDI_TICK, // Tick
INDI_TMA_TRUE, // Triangular Moving Average True
INDI_TRIX, // Triple Exponential Moving Averages Oscillator
Expand Down
3 changes: 1 addition & 2 deletions Indicator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ class Indicator : public IndicatorBase {
* @return
* Returns IndicatorDataEntry struct filled with indicator values.
*/
virtual IndicatorDataEntry GetEntry(int _index = -1) {
IndicatorDataEntry GetEntry(int _index = -1) override {
ResetLastError();
int _ishift = _index >= 0 ? _index : iparams.GetShift();
long _bar_time = GetBarTime(_ishift);
Expand Down Expand Up @@ -1293,7 +1293,6 @@ class Indicator : public IndicatorBase {
COMMA _l COMMA _m);
#endif
}

};

#endif
22 changes: 20 additions & 2 deletions Indicator/IndicatorCandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class IndicatorCandle : public IndicatorBase {
/**
* Class constructor.
*/
IndicatorCandle(const TS& _icparams, IndicatorBase* _indi_src = NULL, int _indi_mode = 0) : icparams(_icparams) {
IndicatorCandle(const TS& _icparams, IndicatorBase* _indi_src = NULL, int _indi_mode = 0) {
icparams = _icparams;
if (_indi_src != NULL) {
SetDataSource(_indi_src, _indi_mode);
}
Expand All @@ -83,9 +84,26 @@ class IndicatorCandle : public IndicatorBase {
* @return
* Returns IndicatorDataEntry struct filled with indicator values.
*/
IndicatorDataEntry GetEntry(int _timestamp = 0) {
IndicatorDataEntry GetEntry(int _index = -1) override {
ResetLastError();
int _ishift = _index >= 0 ? _index : icparams.GetShift();
long _bar_time = GetBarTime(_ishift);

// Trying to fetch entry from cache.
IndicatorDataEntry _entry = icdata.GetByKey(_bar_time);

if (_bar_time > 0 && !_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) {
// There is no valid entry in the cache.
_entry.Resize(iparams.GetMaxModes());
_entry.timestamp = _bar_time;
}

CandleOHLC<TV> _entry = icdata.GetByKey(_timestamp);

if (!_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) {
// There is no candle for given timestamp.
}

/*
IndicatorDataEntry _entry = icdata.GetByKey(_timestamp);
if (!_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) {
Expand Down
5 changes: 3 additions & 2 deletions Indicator/IndicatorTf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
/**
* Class to deal with candle indicators.
*/
class IndicatorTf : public IndicatorCandle<IndicatorTfParams, double> {
template <typename TFP>
class IndicatorTf : public IndicatorCandle<TFP, double> {
protected:
/* Protected methods */

Expand Down Expand Up @@ -78,7 +79,7 @@ class IndicatorTf : public IndicatorCandle<IndicatorTfParams, double> {
/**
* Class constructor with parameters.
*/
IndicatorTf(IndicatorTfParams &_params) : IndicatorCandle<IndicatorTfParams, double>(_params) { Init(); }
IndicatorTf(TFP &_params) : IndicatorCandle<TFP, double>(_params) { Init(); }
};

#endif
21 changes: 21 additions & 0 deletions Indicator/tests/IndicatorTf.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,37 @@
/**
* @file
* Test functionality of IndicatorTf class.
*
* Idea is to check if ticks from IndicatorTick will be properly grouped by given timespan/timeframe.
*/

// Includes.
#include "../../Test.mqh"
#include "../IndicatorTf.h"

// Structs.
struct IndicatorTfDummyParams : IndicatorTfParams {
IndicatorTfDummyParams(uint _spc = 60) : IndicatorTfParams(_spc) {}
};

/**
* Price Indicator.
*/
class IndicatorTfDummy : public IndicatorTf<IndicatorTfDummyParams> {
public:
IndicatorTfDummy(uint _spc) : IndicatorTf(_spc) {}
IndicatorTfDummy(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorTf(_tf) {}
IndicatorTfDummy(ENUM_TIMEFRAMES_INDEX _tfi = 0) : IndicatorTf(_tfi) {}
};

/**
* Implements OnInit().
*/
int OnInit() {
// @todo

// 1-second candles.
Ref<IndicatorTfDummy> indi_tf = new IndicatorTfDummy(1);

return (INIT_SUCCEEDED);
}

0 comments on commit 112a998

Please sign in to comment.