Skip to content

Commit

Permalink
Indicator/IndicatorTf: Improves constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Nov 11, 2021
1 parent 11dd812 commit 0b2e66f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
16 changes: 16 additions & 0 deletions Buffer/BufferTick.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ class BufferTick : public BufferStruct<TickAB<TV>> {
Init();
}

/* Grouping methods */

/**
* Group ticks by seconds.
*/
DictStruct<uint, DictStruct<uint, TickAB<TV>>> GroupBySecs(uint _spc) {
// DictStruct<uint, DictStruct<TickAB<TV>>> _result;
// @todo: for each iter
// for (DictStructIterator<uint, DictStruct<TickAB<TV>>> iter(Begin()); iter.IsValid(); ++iter) {
// Load timestamp from key, TickAB from value
// foreach some timestamp mod % _spc - calculate shift
// _result.Push(_shift, TickAB<TV>)
// Convert to OHLC in upper method
return NULL;
}

/* Callback methods */

/**
Expand Down
3 changes: 1 addition & 2 deletions Chart.struct.tf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

// Includes.
#include "Chart.enum.h"
#include "Serializer.mqh"

/* Defines struct for chart timeframe. */
struct ChartTf {
Expand Down Expand Up @@ -346,8 +347,6 @@ struct ChartTf {
SerializerNodeType Serialize(Serializer& s);
};

#include "Serializer.mqh"

/* Method to serialize ChartTf structure. */
SerializerNodeType ChartTf::Serialize(Serializer& s) {
s.PassEnum(THIS_REF, "tf", tf);
Expand Down
23 changes: 19 additions & 4 deletions Indicator/IndicatorTf.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#endif

// Includes.
#include "../Chart.struct.tf.h"
#include "IndicatorCandle.h"
#include "IndicatorTf.struct.h"

Expand All @@ -51,14 +52,28 @@ class IndicatorTf : public IndicatorCandle<IndicatorTfParams, double> {
/* Special methods */

/**
* Class constructor.
* Class constructor with timeframe enum.
*/
IndicatorTf(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { Init(); }
IndicatorTf(uint _spc) {
icparams.SetSecsPerCandle(_spc);
Init();
}

/**
* Class constructor.
* Class constructor with timeframe enum.
*/
IndicatorTf(ENUM_TIMEFRAMES_INDEX _tfi = 0) { Init(); }
IndicatorTf(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) {
icparams.SetSecsPerCandle(ChartTf::TfToSeconds(_tf));
Init();
}

/**
* Class constructor with timeframe index.
*/
IndicatorTf(ENUM_TIMEFRAMES_INDEX _tfi = 0) {
icparams.SetSecsPerCandle(ChartTf::TfToSeconds(ChartTf::IndexToTf(_tfi)));
Init();
}

/**
* Class constructor with parameters.
Expand Down
10 changes: 9 additions & 1 deletion Indicator/IndicatorTf.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@
#pragma once
#endif

// Includes.
#include "../Indicator.struct.h"

/* Structure for IndicatorTf class parameters. */
struct IndicatorTfParams : IndicatorParams {
uint spc; // Seconds per candle.
// Struct constructor.
IndicatorTfParams() {}
IndicatorTfParams(uint _spc = 60) : spc(_spc) {}
// Getters.
uint GetSecsPerCandle() { return spc; }
// Setters.
void SetSecsPerCandle(uint _spc) { spc = _spc; }
// Copy constructor.
IndicatorTfParams(const IndicatorTfParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) {
THIS_REF = _params;
Expand Down

0 comments on commit 0b2e66f

Please sign in to comment.