diff --git a/Array.mqh b/Array.mqh index 8612c60d4..9ac485b46 100644 --- a/Array.mqh +++ b/Array.mqh @@ -20,9 +20,10 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef ARRAY_MQH -#define ARRAY_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Defines. #ifndef MODE_ASCEND @@ -38,6 +39,26 @@ #define WHOLE_ARRAY 0 #endif +/** + * Reference to the array. + * + * @usage + * ARRAY_REF(, ) + */ +#ifdef __MQL__ +#define ARRAY_REF(T, N) REF(T) N +#endif + +/** + * Array definition. + * + * @usage + * ARRAY(, ) + */ +#ifdef __MQL__ +#define ARRAY(T, N) T N[]; +#endif + /* * Class to provide methods to deal with arrays. */ @@ -698,7 +719,19 @@ class Array { */ template static int ArrayMinimum(const ARRAY_REF(X, _array), int _start = 0, int _count = WHOLE_ARRAY) { +#ifdef __MQL__ return ::ArrayMinimum(_array); +#else + int _peak_index = 0; + + for (int i = 1; i < ArraySize(_array); ++i) { + if (_array[i] < _array[_peak_index]) { + _peak_index = i; + } + } + + return _peak_index; +#endif } /** @@ -718,8 +751,20 @@ class Array { * - https://www.mql5.com/en/docs/array/arraymaximum */ template - static int ArrayMaximum(const ARRAY_REF(X, array), int start = 0, int count = WHOLE_ARRAY) { - return ::ArrayMaximum(array); + static int ArrayMaximum(const ARRAY_REF(X, _array), int start = 0, int count = WHOLE_ARRAY) { +#ifdef __MQL__ + return ::ArrayMaximum(_array); +#else + int _peak_index = 0; + + for (int i = 1; i < ArraySize(_array); ++i) { + if (_array[i] > _array[_peak_index]) { + _peak_index = i; + } + } + + return _peak_index; +#endif } /** @@ -739,4 +784,3 @@ class Array { return ::ArraySize(array); } }; -#endif // ARRAY_MQH diff --git a/Bar.struct.h b/Bar.struct.h index bbd8f5a42..06e0969a8 100644 --- a/Bar.struct.h +++ b/Bar.struct.h @@ -30,11 +30,14 @@ #pragma once #endif +// Forward class declaration. +class Serializer; + // Includes. #include "Bar.enum.h" #include "Chart.enum.h" #include "ISerializable.h" -#include "Serializer.mqh" +#include "Serializer.enum.h" #include "SerializerNode.enum.h" /* Struct for storing OHLC values. */ @@ -216,6 +219,8 @@ struct BarOHLC string ToCSV() { return StringFormat("%d,%g,%g,%g,%g", time, open, high, low, close); } }; +#include "Serializer.mqh" + /* Method to serialize BarOHLC structure. */ SerializerNodeType BarOHLC::Serialize(Serializer &s) { // s.Pass(this, "time", TimeToString(time)); diff --git a/Chart.mqh b/Chart.mqh index 63df2f792..5865b0c75 100644 --- a/Chart.mqh +++ b/Chart.mqh @@ -88,11 +88,11 @@ struct MqlRates { class Chart : public Market { protected: // Structs. - ChartEntry chart_saves[]; + ARRAY(ChartEntry, chart_saves); ChartParams cparams; // Stores information about the prices, volumes and spread. - MqlRates rates[]; + ARRAY(MqlRates, rates); ChartEntry c_entry; // Stores indicator instances. @@ -452,7 +452,7 @@ class Chart : public Market { long StartBar = 0; long StartGenM1 = 0; long HistoryTotal = 0; - datetime modeling_start_time = D'1971.01.01 00:00'; + datetime modeling_start_time = DATETIME_LITERAL(1971.01.01 00:00); if (TimePr == NULL) TimePr = (ENUM_TIMEFRAMES)Period(); if (TimePr == PERIOD_M1) TimeNearPr = PERIOD_M1; diff --git a/Convert.mqh b/Convert.mqh index 8fd41f530..a280e2b3f 100644 --- a/Convert.mqh +++ b/Convert.mqh @@ -26,7 +26,6 @@ // Includes. #include "Account.enum.h" -#include "Math.h" #include "SymbolInfo.static.h" #include "Order.enum.h" @@ -357,60 +356,6 @@ public: static void DoubleToType(double _value, float& _out) { _out = (float)_value; } static void DoubleToType(double _value, double& _out) { _out = (double)_value; } static void DoubleToType(double _value, string& _out) { _out = _value ? "1" : "0"; } - - /** - * Converts MqlParam struct to double. - * - * @todo: Move to Data class. - */ - static double MqlParamToDouble(MqlParam& param) { - switch (param.type) { - case TYPE_BOOL: - return param.integer_value ? 1 : 0; - case TYPE_INT: - case TYPE_LONG: - case TYPE_UINT: - case TYPE_ULONG: - return (double)param.integer_value; - case TYPE_DOUBLE: - case TYPE_FLOAT: - return param.double_value; - case TYPE_CHAR: - case TYPE_STRING: - case TYPE_UCHAR: - return StringToDouble(param.string_value); - } - return DBL_MIN; - } - - /** - * Converts MqlParam struct to integer. - * - * @todo: Move to Data class. - */ - static long MqlParamToInteger(MqlParam& param) { - switch (param.type) { - case TYPE_BOOL: - return param.integer_value ? 1 : 0; - case TYPE_DATETIME: - case TYPE_INT: - case TYPE_LONG: - case TYPE_UINT: - case TYPE_ULONG: - case TYPE_SHORT: - return param.integer_value; - case TYPE_DOUBLE: - case TYPE_FLOAT: - return (int) param.double_value; - case TYPE_CHAR: - case TYPE_COLOR: - case TYPE_STRING: - case TYPE_UCHAR: - return StringToInteger(param.string_value); - } - return INT_MIN; - } - }; diff --git a/Data.struct.h b/Data.struct.h index 1ce505a7b..ae7cde6f4 100644 --- a/Data.struct.h +++ b/Data.struct.h @@ -36,6 +36,7 @@ struct MqlParam; // Includes. #include "Data.enum.h" +#include "Serializer.enum.h" #include "SerializerNode.enum.h" #ifndef __MQL__ @@ -106,6 +107,59 @@ struct MqlParam { }; #endif +/** + * Converts MqlParam struct to integer. + * + * @todo: Move to Data class. + */ +long MqlParamToInteger(MqlParam ¶m) { + switch (param.type) { + case TYPE_BOOL: + return param.integer_value ? 1 : 0; + case TYPE_DATETIME: + case TYPE_INT: + case TYPE_LONG: + case TYPE_UINT: + case TYPE_ULONG: + case TYPE_SHORT: + return param.integer_value; + case TYPE_DOUBLE: + case TYPE_FLOAT: + return (int)param.double_value; + case TYPE_CHAR: + case TYPE_COLOR: + case TYPE_STRING: + case TYPE_UCHAR: + return StringToInteger(param.string_value); + } + return INT_MIN; +} + + /** + * Converts MqlParam struct to double. + * + * @todo: Move to Data class. + */ +static double MqlParamToDouble(MqlParam ¶m) { + switch (param.type) { + case TYPE_BOOL: + return param.integer_value ? 1 : 0; + case TYPE_INT: + case TYPE_LONG: + case TYPE_UINT: + case TYPE_ULONG: + return (double)param.integer_value; + case TYPE_DOUBLE: + case TYPE_FLOAT: + return param.double_value; + case TYPE_CHAR: + case TYPE_STRING: + case TYPE_UCHAR: + return StringToDouble(param.string_value); + } + return DBL_MIN; +} + /** * Struct to provide multitype data parameters. * diff --git a/DateTime.enum.h b/DateTime.enum.h index 73e7facbe..b21cc9a20 100644 --- a/DateTime.enum.h +++ b/DateTime.enum.h @@ -30,6 +30,12 @@ #pragma once #endif +#ifdef __MQL__ +#define DATETIME_LITERAL(STR) D'##STR##' +#else +#define DATETIME_LITERAL(STR) D"##STR##" +#endif + /* Defines datetime conditions. */ enum ENUM_DATETIME_CONDITION { DATETIME_COND_IS_PEAK_HOUR = 1, // On peak hour diff --git a/Math.h b/Math.h index 3ecf23a96..16ab0e763 100644 --- a/Math.h +++ b/Math.h @@ -20,9 +20,10 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef MATH_H -#define MATH_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. #include "Data.struct.h" @@ -256,5 +257,3 @@ class Math { } } }; - -#endif // MATH_M diff --git a/MqlTick.h b/MqlTick.h new file mode 100644 index 000000000..241e807b5 --- /dev/null +++ b/MqlTick.h @@ -0,0 +1,48 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2021, EA31337 Ltd | +//| https://github.com/EA31337 | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * MqlTick structure. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#ifndef __MQL__ +/** + * Structure for storing the latest prices of the symbol. + * @docs + * https://www.mql5.com/en/docs/constants/structures/mqltick + */ +struct MqlTick { + datetime time; // Time of the last prices update. + double ask; // Current Ask price. + double bid; // Current Bid price. + double last; // Price of the last deal (last). + double volume_real; // Volume for the current last price with greater accuracy. + long time_msc; // Time of a price last update in milliseconds. + unsigned int flags; // Tick flags. + unsigned long volume; // Volume for the current last price. +}; +#endif diff --git a/Serializer.mqh b/Serializer.mqh index cef2c45b1..26371304e 100644 --- a/Serializer.mqh +++ b/Serializer.mqh @@ -25,6 +25,7 @@ #define SERIALIZER_MQH // Includes. +#include "Convert.mqh" #include "Serializer.define.h" #include "Serializer.enum.h" #include "SerializerNode.mqh" diff --git a/SymbolInfo.define.h b/SymbolInfo.define.h index 92f8acb43..68ef4c107 100644 --- a/SymbolInfo.define.h +++ b/SymbolInfo.define.h @@ -27,7 +27,7 @@ /* Defines */ -#ifndef __MQL4__ +#ifdef __MQL5__ // -- #define Point _Point #define Digits _Digits diff --git a/SymbolInfo.struct.h b/SymbolInfo.struct.h index d89112c08..addb386f5 100644 --- a/SymbolInfo.struct.h +++ b/SymbolInfo.struct.h @@ -32,26 +32,9 @@ // Includes. #include "ISerializable.h" +#include "MqlTick.h" #include "Serializer.mqh" -#ifndef __MQL__ -/** - * Structure for storing the latest prices of the symbol. - * @docs - * https://www.mql5.com/en/docs/constants/structures/mqltick - */ -struct MqlTick { - datetime time; // Time of the last prices update. - double ask; // Current Ask price. - double bid; // Current Bid price. - double last; // Price of the last deal (last). - double volume_real; // Volume for the current last price with greater accuracy. - long time_msc; // Time of a price last update in milliseconds. - unsigned int flags; // Tick flags. - unsigned long volume; // Volume for the current last price. -}; -#endif - // Defines struct to store symbol data. struct SymbolInfoEntry #ifndef __MQL__ diff --git a/Terminal.mqh b/Terminal.mqh index 4765e9729..5f87fd637 100644 --- a/Terminal.mqh +++ b/Terminal.mqh @@ -875,8 +875,8 @@ class Terminal : public Object { * Returns true when the condition is met. */ bool CheckCondition(ENUM_TERMINAL_CONDITION _cond, ARRAY_REF(DataParamEntry, _args)) { - long _arg1l = ArraySize(_args) > 0 ? Convert::MqlParamToInteger(_args[0]) : WRONG_VALUE; - long _arg2l = ArraySize(_args) > 1 ? Convert::MqlParamToInteger(_args[1]) : WRONG_VALUE; + long _arg1l = ArraySize(_args) > 0 ? MqlParamToInteger(_args[0]) : WRONG_VALUE; + long _arg2l = ArraySize(_args) > 1 ? MqlParamToInteger(_args[1]) : WRONG_VALUE; switch (_cond) { case TERMINAL_COND_IS_CONNECTED: return !IsConnected(); @@ -910,9 +910,9 @@ class Terminal : public Object { * Returns true when the condition is met. */ bool ExecuteAction(ENUM_TERMINAL_ACTION _action, ARRAY_REF(MqlParam, _args)) { - long _arg1l = ArraySize(_args) > 0 ? Convert::MqlParamToInteger(_args[0]) : WRONG_VALUE; - long _arg2l = ArraySize(_args) > 1 ? Convert::MqlParamToInteger(_args[1]) : WRONG_VALUE; - long _arg3l = ArraySize(_args) > 2 ? Convert::MqlParamToInteger(_args[2]) : WRONG_VALUE; + long _arg1l = ArraySize(_args) > 0 ? MqlParamToInteger(_args[0]) : WRONG_VALUE; + long _arg2l = ArraySize(_args) > 1 ? MqlParamToInteger(_args[1]) : WRONG_VALUE; + long _arg3l = ArraySize(_args) > 2 ? MqlParamToInteger(_args[2]) : WRONG_VALUE; switch (_action) { case TERMINAL_ACTION_CRASH: delete THIS_PTR;