Skip to content

Commit

Permalink
WIP. Trying to make tests to run on MT4.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Feb 7, 2023
1 parent 17cd38a commit a30a476
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 379 deletions.
2 changes: 1 addition & 1 deletion Chart.struct.tf.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct ChartTf {
static unsigned int TfToSeconds(const ENUM_TIMEFRAMES _tf) {
switch (_tf) {
case PERIOD_CURRENT:
return TfToSeconds(Period());
return PeriodSeconds(_tf);
case PERIOD_M1: // 1 minute.
return 60;
case PERIOD_M2: // 2 minutes (non-standard).
Expand Down
6 changes: 3 additions & 3 deletions Indicator/Indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ class Indicator : public IndicatorData {
* Sets whether indicator's buffers should be drawn on the chart.
*/
void SetDraw(bool _value, color _color = clrAquamarine, int _window = 0) {
draw.SetEnabled(_value);
draw.SetColorLine(_color);
draw.SetWindow(_window);
// draw.SetEnabled(_value);
// draw.SetColorLine(_color);
// draw.SetWindow(_window);
}

/* Converters */
Expand Down
8 changes: 7 additions & 1 deletion Indicator/IndicatorData.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct ExternInstantiateIndicatorBufferValueStorageDouble {
#include "../Flags.h"
#include "../Storage/IValueStorage.h"
#include "../Storage/ItemsHistory.h"
#include "../Storage/ValueStorage.indicator.h"
#include "../SymbolInfo.struct.h"
#include "Indicator.enum.h"
#include "IndicatorBase.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ class IndicatorData : public IndicatorBase {
ARRAY(WeakRef<IndicatorData>, listeners); // List of indicators that listens for events from this one.
BufferStruct<IndicatorDataEntry> idata;
DictStruct<int, Ref<IndicatorData>> indicators; // Indicators list keyed by id.
DrawIndicator* draw;
// DrawIndicator* draw;
IndicatorCalculateCache<double> cache;
IndicatorDataParams idparams; // Indicator data params.
IndicatorState istate;
Expand Down Expand Up @@ -1939,4 +1940,9 @@ int CopyBuffer(IndicatorData* _indi, int _mode, int _start, int _count, ValueSto
return _num_copied;
}

IValueStorage* ExternInstantiateIndicatorBufferValueStorageDouble::InstantiateIndicatorBufferValueStorageDouble(
IndicatorData* _indi, int _mode) {
return new IndicatorBufferValueStorage<double>(_indi, _mode);
}

#endif // INDICATOR_DATA_H
19 changes: 11 additions & 8 deletions Indicator/tests/classes/Indicators.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,27 @@
* Helper class to store all indicators and call OnTick() on them.
*/
class Indicators {
Ref<IndicatorData> _indis[];
DictStruct<int, Ref<IndicatorData>> _indis;

public:
void Add(IndicatorBase* _indi) {
Ref<IndicatorData> _ref = _indi;
ArrayPushObject(_indis, _ref);
_indis.Push(_ref);
}

void Remove(IndicatorData* _indi) {
Ref<IndicatorData> _ref = _indi;
Util::ArrayRemoveFirst(_indis, _ref);
}
void Add(Ref<IndicatorData>& _indi) { Add(_indi.Ptr()); }

IndicatorData* Get(int index) { return _indis[index].Ptr(); }

IndicatorData* operator[](int index) { return Get(index); }

int Size() { return _indis.Size(); }

/**
* Executes OnTick() on every added indicator.
*/
void Tick(int _global_tick_index) {
for (int i = 0; i < ArraySize(_indis); ++i) {
for (unsigned int i = 0; i < _indis.Size(); ++i) {
_indis[i].Ptr().OnTick(_global_tick_index);
}
}
Expand All @@ -64,7 +67,7 @@ class Indicators {
*/
string ToString(int _shift = 0) {
string _result;
for (int i = 0; i < ArraySize(_indis); ++i) {
for (unsigned int i = 0; i < _indis.Size(); ++i) {
IndicatorDataEntry _entry = _indis[i].Ptr().GetEntry(_shift);
_result += _indis[i].Ptr().GetFullName() + " = " + _entry.ToString<double>() + "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Demo.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Indi_Demo : public Indicator<IndiDemoParams> {
virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _abs_shift = 0) {
double _value = Indi_Demo::iDemo(THIS_PTR, ToRelShift(_abs_shift));
if (idparams.IsDrawing()) {
draw.DrawLineTo(GetName(), GetCandle() PTR_DEREF GetBarTime(ToRelShift(_abs_shift)), _value);
// draw.DrawLineTo(GetName(), GetCandle() PTR_DEREF GetBarTime(ToRelShift(_abs_shift)), _value);
}
return _value;
}
Expand Down
6 changes: 4 additions & 2 deletions Indicators/Indi_Momentum.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ class Indi_Momentum : public Indicator<IndiMomentumParams> {
_value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(),
iparams.shift + ToRelShift(_abs_shift));
if (idparams.IsDrawing()) {
draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + ToRelShift(_abs_shift)), _value, 1);
// draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + ToRelShift(_abs_shift)), _value,
// 1);
}
break;
case IDATA_ICUSTOM:
Expand All @@ -165,7 +166,8 @@ class Indi_Momentum : public Indicator<IndiMomentumParams> {
_value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(),
iparams.shift + ToRelShift(_abs_shift));
if (idparams.IsDrawing()) {
draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + ToRelShift(_abs_shift)), _value, 1);
// draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + ToRelShift(_abs_shift)), _value,
// 1);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_PriceFeeder.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Indi_PriceFeeder : public Indicator<IndiPriceFeederParams> {
int _max_modes = Get<int>(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES));
IndicatorDataEntry _entry = GetEntry(0);
for (int i = 0; i < _max_modes; ++i) {
draw.DrawLineTo(GetName() + "_" + IntegerToString(i), GetBarTime(0), _entry.values[i].GetDbl());
// draw.DrawLineTo(GetName() + "_" + IntegerToString(i), GetBarTime(0), _entry.values[i].GetDbl());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Refs.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ struct Ref {
}
};

template <typename R, typename X>
Ref<R> MakeRef(X* _ptr) {
return Ref<R>(_ptr);
template <typename T>
Ref<T> MakeRef(T* _ptr) {
return Ref<T>(_ptr);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions Storage/ValueStorage.indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,3 @@ class IndicatorBufferValueStorage : public HistoryValueStorage<C> {
*/
C Fetch(int _rel_shift) override { return indi_candle REF_DEREF GetValue<C>(mode, RealShift(_rel_shift)); }
};

IValueStorage* ExternInstantiateIndicatorBufferValueStorageDouble::InstantiateIndicatorBufferValueStorageDouble(
IndicatorData* _indi, int _mode) {
return new IndicatorBufferValueStorage<double>(_indi, _mode);
}
Loading

0 comments on commit a30a476

Please sign in to comment.