diff --git a/Indicator.define.h b/Indicator.define.h index 8cb8c3086..9e040537b 100644 --- a/Indicator.define.h +++ b/Indicator.define.h @@ -119,7 +119,7 @@ class DrawIndicator; _obj.SetHandle(_handle); \ } \ } \ - if (Terminal::IsVisualMode()) { \ + if (Terminal::IsVisualMode()) { \ /* To avoid error 4806 (ERR_INDICATOR_DATA_NOT_FOUND), */ \ /* we check the number of calculated data only in visual mode. */ \ int _bars_calc = BarsCalculated(_handle); \ @@ -131,6 +131,7 @@ class DrawIndicator; } \ } \ if (CopyBuffer(_handle, MODE, SHIFT, 1, _res) < 0) { \ + // Print(#NATIVE_METHOD_CALL, " = ", _res[0], ", LE = ", _LastError); \ return ArraySize(_res) > 0 ? _res[0] : EMPTY_VALUE; \ } \ return _res[0]; diff --git a/IndicatorLegacy.h b/IndicatorLegacy.h index 0a5ef4dd6..471e84676 100644 --- a/IndicatorLegacy.h +++ b/IndicatorLegacy.h @@ -7,6 +7,19 @@ #pragma once #endif +#ifdef INDICATOR_LEGACY_VERSION_MT4 +#define INDICATOR_LEGACY_VERSION_DEFINED +#endif + +#ifdef INDICATOR_LEGACY_VERSION_MT5 +#define INDICATOR_LEGACY_VERSION_DEFINED +#endif + +#ifndef INDICATOR_LEGACY_VERSION_DEFINED +#define INDICATOR_LEGACY_VERSION_MT5 +#define INDICATOR_LEGACY_VERSION_DEFINED +#endif + #ifdef __MQL4__ #include @@ -14,6 +27,8 @@ #include #include +#ifdef INDICATOR_LEGACY_VERSION_MT5 + /** * Replacement for future OnCalculate(). Currently not used, but could be handy in the future. */ @@ -338,8 +353,30 @@ DEFINE_LEGACY_INDICATOR_2(iAD, iAD, string, symbol, int, period); // int iATR(string symbol, ENUM_TIMEFRAMES period, int ma_period); DEFINE_LEGACY_INDICATOR_3(iATR, iATR, string, symbol, int, period, int, ma_period); +// int iRSI(string symbol, ENUM_TIMEFRAMES period, int ma_period, int applied_price); +#define T1 string +#define N1 symbol +#define T2 int +#define N2 period +#define T3 int +#define N3 ma_period +#define T4 int +#define N4 applied_price +DEFINE_LEGACY_INDICATOR_4(iRSI, iRSI) +#undef T1 +#undef N1 +#undef T2 +#undef N2 +#undef T3 +#undef N3 +#undef T4 +#undef N4 +#undef T5 +#undef N5 +#undef T6 +#undef N6 + // int iMA(string symbol, ENUM_TIMEFRAMES period, int ma_period, int ma_shift, ENUM_MA_METHOD ma_method, -// ENUM_APPLIED_PRICE applied_price); #define T1 string #define N1 symbol #define T2 int @@ -366,4 +403,82 @@ DEFINE_LEGACY_INDICATOR_6(iMA, iMA) #undef T6 #undef N6 -#endif +#endif // INDICATOR_LEGACY_VERSION_MT5 +#endif // __MQL4__ + +#ifdef __MQL5__ +#ifdef INDICATOR_LEGACY_VERSION_MT4 + +/** + * Replacement for future StringConcatenate(). + */ +#define StringConcatenate StringConcatenateMT4 + +/** + * MQL5 wrapper of MQL4's StringConcatenate(). + */ +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d, E _e, F _f, G _g, H _h, I _i, J _j, K _k, L _l, + M _m) { + return (string)_a + (string)_b + (string)_c + (string)_d + (string)_e + (string)_f + (string)_g + (string)_h + + (string)_i + (string)_j + (string)_k + (string)_l + (string)_m; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d, E _e, F _f, G _g, H _h, I _i, J _j, K _k, L _l) { + return (string)_a + (string)_b + (string)_c + (string)_d + (string)_e + (string)_f + (string)_g + (string)_h + + (string)_i + (string)_j + (string)_k + (string)_l; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d, E _e, F _f, G _g, H _h, I _i, J _j, K _k) { + return (string)_a + (string)_b + (string)_c + (string)_d + (string)_e + (string)_f + (string)_g + (string)_h + + (string)_i + (string)_j + (string)_k; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d, E _e, F _f, G _g, H _h, I _i, J _j) { + return (string)_a + (string)_b + (string)_c + (string)_d + (string)_e + (string)_f + (string)_g + (string)_h + + (string)_i + (string)_j; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d, E _e, F _f, G _g, H _h, I _i) { + return (string)_a + (string)_b + (string)_c + (string)_d + (string)_e + (string)_f + (string)_g + (string)_h + + (string)_i; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d, E _e, F _f, G _g, H _h) { + return (string)_a + (string)_b + (string)_c + (string)_d + (string)_e + (string)_f + (string)_g + (string)_h; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d, E _e, F _f, G _g) { + return (string)_a + (string)_b + (string)_c + (string)_d + (string)_e + (string)_f + (string)_g; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d, E _e, F _f) { + return (string)_a + (string)_b + (string)_c + (string)_d + (string)_e + (string)_f; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d, E _e) { + return (string)_a + (string)_b + (string)_c + (string)_d + (string)_e; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c, D _d) { + return (string)_a + (string)_b + (string)_c + (string)_d; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b, C _c) { + return (string)_a + (string)_b + (string)_c; +} +template +string StringConcatenateMT4(string& _result, A _a, B _b) { + return (string)_a + (string)_b; +} +template +string StringConcatenateMT4(string& _result, A _a) { + return (string)_a; +} + +#endif // INDICATOR_LEGACY_VERSION_MT4 +#endif // __MQL5__ diff --git a/Storage/ValueStorage.native.h b/Storage/ValueStorage.native.h index ea7ebb4ab..f13271087 100644 --- a/Storage/ValueStorage.native.h +++ b/Storage/ValueStorage.native.h @@ -34,6 +34,7 @@ template class NativeValueStorage : public ValueStorage { // Dynamic native array. C _values[]; + int _values_size; public: /** @@ -49,7 +50,16 @@ class NativeValueStorage : public ValueStorage { /** * Initializes array with given one. */ - void SetData(ARRAY_REF(C, _arr)) { ArrayCopy(_values, _arr); } + void SetData(ARRAY_REF(C, _arr)) { + bool _was_series = ArrayGetAsSeries(_arr); + ArraySetAsSeries(_arr, false); + ArraySetAsSeries(_values, false); + ArrayResize(_values, 0); + ArrayCopy(_values, _arr); + _values_size = ArraySize(_arr); + ArraySetAsSeries(_arr, _was_series); + ArraySetAsSeries(_values, _was_series); + } /** * Initializes storage with given value. @@ -60,7 +70,7 @@ class NativeValueStorage : public ValueStorage { * Fetches value from a given shift. Takes into consideration as-series flag. */ virtual C Fetch(int _shift) { - if (_shift < 0 || _shift >= ArraySize(_values)) { + if (_shift < 0 || _shift >= _values_size) { return (C)EMPTY_VALUE; // Print("Invalid buffer data index: ", _shift, ". Buffer size: ", ArraySize(_values)); // DebugBreak(); @@ -77,7 +87,7 @@ class NativeValueStorage : public ValueStorage { /** * Returns number of values available to fetch (size of the values buffer). */ - virtual int Size() const { return ArraySize(_values); } + virtual int Size() const { return _values_size; } /** * Resizes storage to given size.