diff --git a/Candle.struct.h b/Candle.struct.h index 75acc6b09..6b2f502e3 100644 --- a/Candle.struct.h +++ b/Candle.struct.h @@ -236,7 +236,7 @@ struct CandleOCTOHLC : CandleOHLC { // 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), @@ -251,6 +251,9 @@ struct CandleOCTOHLC : CandleOHLC { } } + // 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. */ diff --git a/DateTime.static.h b/DateTime.static.h index 1b5950128..c2ca188d8 100644 --- a/DateTime.static.h +++ b/DateTime.static.h @@ -31,7 +31,6 @@ #endif // Includes. -#include "DateTime.static.h" #include "PlatformTime.h" /* @@ -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); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/DictSlot.mqh b/DictSlot.mqh index eea48969d..07b42fbf2 100644 --- a/DictSlot.mqh +++ b/DictSlot.mqh @@ -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); } diff --git a/DictStruct.mqh b/DictStruct.mqh index 6ff0063fb..229a9567c 100644 --- a/DictStruct.mqh +++ b/DictStruct.mqh @@ -113,7 +113,7 @@ class DictStruct : public DictBase { /** * 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; } @@ -361,7 +361,7 @@ class DictStruct : public DictBase { /** * Inserts hashless value into given array of DictSlots. */ - bool InsertInto(DictSlotsRef& dictSlotsRef, const V& value) { + bool InsertInto(DictSlotsRef& dictSlotsRef, V& value) { if (THIS_ATTR _mode == DictModeUnknown) THIS_ATTR _mode = DictModeList; else if (THIS_ATTR _mode != DictModeList) { diff --git a/Indicator/Indicator.h b/Indicator/Indicator.h index 9bab3b18f..8d625a583 100644 --- a/Indicator/Indicator.h +++ b/Indicator/Indicator.h @@ -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" @@ -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). diff --git a/Indicator/IndicatorData.h b/Indicator/IndicatorData.h index 2d706bda3..0707e4fe8 100644 --- a/Indicator/IndicatorData.h +++ b/Indicator/IndicatorData.h @@ -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" @@ -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. */ @@ -745,7 +748,7 @@ class IndicatorData : public IndicatorBase { */ void AddListener(IndicatorData* _indi) { WeakRef _ref = _indi; - ArrayPush(listeners, _ref); + ArrayPushObject(listeners, _ref); } /** @@ -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(); } diff --git a/Indicator/IndicatorData.struct.h b/Indicator/IndicatorData.struct.h index dd4e29493..549c44219 100644 --- a/Indicator/IndicatorData.struct.h +++ b/Indicator/IndicatorData.struct.h @@ -530,6 +530,8 @@ struct IndicatorDataParams { indi_color = _clr; draw_window = _window; } + bool IsDrawing() { return is_draw; } + void SetIndicatorColor(color _clr) { indi_color = _clr; } }; diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index d4bf22c37..07afa9a28 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -81,7 +81,7 @@ class Indi_Demo : public Indicator { */ 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; diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 122c15e37..679f96c45 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -150,7 +150,7 @@ class Indi_Momentum : public Indicator { // @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; @@ -164,7 +164,7 @@ class Indi_Momentum : public Indicator { // @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; diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index cbe8b7213..4b93f08ea 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -103,7 +103,7 @@ class Indi_PriceFeeder : public Indicator { void OnTick(int _global_tick_index) override { Indicator::OnTick(_global_tick_index); - if (idparams.is_draw) { + if (idparams.IsDrawing()) { int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); IndicatorDataEntry _entry = GetEntry(0); for (int i = 0; i < _max_modes; ++i) { diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index 3154b4e51..7de50a928 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -199,7 +199,8 @@ class Indi_StdDev : public Indicator { Indi_PriceFeeder *_indi_price_feeder; if (!ObjectsCache::TryGet(_key, _indi_price_feeder)) { IndiPriceFeederParams _params(); - _indi_price_feeder = ObjectsCache::Set(_key, new Indi_PriceFeeder(_params)); + IndicatorData *_indi_pf = new Indi_PriceFeeder(_params); + _indi_price_feeder = ObjectsCache::Set(_key, _indi_pf); } // Filling reused price feeder. diff --git a/Log.mqh b/Log.mqh index 0a4bff34a..b83ca09e0 100644 --- a/Log.mqh +++ b/Log.mqh @@ -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 _ref_log = _log; + logs.Push(_ref_log); } /** diff --git a/Platform.h b/Platform.h index 7a520a5b5..90f8440cf 100644 --- a/Platform.h +++ b/Platform.h @@ -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. diff --git a/PlatformTime.h b/PlatformTime.h index 8e62646f5..89cb39527 100644 --- a/PlatformTime.h +++ b/PlatformTime.h @@ -23,7 +23,6 @@ // Includes. #include "DateTime.enum.h" #include "DateTime.mqh" -#include "DateTime.struct.h" /** * @file @@ -35,7 +34,9 @@ // Includes. #include #include + #include "DateTime.struct.h" +#endif class PlatformTime { static MqlDateTime current_time; @@ -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(¤t_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(system_clock::now().time_since_epoch()).count(); @@ -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 diff --git a/Refs.struct.h b/Refs.struct.h index 9827f7b1a..210f58f11 100644 --- a/Refs.struct.h +++ b/Refs.struct.h @@ -30,9 +30,6 @@ #pragma once #endif -// Includes. -#include - #include "Refs.rc.h" #include "Std.h" @@ -93,10 +90,6 @@ struct SimpleRef { } }; -template -using base_type = - typename std::remove_cv::type>::type>::type; - /** * Class used to hold strong reference to reference-counted object. */ @@ -284,9 +277,9 @@ struct Ref { } }; -template -Ref make_ref() { - return Ref(); +template +Ref MakeRef(X* _ptr) { + return Ref(_ptr); } /** diff --git a/Storage/ValueStorage.indicator.h b/Storage/ValueStorage.indicator.h index 4406fe397..254767c7c 100644 --- a/Storage/ValueStorage.indicator.h +++ b/Storage/ValueStorage.indicator.h @@ -34,6 +34,7 @@ class IndicatorData; // Includes. +#include "../Indicator/IndicatorData.h" #include "ValueStorage.history.h" /** @@ -57,6 +58,7 @@ class IndicatorBufferValueStorage : public HistoryValueStorage { C Fetch(int _rel_shift) override { return indi_candle REF_DEREF GetValue(mode, RealShift(_rel_shift)); } }; -IValueStorage* InstantiateIndicatorBufferValueStorageDouble(IndicatorData* _indi, int _mode) { +IValueStorage* ExternInstantiateIndicatorBufferValueStorageDouble::InstantiateIndicatorBufferValueStorageDouble( + IndicatorData* _indi, int _mode) { return new IndicatorBufferValueStorage(_indi, _mode); } diff --git a/Task/Task.h b/Task/Task.h index c2ca184cc..266a60284 100644 --- a/Task/Task.h +++ b/Task/Task.h @@ -50,7 +50,7 @@ class Task : public Taskable { * Class constructor. */ Task() {} - Task(const TaskEntry &_entry) { Add(_entry); } + Task(TaskEntry &_entry) { Add(_entry); } /** * Class copy constructor. @@ -67,7 +67,7 @@ class Task : public Taskable { /** * Adds new task. */ - void Add(const TaskEntry &_entry) { tasks.Push(_entry); } + void Add(TaskEntry &_entry) { tasks.Push(_entry); } /* Virtual methods */ diff --git a/Terminal.define.h b/Terminal.define.h index a316eea43..fd66662aa 100644 --- a/Terminal.define.h +++ b/Terminal.define.h @@ -37,6 +37,8 @@ #define CP_UTF7 65000 // UTF-7 code page. #define CP_UTF8 65001 // UTF-8 code page. +#ifndef __MQL__ + // Colors. #define clrAliceBlue 0x00F0F8FF #define clrAntiqueWhite 0x00FAEBD7 @@ -304,6 +306,8 @@ #define Yellow clrYellow #define YellowGreen clrYellowGreen +#endif + #ifndef __MQL__ #define clrNONE -1 #define CLR_NONE -1 diff --git a/Terminal.mqh b/Terminal.mqh index 6c5116679..3fe1a77b0 100644 --- a/Terminal.mqh +++ b/Terminal.mqh @@ -934,36 +934,34 @@ class Terminal : public Object { string ToString() override { string _sep = "; "; return StringFormat("Allow DLL: %s", IsDllsAllowed() ? "Yes" : "No") + _sep + - StringFormat("Allow Libraries: %s", IsLibrariesAllowed() ? "Yes" : "No") + _sep + - StringFormat("CPUs: %d", GetCpuCores()) + _sep + - // StringFormat("Community account: %s", (string)HasCommunityAccount()) + _sep + - // StringFormat("Community balance: %.2f", GetCommunityBalance()) + _sep + - // StringFormat("Community connection: %s", (string)IsCommunityConnected()) + _sep + - StringFormat("Disk space: %d", GetDiskSpace()) + _sep + - StringFormat("Enabled FTP: %s", IsFtpEnabled() ? "Yes" : "No") + _sep + - StringFormat("Enabled e-mail: %s", IsEmailEnabled() ? "Yes" : "No") + _sep + - // StringFormat("Enabled notifications: %s", (string)IsNotificationsEnabled()) + _sep + - StringFormat("IsOptimization: %s", IsOptimization() ? "Yes" : "No") + _sep + - StringFormat("IsRealtime: %s", IsRealtime() ? "Yes" : "No") + _sep + - StringFormat("IsTesting: %s", IsTesting() ? "Yes" : "No") + _sep + - StringFormat("IsVisual: %s", IsVisualMode() ? "Yes" : "No") + _sep + - // StringFormat("MQ ID: %s", (string)HasMetaQuotesId()) + _sep + - StringFormat("Memory (free): %d", GetFreeMemory()) + _sep + - StringFormat("Memory (physical): %d", GetPhysicalMemory()) + _sep + - StringFormat("Memory (total): %d", GetTotalMemory()) + _sep + - StringFormat("Memory (used): %d", GetUsedMemory()) + _sep + "Path (Common): " + GetCommonPath() + _sep + - "Path (Data): " + GetDataPath() + _sep + "Path (Expert): " + GetExpertPath() + _sep + - "Path (Terminal): ", - GetTerminalPath() + _sep + "Program name: ", - WindowExpertName() + _sep + StringFormat("Screen DPI: %d", GetScreenDpi()) + _sep + - StringFormat("Terminal build: %d", GetBuild()) + _sep + - "Terminal code page: " + IntegerToString(GetCodePage()) + _sep + "Terminal company: " + GetCompany() + - _sep + "Terminal connected: " + (IsConnected() ? "Yes" : "No") + _sep + - "Terminal language: " + GetLanguage() + _sep + "Terminal name: " + GetName() + _sep + - StringFormat("Termnal max bars: %d", GetMaxBars()) + _sep + - "Trade allowed: " + (IsTradeAllowed() ? "Yes" : "No") + _sep + - "Trade context busy: " + (IsTradeContextBusy() ? "Yes" : "No") + _sep + "Trade perm: %s" + - (CheckPermissionToTrade() ? "Yes" : "No") + _sep + StringFormat("Trade ping (last): %d", GetPingLast()); + StringFormat("Allow Libraries: %s", IsLibrariesAllowed() ? "Yes" : "No") + _sep + + StringFormat("CPUs: %d", GetCpuCores()) + _sep + + // StringFormat("Community account: %s", (string)HasCommunityAccount()) + _sep + + // StringFormat("Community balance: %.2f", GetCommunityBalance()) + _sep + + // StringFormat("Community connection: %s", (string)IsCommunityConnected()) + _sep + + StringFormat("Disk space: %d", GetDiskSpace()) + _sep + + StringFormat("Enabled FTP: %s", IsFtpEnabled() ? "Yes" : "No") + _sep + + StringFormat("Enabled e-mail: %s", IsEmailEnabled() ? "Yes" : "No") + _sep + + // StringFormat("Enabled notifications: %s", (string)IsNotificationsEnabled()) + _sep + + StringFormat("IsOptimization: %s", IsOptimization() ? "Yes" : "No") + _sep + + StringFormat("IsRealtime: %s", IsRealtime() ? "Yes" : "No") + _sep + + StringFormat("IsTesting: %s", IsTesting() ? "Yes" : "No") + _sep + + StringFormat("IsVisual: %s", IsVisualMode() ? "Yes" : "No") + _sep + + // StringFormat("MQ ID: %s", (string)HasMetaQuotesId()) + _sep + + StringFormat("Memory (free): %d", GetFreeMemory()) + _sep + + StringFormat("Memory (physical): %d", GetPhysicalMemory()) + _sep + + StringFormat("Memory (total): %d", GetTotalMemory()) + _sep + + StringFormat("Memory (used): %d", GetUsedMemory()) + _sep + "Path (Common): " + GetCommonPath() + _sep + + "Path (Data): " + GetDataPath() + _sep + "Path (Expert): " + GetExpertPath() + _sep + + "Path (Terminal): " + GetTerminalPath() + _sep + "Program name: " + WindowExpertName() + _sep + + StringFormat("Screen DPI: %d", GetScreenDpi()) + _sep + StringFormat("Terminal build: %d", GetBuild()) + + _sep + "Terminal code page: " + IntegerToString(GetCodePage()) + _sep + "Terminal company: " + GetCompany() + + _sep + "Terminal connected: " + (IsConnected() ? "Yes" : "No") + _sep + + "Terminal language: " + GetLanguage() + _sep + "Terminal name: " + GetName() + _sep + + StringFormat("Termnal max bars: %d", GetMaxBars()) + _sep + + "Trade allowed: " + (IsTradeAllowed() ? "Yes" : "No") + _sep + + "Trade context busy: " + (IsTradeContextBusy() ? "Yes" : "No") + _sep + "Trade perm: %s" + + (CheckPermissionToTrade() ? "Yes" : "No") + _sep + StringFormat("Trade ping (last): %d", GetPingLast()); } }; diff --git a/Tick/Tick.struct.h b/Tick/Tick.struct.h index 9b0622bf2..71f08dcf8 100644 --- a/Tick/Tick.struct.h +++ b/Tick/Tick.struct.h @@ -71,6 +71,7 @@ struct TickTAB : TickAB { // Struct constructors. TickTAB(long _time_ms = 0, T _ask = 0, T _bid = 0) : TickAB(_ask, _bid), time_ms(_time_ms) {} TickTAB(MqlTick &_tick) : TickAB(_tick), time_ms(_tick.time_msc) {} + TickTAB(const TickTAB &r) { THIS_REF = r; } /** * Method used by ItemsHistory. diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index 1b96d9b5c..b1fc5c575 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -164,29 +164,29 @@ bool InitIndicators() { /* Standard indicators */ // AC. - indis.Push(new Indi_AC()); + indis.Push(Ref(new Indi_AC())); // AD. - indis.Push(new Indi_AD()); + indis.Push(Ref(new Indi_AD())); // ADX. IndiADXParams adx_params(14); - indis.Push(new Indi_ADX(adx_params)); + indis.Push(Ref(new Indi_ADX(adx_params))); // Alligator. IndiAlligatorParams alli_params(13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN); - indis.Push(new Indi_Alligator(alli_params)); + indis.Push(Ref(new Indi_Alligator(alli_params))); // Awesome Oscillator (AO). - indis.Push(new Indi_AO()); + indis.Push(Ref(new Indi_AO())); // Accumulation Swing Index (ASI). IndiASIParams _asi_params; - indis.Push(new Indi_ASI(_asi_params)); + indis.Push(Ref(new Indi_ASI(_asi_params))); // Average True Range (ATR). IndiATRParams atr_params(14); - indis.Push(new Indi_ATR(atr_params)); + indis.Push(Ref(new Indi_ATR(atr_params))); // Bollinger Bands - Built-in. IndiBandsParams bands_params(20, 2, 0, PRICE_OPEN); @@ -201,50 +201,50 @@ bool InitIndicators() { // Bears Power. IndiBearsPowerParams bears_params(13, PRICE_CLOSE); - indis.Push(new Indi_BearsPower(bears_params)); + indis.Push(Ref(new Indi_BearsPower(bears_params))); // Bulls Power. IndiBullsPowerParams bulls_params(13, PRICE_CLOSE); - indis.Push(new Indi_BullsPower(bulls_params)); + indis.Push(Ref(new Indi_BullsPower(bulls_params))); // Market Facilitation Index (BWMFI). IndiBWIndiMFIParams _bwmfi_params(1); - indis.Push(new Indi_BWMFI(_bwmfi_params)); + indis.Push(Ref(new Indi_BWMFI(_bwmfi_params))); // Commodity Channel Index (CCI). IndiCCIParams cci_params(14, PRICE_OPEN); - indis.Push(new Indi_CCI(cci_params)); + indis.Push(Ref(new Indi_CCI(cci_params))); // DeMarker. IndiDeMarkerParams dm_params(14); - indis.Push(new Indi_DeMarker(dm_params)); + indis.Push(Ref(new Indi_DeMarker(dm_params))); // Envelopes. IndiEnvelopesParams env_params(13, 0, MODE_SMA, PRICE_OPEN, 2); - indis.Push(new Indi_Envelopes(env_params)); + indis.Push(Ref(new Indi_Envelopes(env_params))); // Force Index. IndiForceParams force_params(13, MODE_SMA, PRICE_CLOSE); - indis.Push(new Indi_Force(force_params)); + indis.Push(Ref(new Indi_Force(force_params))); // Fractals. - indis.Push(new Indi_Fractals()); + indis.Push(Ref(new Indi_Fractals())); // Fractal Adaptive Moving Average (FRAMA). IndiFrAIndiMAParams frama_params(); - indis.Push(new Indi_FrAMA(frama_params)); + indis.Push(Ref(new Indi_FrAMA(frama_params))); // Gator Oscillator. IndiGatorParams gator_params(13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN); - indis.Push(new Indi_Gator(gator_params)); + indis.Push(Ref(new Indi_Gator(gator_params))); // Heiken Ashi. IndiHeikenAshiParams _ha_params(); - indis.Push(new Indi_HeikenAshi(_ha_params)); + indis.Push(Ref(new Indi_HeikenAshi(_ha_params))); // Ichimoku Kinko Hyo. IndiIchimokuParams ichi_params(9, 26, 52); - indis.Push(new Indi_Ichimoku(ichi_params)); + indis.Push(Ref(new Indi_Ichimoku(ichi_params))); // Moving Average. IndiMAParams ma_params(13, 0, MODE_SMA, PRICE_OPEN); @@ -263,23 +263,23 @@ bool InitIndicators() { // Money Flow Index (MFI). IndiMFIParams mfi_params(14); - indis.Push(new Indi_MFI(mfi_params)); + indis.Push(Ref(new Indi_MFI(mfi_params))); // Momentum (MOM). IndiMomentumParams mom_params(); - indis.Push(new Indi_Momentum(mom_params)); + indis.Push(Ref(new Indi_Momentum(mom_params))); // On Balance Volume (OBV). - indis.Push(new Indi_OBV()); + indis.Push(Ref(new Indi_OBV())); // OsMA. IndiOsMAParams osma_params(12, 26, 9, PRICE_CLOSE); - indis.Push(new Indi_OsMA(osma_params)); + indis.Push(Ref(new Indi_OsMA(osma_params))); // Relative Strength Index (RSI). IndiRSIParams rsi_params(14, PRICE_OPEN); Ref indi_rsi = new Indi_RSI(rsi_params); - indis.Push(indi_rsi.Ptr()); + indis.Push(Ref(indi_rsi.Ptr())); // Bollinger Bands over RSI. IndiBandsParams indi_bands_over_rsi_params(20, 2, 0, PRICE_OPEN); @@ -302,11 +302,11 @@ bool InitIndicators() { // Relative Vigor Index (RVI). IndiRVIParams rvi_params(14); - indis.Push(new Indi_RVI(rvi_params)); + indis.Push(Ref(new Indi_RVI(rvi_params))); // Parabolic SAR. IndiSARParams sar_params(0.02, 0.2); - indis.Push(new Indi_SAR(sar_params)); + indis.Push(Ref(new Indi_SAR(sar_params))); // Standard Deviation (StdDev). Ref indi_price_for_stdev = new Indi_Price(PriceIndiParams()); @@ -314,24 +314,24 @@ bool InitIndicators() { // stddev_on_price_params.SetDraw(clrBlue, 1); // @fixme Ref indi_stddev_on_price = new Indi_StdDev(stddev_on_price_params, IDATA_BUILTIN, indi_price_for_stdev.Ptr()); - indis.Push(indi_stddev_on_price.Ptr()); + indis.Push(Ref(indi_stddev_on_price.Ptr())); // Stochastic Oscillator. IndiStochParams stoch_params(5, 3, 3, MODE_SMMA, STO_LOWHIGH); - indis.Push(new Indi_Stochastic(stoch_params)); + indis.Push(Ref(new Indi_Stochastic(stoch_params))); // Williams' Percent Range (WPR). IndiWPRParams wpr_params(14); - indis.Push(new Indi_WPR(wpr_params)); + indis.Push(Ref(new Indi_WPR(wpr_params))); // ZigZag. IndiZigZagParams zz_params(12, 5, 3); - indis.Push(new Indi_ZigZag(zz_params)); + indis.Push(Ref(new Indi_ZigZag(zz_params))); /* Special indicators */ // Demo/Dummy Indicator. - indis.Push(new Indi_Demo()); + indis.Push(Ref(new Indi_Demo())); // Bollinger Bands over Price indicator. PriceIndiParams price_params_4_bands(); @@ -339,7 +339,7 @@ bool InitIndicators() { IndiBandsParams bands_on_price_params(); // bands_on_price_params.SetDraw(clrCadetBlue); // @fixme Ref indi_bands_on_price = new Indi_Bands(bands_on_price_params, IDATA_BUILTIN, indi_price_4_bands.Ptr()); - indis.Push(indi_bands_on_price.Ptr()); + indis.Push(Ref(indi_bands_on_price.Ptr())); // Standard Deviation (StdDev) over MA(SMA). // NOTE: If you set ma_shift parameter for MA, then StdDev will no longer @@ -352,7 +352,7 @@ bool InitIndicators() { Ref indi_stddev_on_ma_sma = new Indi_StdDev(stddev_params_on_ma_sma, IDATA_BUILTIN, indi_ma_sma_for_stddev.Ptr()); - indis.Push(indi_stddev_on_ma_sma.Ptr()); + indis.Push(Ref(indi_stddev_on_ma_sma.Ptr())); // Standard Deviation (StdDev) in SMA mode over Price. PriceIndiParams price_params_for_stddev_sma(); @@ -361,7 +361,7 @@ bool InitIndicators() { // stddev_sma_on_price_params.SetDraw(true, 1); // @fixme Ref indi_stddev_on_sma = new Indi_StdDev(stddev_sma_on_price_params, IDATA_BUILTIN, indi_price_for_stddev_sma.Ptr()); - indis.Push(indi_stddev_on_sma.Ptr()); + indis.Push(Ref(indi_stddev_on_sma.Ptr())); // Moving Average (MA) over Price indicator. PriceIndiParams price_params_4_ma(); @@ -370,7 +370,7 @@ bool InitIndicators() { // ma_on_price_params.SetDraw(clrYellowGreen); // @fixme ma_on_price_params.SetIndicatorType(INDI_MA_ON_PRICE); Ref indi_ma_on_price = new Indi_MA(ma_on_price_params, IDATA_BUILTIN, indi_price_4_ma.Ptr()); - indis.Push(indi_ma_on_price.Ptr()); + indis.Push(Ref(indi_ma_on_price.Ptr())); // Commodity Channel Index (CCI) over Price indicator. PriceIndiParams price_params_4_cci(); @@ -378,7 +378,7 @@ bool InitIndicators() { IndiCCIParams cci_on_price_params(); // cci_on_price_params.SetDraw(clrYellowGreen, 1); // @fixme Ref indi_cci_on_price = new Indi_CCI(cci_on_price_params, IDATA_BUILTIN, indi_price_4_cci.Ptr()); - indis.Push(indi_cci_on_price.Ptr()); + indis.Push(Ref(indi_cci_on_price.Ptr())); // Envelopes over Price indicator. PriceIndiParams price_params_4_envelopes(); @@ -387,7 +387,7 @@ bool InitIndicators() { // env_on_price_params.SetDraw(clrBrown); // @fixme Ref indi_envelopes_on_price = new Indi_Envelopes(env_on_price_params, IDATA_BUILTIN, indi_price_4_envelopes.Ptr()); - indis.Push(indi_envelopes_on_price.Ptr()); + indis.Push(Ref(indi_envelopes_on_price.Ptr())); // DEMA over Price indicator. PriceIndiParams price_params_4_dema(); @@ -404,7 +404,7 @@ bool InitIndicators() { // mom_on_price_params.SetDraw(clrDarkCyan); // @fixme Ref indi_momentum_on_price = new Indi_Momentum(mom_on_price_params, IDATA_BUILTIN, indi_price_4_momentum.Ptr()); - indis.Push(indi_momentum_on_price.Ptr()); + indis.Push(Ref(indi_momentum_on_price.Ptr())); // Relative Strength Index (RSI) over Price indicator. PriceIndiParams price_params_4_rsi(); @@ -412,13 +412,13 @@ bool InitIndicators() { IndiRSIParams rsi_on_price_params(); // rsi_on_price_params.SetDraw(clrBisque, 1); // @fixme Ref indi_rsi_on_price = new Indi_RSI(rsi_on_price_params, IDATA_BUILTIN, indi_price_4_rsi.Ptr()); - indis.Push(indi_rsi_on_price.Ptr()); + indis.Push(Ref(indi_rsi_on_price.Ptr())); // Drawer (socket-based) indicator over RSI over Price. IndiDrawerParams drawer_params(14, PRICE_OPEN); // drawer_params.SetDraw(clrBisque, 0); // @fixme Ref indi_drawer_on_rsi = new Indi_Drawer(drawer_params, IDATA_BUILTIN, indi_rsi_on_price.Ptr()); - indis.Push(indi_drawer_on_rsi.Ptr()); + indis.Push(Ref(indi_drawer_on_rsi.Ptr())); // Applied Price over OHCL indicator. IndiAppliedPriceParams applied_price_params(); @@ -426,11 +426,11 @@ bool InitIndicators() { IndiOHLCParams applied_price_ohlc_params(PRICE_TYPICAL); Ref indi_applied_price_on_price = new Indi_AppliedPrice(applied_price_params, IDATA_INDICATOR, new Indi_OHLC(applied_price_ohlc_params)); - indis.Push(indi_applied_price_on_price.Ptr()); + indis.Push(Ref(indi_applied_price_on_price.Ptr())); // ADXW. IndiADXWParams adxw_params(14); - indis.Push(new Indi_ADXW(adxw_params)); + indis.Push(Ref(new Indi_ADXW(adxw_params))); // AMA. IndiAMAParams ama_params(); @@ -438,126 +438,126 @@ bool InitIndicators() { // However, in that case we need to specifiy applied price (excluding ASK and BID). Indi_AMA* _indi_ama = new Indi_AMA(ama_params, IDATA_INDICATOR); _indi_ama.SetAppliedPrice(PRICE_OPEN); - indis.Push(_indi_ama); + indis.Push(Ref(_indi_ama)); // Original AMA. IndiAMAParams ama_params_orig(); ama_params_orig.SetName("Original AMA to compare"); - indis.Push(new Indi_AMA(ama_params_orig)); + indis.Push(Ref(new Indi_AMA(ama_params_orig))); // Chaikin Oscillator. IndiCHOParams cho_params(); - indis.Push(new Indi_CHO(cho_params)); + indis.Push(Ref(new Indi_CHO(cho_params))); // Chaikin Volatility. IndiCHVParams chv_params(); - indis.Push(new Indi_CHV(chv_params)); + indis.Push(Ref(new Indi_CHV(chv_params))); // Color Bars. IndiColorBarsParams color_bars_params(); - indis.Push(new Indi_ColorBars(color_bars_params)); + indis.Push(Ref(new Indi_ColorBars(color_bars_params))); // Color Candles Daily. IndiColorCandlesDailyParams color_candles_daily_params(); - indis.Push(new Indi_ColorCandlesDaily(color_candles_daily_params)); + indis.Push(Ref(new Indi_ColorCandlesDaily(color_candles_daily_params))); // Color Line. IndiColorLineParams color_line_params(); - indis.Push(new Indi_ColorLine(color_line_params)); + indis.Push(Ref(new Indi_ColorLine(color_line_params))); // Detrended Price Oscillator. IndiDetrendedPriceParams detrended_params(); - indis.Push(new Indi_DetrendedPrice(detrended_params)); + indis.Push(Ref(new Indi_DetrendedPrice(detrended_params))); // Mass Index. IndiMassIndexParams mass_index_params(); - indis.Push(new Indi_MassIndex(mass_index_params)); + indis.Push(Ref(new Indi_MassIndex(mass_index_params))); // OHLC. IndiOHLCParams ohlc_params(); - indis.Push(new Indi_OHLC(ohlc_params)); + indis.Push(Ref(new Indi_OHLC(ohlc_params))); // Price Channel. IndiPriceChannelParams price_channel_params(); - indis.Push(new Indi_PriceChannel(price_channel_params)); + indis.Push(Ref(new Indi_PriceChannel(price_channel_params))); // Price Volume Trend. IndiPriceVolumeTrendParams price_volume_trend_params(); - indis.Push(new Indi_PriceVolumeTrend(price_volume_trend_params)); + indis.Push(Ref(new Indi_PriceVolumeTrend(price_volume_trend_params))); // Bill Williams' Zone Trade. IndiBWZTParams bwzt_params(); - indis.Push(new Indi_BWZT(bwzt_params)); + indis.Push(Ref(new Indi_BWZT(bwzt_params))); // Rate of Change. IndiRateOfChangeParams rate_of_change_params(); - indis.Push(new Indi_RateOfChange(rate_of_change_params)); + indis.Push(Ref(new Indi_RateOfChange(rate_of_change_params))); // Triple Exponential Moving Average. IndiTEMAParams tema_params(); - indis.Push(new Indi_TEMA(tema_params)); + indis.Push(Ref(new Indi_TEMA(tema_params))); // Triple Exponential Average. IndiTRIXParams trix_params(); - indis.Push(new Indi_TRIX(trix_params)); + indis.Push(Ref(new Indi_TRIX(trix_params))); // Ultimate Oscillator. IndiUltimateOscillatorParams ultimate_oscillator_params(); - indis.Push(new Indi_UltimateOscillator(ultimate_oscillator_params)); + indis.Push(Ref(new Indi_UltimateOscillator(ultimate_oscillator_params))); // VIDYA. IndiVIDYAParams vidya_params(); - indis.Push(new Indi_VIDYA(vidya_params)); + indis.Push(Ref(new Indi_VIDYA(vidya_params))); // Volumes. IndiVolumesParams volumes_params(); - indis.Push(new Indi_Volumes(volumes_params)); + indis.Push(Ref(new Indi_Volumes(volumes_params))); // Volume Rate of Change. IndiVROCParams vol_rate_of_change_params(); - indis.Push(new Indi_VROC(vol_rate_of_change_params)); + indis.Push(Ref(new Indi_VROC(vol_rate_of_change_params))); // Larry Williams' Accumulation/Distribution. IndiWilliamsADParams williams_ad_params(); - indis.Push(new Indi_WilliamsAD(williams_ad_params)); + indis.Push(Ref(new Indi_WilliamsAD(williams_ad_params))); // ZigZag Color. IndiZigZagColorParams zigzag_color_params(); - indis.Push(new Indi_ZigZagColor(zigzag_color_params)); + indis.Push(Ref(new Indi_ZigZagColor(zigzag_color_params))); // Custom Moving Average. IndiCustomMovingAverageParams cma_params(); - indis.Push(new Indi_CustomMovingAverage(cma_params)); + indis.Push(Ref(new Indi_CustomMovingAverage(cma_params))); // Math (specialized indicator). IndiMathParams math_params(MATH_OP_SUB, BAND_UPPER, BAND_LOWER, 0, 0); // math_params.SetDraw(clrBlue); // @fixme math_params.SetName("Bands(UP - LO)"); Ref indi_math_1 = new Indi_Math(math_params, IDATA_INDICATOR, indi_bands.Ptr()); - indis.Push(indi_math_1.Ptr()); + indis.Push(Ref(indi_math_1.Ptr())); // Math (specialized indicator) via custom math method. IndiMathParams math_custom_params(MathCustomOp, BAND_UPPER, BAND_LOWER, 0, 0); // math_custom_params.SetDraw(clrBeige); // @fixme math_custom_params.SetName("Bands(Custom math fn)"); Ref indi_math_2 = new Indi_Math(math_custom_params, IDATA_INDICATOR, indi_bands.Ptr()); - indis.Push(indi_math_2.Ptr()); + indis.Push(Ref(indi_math_2.Ptr())); // RS (Math-based) indicator. IndiRSParams rs_params(); - indis.Push(new Indi_RS(rs_params)); + indis.Push(Ref(new Indi_RS(rs_params))); // Pattern Detector. IndiPatternParams pattern_params(); - indis.Push(new Indi_Pattern(pattern_params)); + indis.Push(Ref(new Indi_Pattern(pattern_params))); // Pivot. IndiPivotParams pivot_params(); - indis.Push(new Indi_Pivot(pivot_params)); + indis.Push(Ref(new Indi_Pivot(pivot_params))); // Candle Pattern Detector. CandleParams candle_params(); - indis.Push(new Indi_Candle(candle_params)); + indis.Push(Ref(new Indi_Candle(candle_params))); // Push white-listed indicators here. // whitelisted_indis.Push(_indi_test); @@ -592,7 +592,7 @@ bool PrintIndicators(string _prefix = "") { continue; } if (_indi.Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY))) { - PrintFormat("%s: %s: %s", _prefix, _indi.GetName(), _indi.ToString(0)); + PrintFormat("%s: %s: %s", _prefix, _indi.GetName(), _indi.ToString()); } } return GetLastError() == ERR_NO_ERROR;