Skip to content

Commit

Permalink
IndicatorsTest now compiles in MT5. Need to check other tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Jan 26, 2023
1 parent f4c5d18 commit c09b514
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 155 deletions.
5 changes: 4 additions & 1 deletion Candle.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ struct CandleOCTOHLC : CandleOHLC<T> {
// Number of ticks which formed the candle. Also known as volume.
int volume;

// Struct constructors.
// Struct constructor.
CandleOCTOHLC(T _open = 0, T _high = 0, T _low = 0, T _close = 0, int _start_time = -1, int _length = 0,
long _open_timestamp_ms = -1, long _close_timestamp_ms = -1, int _volume = 0)
: CandleOHLC(_open, _high, _low, _close),
Expand All @@ -251,6 +251,9 @@ struct CandleOCTOHLC : CandleOHLC<T> {
}
}

// Struct constructor.
CandleOCTOHLC(const CandleOCTOHLC &r) { THIS_REF = r; }

/**
* Initializes candle with a given start time, lenght in seconds, first tick's timestamp and its price.
*/
Expand Down
17 changes: 8 additions & 9 deletions DateTime.static.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#endif

// Includes.
#include "DateTime.static.h"
#include "PlatformTime.h"

/*
Expand All @@ -43,7 +42,7 @@ struct DateTimeStatic {
*/
static int Day(datetime dt = 0) {
if (dt == (datetime)0) {
dt = PlatformTime::CurrentTimestamp();
dt = (datetime)PlatformTime::CurrentTimestamp();
}
#ifdef __MQL4__
return ::TimeDay(dt);
Expand All @@ -59,7 +58,7 @@ struct DateTimeStatic {
*/
static int DayOfWeek(datetime dt = 0) {
if (dt == (datetime)0) {
dt = PlatformTime::CurrentTimestamp();
dt = (datetime)PlatformTime::CurrentTimestamp();
}
#ifdef __MQL4__
return ::DayOfWeek();
Expand All @@ -75,7 +74,7 @@ struct DateTimeStatic {
*/
static int DayOfYear(datetime dt = 0) {
if (dt == (datetime)0) {
dt = PlatformTime::CurrentTimestamp();
dt = (datetime)PlatformTime::CurrentTimestamp();
}
#ifdef __MQL4__
return ::DayOfYear();
Expand All @@ -91,7 +90,7 @@ struct DateTimeStatic {
*/
static int Hour(datetime dt = 0) {
if (dt == (datetime)0) {
dt = PlatformTime::CurrentTimestamp();
dt = (datetime)PlatformTime::CurrentTimestamp();
}
#ifdef __MQL4__
return ::Hour();
Expand All @@ -116,7 +115,7 @@ struct DateTimeStatic {
*/
static int Minute(datetime dt = 0) {
if (dt == (datetime)0) {
dt = PlatformTime::CurrentTimestamp();
dt = (datetime)PlatformTime::CurrentTimestamp();
}
#ifdef __MQL4__
return ::Minute();
Expand All @@ -132,7 +131,7 @@ struct DateTimeStatic {
*/
static int Month(datetime dt = 0) {
if (dt == (datetime)0) {
dt = PlatformTime::CurrentTimestamp();
dt = (datetime)PlatformTime::CurrentTimestamp();
}
#ifdef __MQL4__
return ::Month();
Expand All @@ -148,7 +147,7 @@ struct DateTimeStatic {
*/
static int Seconds(datetime dt = 0) {
if (dt == (datetime)0) {
dt = PlatformTime::CurrentTimestamp();
dt = (datetime)PlatformTime::CurrentTimestamp();
}
#ifdef __MQL4__
return ::Seconds();
Expand Down Expand Up @@ -194,7 +193,7 @@ struct DateTimeStatic {
*/
static int Year(datetime dt = 0) {
if (dt == (datetime)0) {
dt = PlatformTime::CurrentTimestamp();
dt = (datetime)PlatformTime::CurrentTimestamp();
}
#ifdef __MQL4__
return ::Year();
Expand Down
2 changes: 1 addition & 1 deletion DictSlot.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DictSlot {

DictSlot(unsigned char flags = 0) : _flags(flags) {}

DictSlot(const DictSlot& r) : _flags(r._flags), key(r.key), value(r.value) {}
DictSlot(const DictSlot& r) : _flags(r._flags), key(r.key) { value = r.value; }

bool IsValid() { return !bool(_flags & DICT_SLOT_INVALID); }

Expand Down
4 changes: 2 additions & 2 deletions DictStruct.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DictStruct : public DictBase<K, V> {
/**
* Inserts value using hashless key.
*/
bool Push(const V& value) {
bool Push(V& value) {
if (!InsertInto(THIS_ATTR _DictSlots_ref, value)) return false;
return true;
}
Expand Down Expand Up @@ -361,7 +361,7 @@ class DictStruct : public DictBase<K, V> {
/**
* Inserts hashless value into given array of DictSlots.
*/
bool InsertInto(DictSlotsRef<K, V>& dictSlotsRef, const V& value) {
bool InsertInto(DictSlotsRef<K, V>& dictSlotsRef, V& value) {
if (THIS_ATTR _mode == DictModeUnknown)
THIS_ATTR _mode = DictModeList;
else if (THIS_ATTR _mode != DictModeList) {
Expand Down
12 changes: 6 additions & 6 deletions Indicator/Indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
// Forward class declaration.
struct IndicatorParams;

#include "Indicator.define.h"
#include "Indicator.enum.h"
#include "Indicator.struct.h"
#include "Indicator.struct.serialize.h"
#include "IndicatorData.h"

// Includes.
#include "../Array.mqh"
#include "../BufferStruct.mqh"
Expand All @@ -48,6 +42,12 @@ struct IndicatorParams;
#include "../Storage/ValueStorage.h"
#include "../Storage/ValueStorage.indicator.h"
#include "../Storage/ValueStorage.native.h"
#include "../Task/TaskCondition.enum.h"
#include "Indicator.define.h"
#include "Indicator.enum.h"
#include "Indicator.struct.h"
#include "Indicator.struct.serialize.h"
#include "IndicatorData.h"

#ifndef __MQL4__
// Defines global functions (for MQL4 backward compatibility).
Expand Down
13 changes: 9 additions & 4 deletions Indicator/IndicatorData.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
// Forward class declaration.
class IndicatorData;
class DrawIndicator;
class IValueStorage;

struct ExternInstantiateIndicatorBufferValueStorageDouble {
static IValueStorage* InstantiateIndicatorBufferValueStorageDouble(IndicatorData*, int);
};

// Includes.
#include "../Bar.struct.h"
Expand All @@ -48,8 +53,6 @@ class DrawIndicator;
#include "IndicatorData.struct.serialize.h"
#include "IndicatorData.struct.signal.h"

extern IValueStorage* InstantiateIndicatorBufferValueStorageDouble(IndicatorData* _indi, int _mode);

/**
* Implements class to store indicator data.
*/
Expand Down Expand Up @@ -745,7 +748,7 @@ class IndicatorData : public IndicatorBase {
*/
void AddListener(IndicatorData* _indi) {
WeakRef<IndicatorData> _ref = _indi;
ArrayPush(listeners, _ref);
ArrayPushObject(listeners, _ref);
}

/**
Expand Down Expand Up @@ -1746,7 +1749,9 @@ class IndicatorData : public IndicatorBase {
}

if (!value_storages[_mode].IsSet()) {
value_storages[_mode] = InstantiateIndicatorBufferValueStorageDouble(THIS_PTR, _mode);
value_storages[_mode] =
ExternInstantiateIndicatorBufferValueStorageDouble::InstantiateIndicatorBufferValueStorageDouble(THIS_PTR,
_mode);
}
return value_storages[_mode].Ptr();
}
Expand Down
2 changes: 2 additions & 0 deletions Indicator/IndicatorData.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ struct IndicatorDataParams {
indi_color = _clr;
draw_window = _window;
}
bool IsDrawing() { return is_draw; }

void SetIndicatorColor(color _clr) { indi_color = _clr; }
};

Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Demo.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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.is_draw) {
if (idparams.IsDrawing()) {
draw.DrawLineTo(GetName(), GetCandle() PTR_DEREF GetBarTime(ToRelShift(_abs_shift)), _value);
}
return _value;
Expand Down
4 changes: 2 additions & 2 deletions Indicators/Indi_Momentum.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Indi_Momentum : public Indicator<IndiMomentumParams> {
// @fixit Somehow shift isn't used neither in MT4 nor MT5.
_value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(),
iparams.shift + ToRelShift(_abs_shift));
if (idparams.is_draw) {
if (idparams.IsDrawing()) {
draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + ToRelShift(_abs_shift)), _value, 1);
}
break;
Expand All @@ -164,7 +164,7 @@ class Indi_Momentum : public Indicator<IndiMomentumParams> {
// @fixit Somehow shift isn't used neither in MT4 nor MT5.
_value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(),
iparams.shift + ToRelShift(_abs_shift));
if (idparams.is_draw) {
if (idparams.IsDrawing()) {
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 @@ -103,7 +103,7 @@ class Indi_PriceFeeder : public Indicator<IndiPriceFeederParams> {
void OnTick(int _global_tick_index) override {
Indicator<IndiPriceFeederParams>::OnTick(_global_tick_index);

if (idparams.is_draw) {
if (idparams.IsDrawing()) {
int _max_modes = Get<int>(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES));
IndicatorDataEntry _entry = GetEntry(0);
for (int i = 0; i < _max_modes; ++i) {
Expand Down
3 changes: 2 additions & 1 deletion Indicators/Indi_StdDev.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ class Indi_StdDev : public Indicator<IndiStdDevParams> {
Indi_PriceFeeder *_indi_price_feeder;
if (!ObjectsCache<Indi_PriceFeeder>::TryGet(_key, _indi_price_feeder)) {
IndiPriceFeederParams _params();
_indi_price_feeder = ObjectsCache<Indi_PriceFeeder>::Set(_key, new Indi_PriceFeeder(_params));
IndicatorData *_indi_pf = new Indi_PriceFeeder(_params);
_indi_price_feeder = ObjectsCache<Indi_PriceFeeder>::Set(_key, _indi_pf);
}

// Filling reused price feeder.
Expand Down
3 changes: 2 additions & 1 deletion Log.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ class Log : public Object {
void Link(Log *_log) {
PTR_ATTRIB(_log, SetLevel(log_level)); // Sets the same level as this instance.
// @todo: Make sure we're not linking the same instance twice.
logs.Push(_log);
Ref<Log> _ref_log = _log;
logs.Push(_ref_log);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ class Platform {
/**
* Returns id of the current chart.
*/
static int ChartID() { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); }
static int ChartID() {
Print("Not yet implemented: ", __FUNCTION__, " returns 0.");
return 0;
}

/**
* Binds Candle and/or Tick indicator as a source of prices or data for given indicator.
Expand Down
19 changes: 9 additions & 10 deletions PlatformTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
// Includes.
#include "DateTime.enum.h"
#include "DateTime.mqh"
#include "DateTime.struct.h"

/**
* @file
Expand All @@ -35,7 +34,9 @@
// Includes.
#include <chrono>
#include <ctime>

#include "DateTime.struct.h"
#endif

class PlatformTime {
static MqlDateTime current_time;
Expand All @@ -49,19 +50,19 @@ class PlatformTime {

void static Tick() {
#ifdef __MQL__
static _last_time_ms = 0;
static long _last_timestamp_ms = 0;

current_time_s = ::TimeCurrent(&current_time);
current_timestamp_s = ::TimeCurrent(current_time);

current_time_ms = (long)GetTickCount();
current_timestamp_ms = (long)GetTickCount();

if (_last_time_ms != 0 && current_time_ms < _last_time_ms) {
if (_last_timestamp_ms != 0 && current_timestamp_ms < _last_timestamp_ms) {
// Overflow occured (49.7 days passed).
// More info: https://docs.mql4.com/common/gettickcount
current_time_ms += _last_time_ms;
current_timestamp_ms += _last_timestamp_ms;
}

_last_time_ms = current_time_ms;
_last_timestamp_ms = current_timestamp_ms;
#else
using namespace std::chrono;
current_timestamp_s = (long)duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
Expand All @@ -82,8 +83,6 @@ class PlatformTime {
}
};

MqlDateTime PlatformTime::current_time{0, 0, 0, 0, 0, 0, 0, 0};
MqlDateTime PlatformTime::current_time = {0, 0, 0, 0, 0, 0, 0, 0};
long PlatformTime::current_timestamp_s = 0;
long PlatformTime::current_timestamp_ms = 0;

#endif
13 changes: 3 additions & 10 deletions Refs.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
#pragma once
#endif

// Includes.
#include <type_traits>

#include "Refs.rc.h"
#include "Std.h"

Expand Down Expand Up @@ -93,10 +90,6 @@ struct SimpleRef {
}
};

template <typename T>
using base_type =
typename std::remove_cv<typename std::remove_reference<typename std::remove_pointer<T>::type>::type>::type;

/**
* Class used to hold strong reference to reference-counted object.
*/
Expand Down Expand Up @@ -284,9 +277,9 @@ struct Ref {
}
};

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

/**
Expand Down
4 changes: 3 additions & 1 deletion Storage/ValueStorage.indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
class IndicatorData;

// Includes.
#include "../Indicator/IndicatorData.h"
#include "ValueStorage.history.h"

/**
Expand All @@ -57,6 +58,7 @@ class IndicatorBufferValueStorage : public HistoryValueStorage<C> {
C Fetch(int _rel_shift) override { return indi_candle REF_DEREF GetValue<C>(mode, RealShift(_rel_shift)); }
};

IValueStorage* InstantiateIndicatorBufferValueStorageDouble(IndicatorData* _indi, int _mode) {
IValueStorage* ExternInstantiateIndicatorBufferValueStorageDouble::InstantiateIndicatorBufferValueStorageDouble(
IndicatorData* _indi, int _mode) {
return new IndicatorBufferValueStorage<double>(_indi, _mode);
}
4 changes: 2 additions & 2 deletions Task/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Task : public Taskable<TaskEntry> {
* Class constructor.
*/
Task() {}
Task(const TaskEntry &_entry) { Add(_entry); }
Task(TaskEntry &_entry) { Add(_entry); }

/**
* Class copy constructor.
Expand All @@ -67,7 +67,7 @@ class Task : public Taskable<TaskEntry> {
/**
* Adds new task.
*/
void Add(const TaskEntry &_entry) { tasks.Push(_entry); }
void Add(TaskEntry &_entry) { tasks.Push(_entry); }

/* Virtual methods */

Expand Down
Loading

0 comments on commit c09b514

Please sign in to comment.