From c684e775c5313717036c292f35383f27d6b41eec Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Fri, 23 Jul 2021 13:07:47 +0200 Subject: [PATCH] Working MQL code after partial MQL/C++ refactoring. --- Array.mqh | 11 +++++ Config.mqh | 60 +++++++++++++++++++------- Data.struct.h | 6 +++ EA.mqh | 12 +++--- Indicator.mqh | 3 +- Market.struct.h | 3 ++ Order.mqh | 44 +++++++++---------- Order.struct.h | 13 +++--- Orders.mqh | 11 ++--- Refs.mqh | 1 + Strategy.mqh | 36 ++++++++-------- String.mqh | 11 +++-- SymbolInfo.struct.h | 2 - Terminal.enum.h | 2 +- Terminal.mqh | 5 +-- Trade.mqh | 3 +- tests/AccountTest.mq5 | 10 ++--- tests/BufferStructTest.mq5 | 15 ++++--- tests/ConfigTest.mq5 | 17 ++++---- tests/DatabaseTest.mq5 | 4 +- tests/MarketTest.mq5 | 11 ++--- tests/MatrixTest.mq5 | 86 +++++++++++++++++++------------------- tests/OrderTest.mq5 | 7 +++- tests/SerializerTest.mq5 | 58 +++++++++++-------------- tests/StrategyTest-RSI.mq5 | 5 ++- tests/StrategyTest.mq5 | 8 ++-- tests/SymbolInfoTest.mq5 | 78 +++++++++++++++++----------------- tests/TradeTest.mq5 | 10 ++--- 28 files changed, 297 insertions(+), 235 deletions(-) diff --git a/Array.mqh b/Array.mqh index 56ecf6b3a..2104989da 100644 --- a/Array.mqh +++ b/Array.mqh @@ -757,3 +757,14 @@ static int ArraySize(const ARRAY_REF(X, array)) { } } ; + +template +void ArrayPush(ARRAY_REF(X, array), X value) { + ArrayResize(ArraySize(array) + 1); + array[ArraySize(array) - 1] = value; +} +template +void ArrayPushObject(ARRAY_REF(X, array), X& value) { + ArrayResize(array, Array::ArraySize(array) + 1); + array[Array::ArraySize(array) - 1] = value; +} diff --git a/Config.mqh b/Config.mqh index 3e012cd2a..331243fee 100644 --- a/Config.mqh +++ b/Config.mqh @@ -41,23 +41,23 @@ string ToJSON(const MqlParam& param, bool, int) { switch (param.type) { case TYPE_BOOL: // boolean - return Serializer::ValueToString((bool)param.integer_value); + return SerializerConversions::ValueToString((bool)param.integer_value); case TYPE_INT: - return Serializer::ValueToString((int)param.integer_value); + return SerializerConversions::ValueToString((int)param.integer_value); break; case TYPE_DOUBLE: case TYPE_FLOAT: - return Serializer::ValueToString(param.double_value); + return SerializerConversions::ValueToString(param.double_value); break; case TYPE_CHAR: case TYPE_STRING: - return Serializer::ValueToString(param.string_value, true); + return SerializerConversions::ValueToString(param.string_value, true); break; case TYPE_DATETIME: #ifdef __MQL5__ - return Serializer::ValueToString(TimeToString(param.integer_value), true); + return SerializerConversions::ValueToString(TimeToString(param.integer_value), true); #else - return Serializer::ValueToString(TimeToStr(param.integer_value), true); + return SerializerConversions::ValueToString(TimeToStr(param.integer_value), true); #endif break; } @@ -81,6 +81,38 @@ struct ConfigEntry : public MqlParam { string_value == _s.string_value; } + ConfigEntry() { type = (ENUM_DATATYPE)-1; } + ConfigEntry(const ConfigEntry& _r) { THIS_REF = _r; } + + ConfigEntry(long _value) { + type = ENUM_DATATYPE::TYPE_LONG; + integer_value = _value; + } + ConfigEntry(int _value) { + type = ENUM_DATATYPE::TYPE_INT; + integer_value = _value; + } + ConfigEntry(bool _value) { + type = ENUM_DATATYPE::TYPE_BOOL; + integer_value = _value ? 1 : 0; + } + ConfigEntry(float _value) { + type = ENUM_DATATYPE::TYPE_FLOAT; + double_value = (double)_value; + } + ConfigEntry(double _value) { + type = ENUM_DATATYPE::TYPE_DOUBLE; + double_value = _value; + } + ConfigEntry(string _value) { + type = ENUM_DATATYPE::TYPE_STRING; + string_value = _value; + } + ConfigEntry(datetime _value) { + type = ENUM_DATATYPE::TYPE_DATETIME; + integer_value = _value; + } + SerializerNodeType Serialize(Serializer& s) { s.PassEnum(THIS_REF, "type", type, SERIALIZER_FIELD_FLAG_HIDDEN); @@ -155,38 +187,34 @@ class Config : public DictStruct { Config(const Config& r) : DictStruct(r) {} bool Set(string key, bool value) { - ConfigEntry param = {TYPE_BOOL, 0, 0, ""}; + ConfigEntry param = value; param.integer_value = value; return Set(key, param); } bool Set(string key, int value) { - ConfigEntry param = {TYPE_INT, 0, 0, ""}; + ConfigEntry param = value; param.integer_value = value; return Set(key, param); } bool Set(string key, long value) { - ConfigEntry param = {TYPE_LONG, 0, 0, ""}; - param.integer_value = value; + ConfigEntry param = value; return Set(key, param); } bool Set(string key, double value) { - ConfigEntry param = {TYPE_DOUBLE, 0, 0, ""}; - param.double_value = value; + ConfigEntry param = value; return Set(key, param); } bool Set(string key, string value) { - ConfigEntry param = {TYPE_STRING, 0, 0, ""}; - param.string_value = value; + ConfigEntry param = value; return Set(key, param); } bool Set(string key, datetime value) { - ConfigEntry param = {TYPE_DATETIME, 0, 0, ""}; - param.integer_value = value; + ConfigEntry param = value; return Set(key, param); } diff --git a/Data.struct.h b/Data.struct.h index a790da8ea..f78e82ff3 100644 --- a/Data.struct.h +++ b/Data.struct.h @@ -172,6 +172,12 @@ double MqlParamToDouble(MqlParam ¶m) { struct DataParamEntry : public MqlParam { public: DataParamEntry() { type = (ENUM_DATATYPE)WRONG_VALUE; } + DataParamEntry(ENUM_DATATYPE _type, long _integer_value, double _double_value, string _string_value) { + type = _type; + integer_value = _integer_value; + double_value = _double_value; + string_value = _string_value; + } DataParamEntry(const DataParamEntry &_r) { ASSIGN_TO_THIS(MqlParam, _r); } // Struct operators. void operator=(const bool _value) { diff --git a/EA.mqh b/EA.mqh index d498bc1e4..dbdfcffa6 100644 --- a/EA.mqh +++ b/EA.mqh @@ -710,16 +710,16 @@ class EA { } bool ExecuteAction(ENUM_EA_ACTION _action, long _arg1) { ARRAY(DataParamEntry, _args); - _args[0].type = TYPE_INT; - _args[0].integer_value = _arg1; + DataParamEntry _param1 = _arg1; + ArrayPushObject(_args, _param1); return EA::ExecuteAction(_action, _args); } bool ExecuteAction(ENUM_EA_ACTION _action, long _arg1, long _arg2) { ARRAY(DataParamEntry, _args); - _args[0].type = TYPE_INT; - _args[0].integer_value = _arg1; - _args[1].type = TYPE_INT; - _args[1].integer_value = _arg2; + DataParamEntry _param1 = _arg1; + DataParamEntry _param2 = _arg2; + ArrayPushObject(_args, _param1); + ArrayPushObject(_args, _param2); return EA::ExecuteAction(_action, _args); } diff --git a/Indicator.mqh b/Indicator.mqh index eba1c0727..37ae26c75 100644 --- a/Indicator.mqh +++ b/Indicator.mqh @@ -922,7 +922,8 @@ class Indicator : public Chart { } bool ExecuteAction(ENUM_INDICATOR_ACTION _action, long _arg1) { ARRAY(DataParamEntry, _args); - _args[0].type = TYPE_LONG; + DataParamEntry _param1 = _arg1; + ArrayPushObject(_args, _param1); _args[0].integer_value = _arg1; return ExecuteAction(_action, _args); } diff --git a/Market.struct.h b/Market.struct.h index cd6fe846f..1b8fa2961 100644 --- a/Market.struct.h +++ b/Market.struct.h @@ -25,6 +25,9 @@ * Includes Market's structs. */ +// Includes. +#include "Std.h" + // Structure for trade time static methods. struct MarketTimeForex : MqlDateTime { // Market sessions for trading Forex. diff --git a/Order.mqh b/Order.mqh index 64453732b..25f383740 100644 --- a/Order.mqh +++ b/Order.mqh @@ -1125,11 +1125,11 @@ class Order : public SymbolInfo { if (Order::OrderModify(_request.position, _request.price, _request.sl, _request.tp, _request.expiration, _color)) { // @see: https://www.mql5.com/en/docs/constants/structures/mqltraderesult - _result.ask = SymbolInfo::GetAsk(_request.symbol); // The current market Bid price (requote price). - _result.bid = SymbolInfo::GetBid(_request.symbol); // The current market Ask price (requote price). - _result.order = _request.position; // Order ticket. - _result.price = _request.price; // Deal price, confirmed by broker. - _result.volume = _request.volume; // Deal volume, confirmed by broker (@fixme?). + _result.ask = SymbolInfoStatic::GetAsk(_request.symbol); // The current market Bid price (requote price). + _result.bid = SymbolInfoStatic::GetBid(_request.symbol); // The current market Ask price (requote price). + _result.order = _request.position; // Order ticket. + _result.price = _request.price; // Deal price, confirmed by broker. + _result.volume = _request.volume; // Deal volume, confirmed by broker (@fixme?). _result.retcode = TRADE_RETCODE_DONE; //_result.comment = TODO; // The broker comment to operation (by default it is filled by description of trade // server return code). @@ -1137,19 +1137,19 @@ class Order : public SymbolInfo { } else if (_request.action == TRADE_ACTION_CLOSE_BY) { if (Order::OrderCloseBy(_request.position, _request.position_by, _color)) { // @see: https://www.mql5.com/en/docs/constants/structures/mqltraderesult - _result.ask = SymbolInfo::GetAsk(_request.symbol); // The current market Bid price (requote price). - _result.bid = SymbolInfo::GetBid(_request.symbol); // The current market Ask price (requote price). + _result.ask = SymbolInfoStatic::GetAsk(_request.symbol); // The current market Bid price (requote price). + _result.bid = SymbolInfoStatic::GetBid(_request.symbol); // The current market Ask price (requote price). _result.retcode = TRADE_RETCODE_DONE; } } else if (_request.action == TRADE_ACTION_DEAL || _request.action == TRADE_ACTION_REMOVE) { // @see: https://docs.mql4.com/trading/orderclose if (Order::OrderClose(_request.position, _request.volume, _request.price, (int)_request.deviation, _color)) { // @see: https://www.mql5.com/en/docs/constants/structures/mqltraderesult - _result.ask = SymbolInfo::GetAsk(_request.symbol); // The current market Bid price (requote price). - _result.bid = SymbolInfo::GetBid(_request.symbol); // The current market Ask price (requote price). - _result.order = _request.position; // Order ticket. - _result.price = _request.price; // Deal price, confirmed by broker. - _result.volume = _request.volume; // Deal volume, confirmed by broker (@fixme?). + _result.ask = SymbolInfoStatic::GetAsk(_request.symbol); // The current market Bid price (requote price). + _result.bid = SymbolInfoStatic::GetBid(_request.symbol); // The current market Ask price (requote price). + _result.order = _request.position; // Order ticket. + _result.price = _request.price; // Deal price, confirmed by broker. + _result.volume = _request.volume; // Deal volume, confirmed by broker (@fixme?). _result.retcode = TRADE_RETCODE_DONE; //_result.comment = TODO; // The broker comment to operation (by default it is filled by description of trade // server return code). @@ -1175,10 +1175,10 @@ class Order : public SymbolInfo { if (_request.order > 0) { // @see: https://www.mql5.com/en/docs/constants/structures/mqltraderesult - _result.ask = SymbolInfo::GetAsk(_request.symbol); // The current market Bid price (requote price). - _result.bid = SymbolInfo::GetBid(_request.symbol); // The current market Ask price (requote price). - _result.price = _request.price; // Deal price, confirmed by broker. - _result.volume = _request.volume; // Deal volume, confirmed by broker (@fixme?). + _result.ask = SymbolInfoStatic::GetAsk(_request.symbol); // The current market Bid price (requote price). + _result.bid = SymbolInfoStatic::GetBid(_request.symbol); // The current market Ask price (requote price). + _result.price = _request.price; // Deal price, confirmed by broker. + _result.volume = _request.volume; // Deal volume, confirmed by broker (@fixme?). //_result.comment = TODO; // The broker comment to operation (by default it is filled by description of trade // server return code). } @@ -2169,7 +2169,7 @@ class Order : public SymbolInfo { _result = ::OrderTakeProfit(); break; case ORDER_PRICE_CURRENT: - _result = SymbolInfo::GetBid(Order::OrderSymbol()); + _result = SymbolInfoStatic::GetBid(Order::OrderSymbol()); break; case ORDER_PRICE_STOPLIMIT: SetUserError(ERR_INVALID_PARAMETER); @@ -2608,13 +2608,13 @@ class Order : public SymbolInfo { bool ProcessConditions() { bool _result = true; if (IsOpen() && ShouldCloseOrder()) { - ARRAY(DataParamEntry, _args); - DataParamEntry _cond; - _cond.type = TYPE_STRING; - _cond.string_value = "Close condition"; + string _reason = "Close condition"; #ifdef __MQL__ - _args[0].string_value += StringFormat(": %s", EnumToString(oparams.cond_close)); + _reason += StringFormat(": %s", EnumToString(oparams.cond_close)); #endif + ARRAY(DataParamEntry, _args); + DataParamEntry _cond = _reason; + ArrayPushObject(_args, _cond); _result &= Order::ExecuteAction(ORDER_ACTION_CLOSE, _args); } return _result; diff --git a/Order.struct.h b/Order.struct.h index e207cd872..43c8453b4 100644 --- a/Order.struct.h +++ b/Order.struct.h @@ -30,8 +30,11 @@ #pragma once #endif -#include "Serializer.mqh" +// Includes. +#include "Data.struct.h" #include "Order.enum.h" +#include "Serializer.mqh" +#include "Terminal.mqh" #ifndef __MQL5__ /** @@ -56,10 +59,10 @@ struct MqlTradeCheckResult { * The structure for order parameters. */ struct OrderParams { - bool dummy; // Whether order is dummy (fake) or not (real). - color color_arrow; // Color of the opening arrow on the chart. - unsigned short refresh_rate; // How often to refresh order values (in secs). - ENUM_ORDER_CONDITION cond_close; // Close condition. + bool dummy; // Whether order is dummy (fake) or not (real). + color color_arrow; // Color of the opening arrow on the chart. + unsigned short refresh_rate; // How often to refresh order values (in secs). + ENUM_ORDER_CONDITION cond_close; // Close condition. ARRAY(DataParamEntry, cond_close_args); // Close condition argument. // Special struct methods. OrderParams() : dummy(false), color_arrow(clrNONE), refresh_rate(10), cond_close(ORDER_COND_NONE){}; diff --git a/Orders.mqh b/Orders.mqh index fd02de51c..3e5ca3a75 100644 --- a/Orders.mqh +++ b/Orders.mqh @@ -350,7 +350,8 @@ class Orders { * @return * Returns true on success. */ - bool OrdersCloseAll(const string _symbol = NULL, const ENUM_POSITION_TYPE _type = (ENUM_POSITION_TYPE)-1, const int _magic = -1) { + bool OrdersCloseAll(const string _symbol = NULL, const ENUM_POSITION_TYPE _type = (ENUM_POSITION_TYPE)-1, + const int _magic = -1) { #ifdef __MQL4__ //--- @@ -372,7 +373,7 @@ class Orders { (_magic == -1 || OrderMagicNumber() == _magic)) { string o_symbol = OrderSymbol(); - uint _digits = SymbolInfo::GetDigits(o_symbol); + uint _digits = SymbolInfoStatic::GetDigits(o_symbol); bool res_one = false; int attempts = 10; while (attempts > 0) { @@ -388,14 +389,14 @@ class Orders { double close_price = 0.0; if (order_type == OP_BUY) { - close_price = SymbolInfo::GetBid(o_symbol); + close_price = SymbolInfoStatic::GetBid(o_symbol); } if (order_type == OP_SELL) { - close_price = SymbolInfo::GetAsk(o_symbol); + close_price = SymbolInfoStatic::GetAsk(o_symbol); } //--- - uint slippage = SymbolInfo::GetSpread(o_symbol); + uint slippage = SymbolInfoStatic::GetSpread(o_symbol); //--- if (OrderClose(OrderTicket(), OrderLots(), close_price, slippage)) { diff --git a/Refs.mqh b/Refs.mqh index a36a1964d..1239e88ba 100644 --- a/Refs.mqh +++ b/Refs.mqh @@ -26,6 +26,7 @@ // Includes. #include "Refs.struct.h" +#include "Std.h" /** * For explanation about difference between strong(Ref) and weak(WeakRef) references please look at: diff --git a/Strategy.mqh b/Strategy.mqh index 3fd4f8014..c24ced03e 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -819,16 +819,16 @@ class Strategy : public Object { } bool CheckCondition(ENUM_STRATEGY_CONDITION _cond, long _arg1) { ARRAY(DataParamEntry, _args); - _args[0].type = TYPE_LONG; - _args[0].integer_value = _arg1; + DataParamEntry _param1 = _arg1; + ArrayPushObject(_args, _param1); return Strategy::CheckCondition(_cond, _args); } bool CheckCondition(ENUM_STRATEGY_CONDITION _cond, long _arg1, long _arg2) { ARRAY(DataParamEntry, _args); - _args[0].type = TYPE_LONG; - _args[0].integer_value = _arg1; - _args[1].type = TYPE_LONG; - _args[1].integer_value = _arg2; + DataParamEntry _param1 = _arg1; + DataParamEntry _param2 = _arg2; + ArrayPushObject(_args, _param1); + ArrayPushObject(_args, _param2); return Strategy::CheckCondition(_cond, _args); } bool CheckCondition(ENUM_STRATEGY_CONDITION _cond) { @@ -908,26 +908,26 @@ class Strategy : public Object { } bool ExecuteAction(ENUM_STRATEGY_ACTION _action, long _arg1) { ARRAY(DataParamEntry, _args); - _args[0].type = TYPE_INT; - _args[0].integer_value = _arg1; + DataParamEntry _param1 = _arg1; + ArrayPushObject(_args, _param1); return Strategy::ExecuteAction(_action, _args); } bool ExecuteAction(ENUM_STRATEGY_ACTION _action, long _arg1, long _arg2) { ARRAY(DataParamEntry, _args); - _args[0].type = TYPE_INT; - _args[0].integer_value = _arg1; - _args[1].type = TYPE_INT; - _args[1].integer_value = _arg2; + DataParamEntry _param1 = _arg1; + DataParamEntry _param2 = _arg2; + ArrayPushObject(_args, _param1); + ArrayPushObject(_args, _param2); return Strategy::ExecuteAction(_action, _args); } bool ExecuteAction(ENUM_STRATEGY_ACTION _action, long _arg1, long _arg2, long _arg3) { ARRAY(DataParamEntry, _args); - _args[0].type = TYPE_INT; - _args[0].integer_value = _arg1; - _args[1].type = TYPE_INT; - _args[1].integer_value = _arg2; - _args[2].type = TYPE_INT; - _args[2].integer_value = _arg3; + DataParamEntry _param1 = _arg1; + DataParamEntry _param2 = _arg2; + DataParamEntry _param3 = _arg3; + ArrayPushObject(_args, _param1); + ArrayPushObject(_args, _param2); + ArrayPushObject(_args, _param3); return Strategy::ExecuteAction(_action, _args); } bool ExecuteAction(ENUM_STRATEGY_ACTION _action) { diff --git a/String.mqh b/String.mqh index f29cb501a..3acccfd30 100644 --- a/String.mqh +++ b/String.mqh @@ -24,6 +24,9 @@ #ifndef STRING_MQH #define STRING_MQH +// Includes. +#include "Std.h" + // Defines. #define NL "\n" // New line: 0x0A (MQL file functions auto-convert 0x0A to 0x0D0A). #define TAB "\t" // Tab: 0x09. @@ -40,7 +43,9 @@ class String { /** * Class constructor. */ - String(string _string = "") : dlm(",") { if (_string != "") Add(_string); } + String(string _string = "") : dlm(",") { + if (_string != "") Add(_string); + } /** * Add a new string. @@ -58,9 +63,7 @@ class String { /** * Add a new value. */ - bool Add(int _value) { - return Add(IntegerToString(_value)); - } + bool Add(int _value) { return Add(IntegerToString(_value)); } /** * Get all arrays to string. diff --git a/SymbolInfo.struct.h b/SymbolInfo.struct.h index 1461593b8..04ea0e0b5 100644 --- a/SymbolInfo.struct.h +++ b/SymbolInfo.struct.h @@ -95,5 +95,3 @@ SerializerNodeType SymbolInfoProp::Serialize(Serializer& _s) { _s.Pass(THIS_REF, "vol_digits", vol_digits); return SerializerNodeObject; } - - diff --git a/Terminal.enum.h b/Terminal.enum.h index c1f2dbe83..6c12c13cc 100644 --- a/Terminal.enum.h +++ b/Terminal.enum.h @@ -181,7 +181,7 @@ enum ENUM_TERMINAL_INFO_STRING { }; /** - * Uninitialization reason codes are returned by the UninitializeReason() function. + * Uninitialization reason codes are returned by the UninitializeReason() function. * * @docs * - https://www.mql5.com/en/docs/constants/namedconstants/uninit diff --git a/Terminal.mqh b/Terminal.mqh index 5f87fd637..1f53e3b83 100644 --- a/Terminal.mqh +++ b/Terminal.mqh @@ -887,9 +887,8 @@ class Terminal : public Object { } bool CheckCondition(ENUM_TERMINAL_CONDITION _cond, long _arg1) { ARRAY(DataParamEntry, _args); - ArrayResize(_args, 1); - _args[0].type = TYPE_LONG; - _args[0].integer_value = _arg1; + DataParamEntry _param1 = _arg1; + ArrayPushObject(_args, _param1); return Terminal::CheckCondition(_cond, _args); } bool CheckCondition(ENUM_TERMINAL_CONDITION _cond) { diff --git a/Trade.mqh b/Trade.mqh index e70cd0adc..2baed3652 100644 --- a/Trade.mqh +++ b/Trade.mqh @@ -1466,7 +1466,8 @@ HistorySelect(0, TimeCurrent()); // Select history for access. } bool CheckCondition(ENUM_TRADE_CONDITION _cond, long _arg1) { ARRAY(DataParamEntry, _args); - _args[0].integer_value = _arg1; + DataParamEntry _param1 = _arg1; + ArrayPushObject(_args, _param1); return Trade::CheckCondition(_cond, _args); } bool CheckCondition(ENUM_TRADE_CONDITION _cond) { diff --git a/tests/AccountTest.mq5 b/tests/AccountTest.mq5 index f569c4a78..b63b3bbe8 100644 --- a/tests/AccountTest.mq5 +++ b/tests/AccountTest.mq5 @@ -72,12 +72,12 @@ int OnInit() { assertTrueOrFail(acc.GetStartCredit() == _credit, "Invalid start credit!"); // 0 assertTrueOrFail(acc.GetAccountStopoutLevel() == 0.3, "Invalid account stopout level!"); // 0.3 - Print(acc.GetAccountFreeMarginCheck(ORDER_TYPE_BUY, SymbolInfo::GetVolumeMin(_Symbol))); - Print(acc.GetAccountFreeMarginCheck(ORDER_TYPE_SELL, SymbolInfo::GetVolumeMin(_Symbol))); - Print(acc.IsFreeMargin(ORDER_TYPE_BUY, SymbolInfo::GetVolumeMin(_Symbol))); - Print(acc.IsFreeMargin(ORDER_TYPE_SELL, SymbolInfo::GetVolumeMin(_Symbol))); + Print(acc.GetAccountFreeMarginCheck(ORDER_TYPE_BUY, SymbolInfoStatic::GetVolumeMin(_Symbol))); + Print(acc.GetAccountFreeMarginCheck(ORDER_TYPE_SELL, SymbolInfoStatic::GetVolumeMin(_Symbol))); + Print(acc.IsFreeMargin(ORDER_TYPE_BUY, SymbolInfoStatic::GetVolumeMin(_Symbol))); + Print(acc.IsFreeMargin(ORDER_TYPE_SELL, SymbolInfoStatic::GetVolumeMin(_Symbol))); - assertTrueOrFail(acc.GetDrawdownInPct() == 0.0, "Invalid drawdown value!"); // 0 + assertTrueOrFail(acc.GetDrawdownInPct() == 0.0, "Invalid drawdown value!"); // 0 // assertTrueOrFail(acc.GetRiskMarginLevel() == 0.0, "Invalid risk margin level!"); // 0 assertTrueOrFail(acc.CalcInitDeposit() == _balance, "Invalid calculated initial deposit!"); // 10000 diff --git a/tests/BufferStructTest.mq5 b/tests/BufferStructTest.mq5 index 0aa38a9ca..a55ed6baa 100644 --- a/tests/BufferStructTest.mq5 +++ b/tests/BufferStructTest.mq5 @@ -26,7 +26,10 @@ // Includes #include "../BufferStruct.mqh" +#include "../Data.define.h" +#include "../Data.struct.h" #include "../SerializerJSON.mqh" +#include "../Std.h" #include "../Test.mqh" /** @@ -36,12 +39,12 @@ int OnInit() { // Test 1 (DataParamEntry). BufferStruct buff_params; - DataParamEntry pair = {TYPE_STRING, 0, 0, "XLMBTC"}; - DataParamEntry startDate = {TYPE_DATETIME, D'2020.01.01 00:00', 0, ""}; - DataParamEntry endDate = {TYPE_DATETIME, D'2025.03.05 23:23', 0, ""}; - DataParamEntry enable = {TYPE_BOOL, 1, 0, ""}; - DataParamEntry limit = {TYPE_INT, 5, 0, ""}; - DataParamEntry doubleVal = {TYPE_DOUBLE, 0, 7.5, ""}; + DataParamEntry pair = "XLMBTC"; + DataParamEntry startDate = StrToTime("2020.01.01 00:00"); + DataParamEntry endDate = StrToTime("2025.03.05 23:23"); + DataParamEntry enable = true; + DataParamEntry limit = 5; + DataParamEntry doubleVal = 7.5; buff_params.Add(pair, 1); buff_params.Add(startDate, 2); diff --git a/tests/ConfigTest.mq5 b/tests/ConfigTest.mq5 index c8aec8963..2477a62f6 100644 --- a/tests/ConfigTest.mq5 +++ b/tests/ConfigTest.mq5 @@ -26,6 +26,7 @@ // Includes. #include "../Config.mqh" +#include "../Data.define.h" #include "../Dict.mqh" #include "../DictObject.mqh" #include "../SerializerConverter.mqh" @@ -70,12 +71,12 @@ Config* config; int OnInit() { config = new Config(); - ConfigEntry pair = {TYPE_STRING, 0, 0, "XLMBTC"}; - ConfigEntry startDate = {TYPE_DATETIME, D'2020.01.01 00:00', 0, ""}; - ConfigEntry endDate = {TYPE_DATETIME, D'2025.03.05 23:23', 0, ""}; - ConfigEntry enable = {TYPE_BOOL, 1, 0, ""}; - ConfigEntry limit = {TYPE_INT, 5, 0, ""}; - ConfigEntry max = {TYPE_DOUBLE, 0, 7.5, ""}; + ConfigEntry pair = "XLMBTC"; + ConfigEntry startDate = StrToTime("2020.01.01 00:00"); + ConfigEntry endDate = StrToTime("2025.03.05 23:23"); + ConfigEntry enable = true; + ConfigEntry limit = 5; + ConfigEntry max = 7.5; config.Set("pair", pair); config.Set("startDate", startDate); @@ -85,8 +86,8 @@ int OnInit() { config.Set("max", max); config.Set("otherPair", "XLMBTC"); - config.Set("otherStartDate", D'2020.01.01 00:00'); - config.Set("otherEndDate", D'2025.03.05 23:23'); + config.Set("otherStartDate", StrToTime("2020.01.01 00:00")); + config.Set("otherEndDate", StrToTime("2025.03.05 23:23")); config.Set("otherEnable", true); config.Set("otherLimit", 5); config.Set("otherMax", 7.5); diff --git a/tests/DatabaseTest.mq5 b/tests/DatabaseTest.mq5 index 2bcc96979..c37b969c9 100644 --- a/tests/DatabaseTest.mq5 +++ b/tests/DatabaseTest.mq5 @@ -24,10 +24,12 @@ * Test functionality of Database class. */ +// Need to be include before Database.mqh. +#include "../SymbolInfo.mqh" // FOOBAR pragma: keep + // Includes. #include "../BufferStruct.mqh" #include "../Database.mqh" -#include "../SymbolInfo.mqh" #include "../Test.mqh" // Global variables. diff --git a/tests/MarketTest.mq5 b/tests/MarketTest.mq5 index 9b322fe7c..c1b508841 100644 --- a/tests/MarketTest.mq5 +++ b/tests/MarketTest.mq5 @@ -25,6 +25,7 @@ */ // Includes. +#include "../Chart.define.h" #include "../Market.mqh" #include "../Test.mqh" @@ -55,7 +56,7 @@ int OnInit() { "Invalid market value for MODE_LOTSIZE!"); assertTrueOrFail(Market::MarketInfo(_Symbol, MODE_TICKVALUE) == market.GetTickValue(), "Invalid market value for MODE_TICKVALUE!"); - assertTrueOrFail((float) Market::MarketInfo(_Symbol, MODE_TICKSIZE) == (float) market.GetTickSize(), + assertTrueOrFail((float)Market::MarketInfo(_Symbol, MODE_TICKSIZE) == (float)market.GetTickSize(), "Invalid market value for MODE_TICKSIZE!"); assertTrueOrFail(Market::MarketInfo(_Symbol, MODE_SWAPLONG) == market.GetSwapLong(), "Invalid market value for MODE_SWAPLONG!"); @@ -75,8 +76,8 @@ int OnInit() { // @todo: MODE_STARTING // @todo: MODE_EXPIRATION // @fixme - //assertTrueOrFail((bool)Market::MarketInfo(_Symbol, MODE_TRADEALLOWED) == Terminal::IsTradeAllowed(), - //"Invalid market value for MODE_TRADEALLOWED!"); + // assertTrueOrFail((bool)Market::MarketInfo(_Symbol, MODE_TRADEALLOWED) == Terminal::IsTradeAllowed(), + //"Invalid market value for MODE_TRADEALLOWED!"); // MODE_MARGINCALCMODE assertTrueOrFail(Market::MarketInfo(_Symbol, MODE_MARGININIT) == market.GetMarginInit(), "Invalid market value for MODE_MARGININIT!"); @@ -129,8 +130,8 @@ int OnInit() { // @todo: MODE_STARTING // @todo: MODE_EXPIRATION // @fixme - // assertTrueOrFail((bool)Market::MarketInfo(_Symbol, MODE_TRADEALLOWED), "Invalid market value for MODE_TRADEALLOWED!"); - // MODE_MARGINCALCMODE + // assertTrueOrFail((bool)Market::MarketInfo(_Symbol, MODE_TRADEALLOWED), "Invalid market value for + // MODE_TRADEALLOWED!"); MODE_MARGINCALCMODE assertTrueOrFail(Market::MarketInfo(_Symbol, MODE_MARGININIT) == MarketInfo(_Symbol, MODE_MARGININIT), "Invalid market value for MODE_MARGININIT!"); assertTrueOrFail(Market::MarketInfo(_Symbol, MODE_MARGINMAINTENANCE) == MarketInfo(_Symbol, MODE_MARGINMAINTENANCE), diff --git a/tests/MatrixTest.mq5 b/tests/MatrixTest.mq5 index 24c57c52a..f1d3d679e 100644 --- a/tests/MatrixTest.mq5 +++ b/tests/MatrixTest.mq5 @@ -37,77 +37,77 @@ int OnInit() { int a, b, c; - Matrix matrix(2, 3, 20); + Matrix _matrix(2, 3, 20); - assertTrueOrFail(matrix.GetRange(0) == 2, "1st dimension's length is not valid!"); - assertTrueOrFail(matrix.GetRange(1) == 3, "2nd dimension's length is not valid!"); - assertTrueOrFail(matrix.GetRange(2) == 20, "3rd dimension's length is not valid!"); + assertTrueOrFail(_matrix.GetRange(0) == 2, "1st dimension's length is not valid!"); + assertTrueOrFail(_matrix.GetRange(1) == 3, "2nd dimension's length is not valid!"); + assertTrueOrFail(_matrix.GetRange(2) == 20, "3rd dimension's length is not valid!"); - assertTrueOrFail(matrix.GetDimensions() == 3, "Number of matrix dimensions isn't valid!"); + assertTrueOrFail(_matrix.GetDimensions() == 3, "Number of _matrix dimensions isn't valid!"); - matrix.Fill(1); + _matrix.Fill(1); - for (a = 0; a < matrix.GetRange(0); ++a) { - for (b = 0; b < matrix.GetRange(1); ++b) { - for (c = 0; c < matrix.GetRange(2); ++c) { - assertTrueOrFail(matrix[a][b][c].Val() == 1, "Fill() didn't fill the whole matrix!"); + for (a = 0; a < _matrix.GetRange(0); ++a) { + for (b = 0; b < _matrix.GetRange(1); ++b) { + for (c = 0; c < _matrix.GetRange(2); ++c) { + assertTrueOrFail(_matrix[a][b][c].Val() == 1, "Fill() didn't fill the whole _matrix!"); } } } - matrix.Add(2); + _matrix.Add(2); - for (a = 0; a < matrix.GetRange(0); ++a) { - for (b = 0; b < matrix.GetRange(1); ++b) { - for (c = 0; c < matrix.GetRange(2); ++c) { - assertTrueOrFail(matrix[a][b][c].Val() == 3, "Add() didn't add value to the whole matrix!"); + for (a = 0; a < _matrix.GetRange(0); ++a) { + for (b = 0; b < _matrix.GetRange(1); ++b) { + for (c = 0; c < _matrix.GetRange(2); ++c) { + assertTrueOrFail(_matrix[a][b][c].Val() == 3, "Add() didn't add value to the whole _matrix!"); } } } - matrix.Sub(2); + _matrix.Sub(2); - for (a = 0; a < matrix.GetRange(0); ++a) { - for (b = 0; b < matrix.GetRange(1); ++b) { - for (c = 0; c < matrix.GetRange(2); ++c) { - assertTrueOrFail(matrix[a][b][c].Val() == 1, "Sub() didn't subtract value from the whole matrix!"); + for (a = 0; a < _matrix.GetRange(0); ++a) { + for (b = 0; b < _matrix.GetRange(1); ++b) { + for (c = 0; c < _matrix.GetRange(2); ++c) { + assertTrueOrFail(_matrix[a][b][c].Val() == 1, "Sub() didn't subtract value from the whole _matrix!"); } } } - matrix.Mul(4); + _matrix.Mul(4); - for (a = 0; a < matrix.GetRange(0); ++a) { - for (b = 0; b < matrix.GetRange(1); ++b) { - for (c = 0; c < matrix.GetRange(2); ++c) { - assertTrueOrFail(matrix[a][b][c].Val() == 4, "Mul() didn't multiply value for the whole matrix!"); + for (a = 0; a < _matrix.GetRange(0); ++a) { + for (b = 0; b < _matrix.GetRange(1); ++b) { + for (c = 0; c < _matrix.GetRange(2); ++c) { + assertTrueOrFail(_matrix[a][b][c].Val() == 4, "Mul() didn't multiply value for the whole _matrix!"); } } } - matrix.Div(4); + _matrix.Div(4); - for (a = 0; a < matrix.GetRange(0); ++a) { - for (b = 0; b < matrix.GetRange(1); ++b) { - for (c = 0; c < matrix.GetRange(2); ++c) { - assertTrueOrFail(matrix[a][b][c].Val() == 1, "Div() didn't divide value for the whole matrix!"); + for (a = 0; a < _matrix.GetRange(0); ++a) { + for (b = 0; b < _matrix.GetRange(1); ++b) { + for (c = 0; c < _matrix.GetRange(2); ++c) { + assertTrueOrFail(_matrix[a][b][c].Val() == 1, "Div() didn't divide value for the whole _matrix!"); } } } - assertTrueOrFail((int)matrix.Sum() == matrix.GetSize(), "Sum() didn't sum values for the whole matrix!"); + assertTrueOrFail((int)_matrix.Sum() == _matrix.GetSize(), "Sum() didn't sum values for the whole _matrix!"); - matrix.FillRandom(); + _matrix.FillRandom(); - assertTrueOrFail((int)matrix.Sum() != matrix.GetSize(), "FillRandom() should replace 1's with another values!"); + assertTrueOrFail((int)_matrix.Sum() != _matrix.GetSize(), "FillRandom() should replace 1's with another values!"); - matrix.FillRandom(-0.1, 0.1); + _matrix.FillRandom(-0.1, 0.1); - for (a = 0; a < matrix.GetRange(0); ++a) { - for (b = 0; b < matrix.GetRange(1); ++b) { - for (c = 0; c < matrix.GetRange(2); ++c) { - assertTrueOrFail(matrix[a][b][c].Val() >= -0.1 && matrix[a][b][c].Val() <= 0.1, - "FillRandom() didn't fill random values properly for the whole matrix!"); + for (a = 0; a < _matrix.GetRange(0); ++a) { + for (b = 0; b < _matrix.GetRange(1); ++b) { + for (c = 0; c < _matrix.GetRange(2); ++c) { + assertTrueOrFail(_matrix[a][b][c].Val() >= -0.1 && _matrix[a][b][c].Val() <= 0.1, + "FillRandom() didn't fill random values properly for the whole _matrix!"); } } } @@ -120,13 +120,13 @@ int OnInit() { matrix2[0][3] = 7; matrix2[0][4] = 12; - assertTrueOrFail(matrix2.Avg() == 5.2, "Avg() didn't calculate valid average for matrix values!"); + assertTrueOrFail(matrix2.Avg() == 5.2, "Avg() didn't calculate valid average for _matrix values!"); - assertTrueOrFail(matrix2.Min() == 1, "Min() didn't find the lowest matrix value!"); + assertTrueOrFail(matrix2.Min() == 1, "Min() didn't find the lowest _matrix value!"); - assertTrueOrFail(matrix2.Max() == 12, "Max() didn't find the highest matrix value!"); + assertTrueOrFail(matrix2.Max() == 12, "Max() didn't find the highest _matrix value!"); - assertTrueOrFail(matrix2.Med() == 4, "Med() didn't find median of the matrix values!"); + assertTrueOrFail(matrix2.Med() == 4, "Med() didn't find median of the _matrix values!"); matrix2.SetShape(2, 5); diff --git a/tests/OrderTest.mq5 b/tests/OrderTest.mq5 index 6266fed62..b9f8427c0 100644 --- a/tests/OrderTest.mq5 +++ b/tests/OrderTest.mq5 @@ -106,8 +106,11 @@ bool OpenOrder(int _index, int _order_no) { // New order params. OrderParams _oparams; if (_request.type == ORDER_TYPE_SELL) { - DataParamEntry _cond_args[] = {{TYPE_INT, ORDER_TYPE_TIME}, {TYPE_INT, 0}}; - _cond_args[1].integer_value = PeriodSeconds() * (MAX_ORDERS + _index); + ARRAY(DataParamEntry, _cond_args); + DataParamEntry _param1 = ORDER_TYPE_TIME; + DataParamEntry _param2 = PeriodSeconds() * (MAX_ORDERS + _index); + ArrayPushObject(_cond_args, _param1); + ArrayPushObject(_cond_args, _param2); _oparams.SetConditionClose(ORDER_COND_LIFETIME_GT_ARG, _cond_args); } // New order. diff --git a/tests/SerializerTest.mq5 b/tests/SerializerTest.mq5 index 6a7b2f37d..b4a8a3f53 100644 --- a/tests/SerializerTest.mq5 +++ b/tests/SerializerTest.mq5 @@ -182,17 +182,9 @@ int OnInit() { DictStruct buffer_entries; - DataParamEntry buffer_entry1; - buffer_entry1.type = TYPE_DOUBLE; - buffer_entry1.double_value = 1.0; - - DataParamEntry buffer_entry2; - buffer_entry2.type = TYPE_DOUBLE; - buffer_entry2.double_value = 2.0; - - DataParamEntry buffer_entry3; - buffer_entry3.type = TYPE_DOUBLE; - buffer_entry3.double_value = 3.0; + DataParamEntry buffer_entry1 = 1.0; + DataParamEntry buffer_entry2 = 2.0; + DataParamEntry buffer_entry3 = 3.0; buffer_entries.Push(buffer_entry1); buffer_entries.Push(buffer_entry2); @@ -207,12 +199,12 @@ int OnInit() { Config config1; - ConfigEntry pair1 = {TYPE_STRING, 0, 0, "XLMBTC"}; - ConfigEntry startDate1 = {TYPE_DATETIME, D'2020.01.01 00:00', 0, ""}; - ConfigEntry endDate1 = {TYPE_DATETIME, D'2025.03.05 23:23', 0, ""}; - ConfigEntry enable1 = {TYPE_BOOL, 1, 0, ""}; - ConfigEntry limit1 = {TYPE_INT, 5, 0, ""}; - ConfigEntry max1 = {TYPE_DOUBLE, 0, 7.5, ""}; + ConfigEntry pair1 = "XLMBTC"; + ConfigEntry startDate1 = StrToTime("2020.01.01 00:00"); + ConfigEntry endDate1 = StrToTime("2025.03.05 23:23"); + ConfigEntry enable1 = true; + ConfigEntry limit1 = 5; + ConfigEntry max1 = 7.5; config1.Set("pair", pair1); config1.Set("startDate", startDate1); @@ -221,20 +213,20 @@ int OnInit() { config1.Set("limit", limit1); config1.Set("max", max1); config1.Set("otherPair", "XLMBTC"); - config1.Set("otherStartDate", D'2020.01.01 00:00'); - config1.Set("otherEndDate", D'2025.03.05 23:23'); + config1.Set("otherStartDate", StrToTime("2020.01.01 00:00")); + config1.Set("otherEndDate", StrToTime("2025.03.05 23:23")); config1.Set("otherEnable", true); config1.Set("otherLimit", 5); config1.Set("otherMax", 7.5); Config config2; - ConfigEntry pair2 = {TYPE_STRING, 0, 0, "PLNBTC"}; - ConfigEntry startDate2 = {TYPE_DATETIME, D'2011.01.01 00:00', 0, ""}; - ConfigEntry endDate2 = {TYPE_DATETIME, D'2015.03.05 23:23', 0, ""}; - ConfigEntry enable2 = {TYPE_BOOL, 3, 0, ""}; - ConfigEntry limit2 = {TYPE_INT, 6, 0, ""}; - ConfigEntry max2 = {TYPE_DOUBLE, 0, 2.1, ""}; + ConfigEntry pair2 = "PLNBTC"; + ConfigEntry startDate2 = StrToTime("2011.01.01 00:00"); + ConfigEntry endDate2 = StrToTime("2015.03.05 23:23"); + ConfigEntry enable2 = true; + ConfigEntry limit2 = 6; + ConfigEntry max2 = 2.1; config2.Set("pair", pair2); config2.Set("startDate", startDate2); @@ -243,8 +235,8 @@ int OnInit() { config2.Set("limit", limit2); config2.Set("max", max2); config2.Set("otherPair", "XLMBTC"); - config2.Set("otherStartDate", D'2019.01.01 00:00'); - config2.Set("otherEndDate", D'2023.03.05 23:23'); + config2.Set("otherStartDate", StrToTime("2019.01.01 00:00")); + config2.Set("otherEndDate", StrToTime("2023.03.05 23:23")); config2.Set("otherEnable", false); config2.Set("otherLimit", 2); config2.Set("otherMax", 1.5); @@ -299,12 +291,12 @@ int OnInit() { BufferStruct buff_params; - DataParamEntry pair = {TYPE_STRING, 0, 0, "XLMBTC"}; - DataParamEntry startDate = {TYPE_DATETIME, D'2020.01.01 00:00', 0, ""}; - DataParamEntry endDate = {TYPE_DATETIME, D'2025.03.05 23:23', 0, ""}; - DataParamEntry enable = {TYPE_BOOL, 1, 0, ""}; - DataParamEntry limit = {TYPE_INT, 5, 0, ""}; - DataParamEntry doubleVal = {TYPE_DOUBLE, 0, 7.5, ""}; + DataParamEntry pair = "XLMBTC"; + DataParamEntry startDate = StrToTime("2020.01.01 00:00"); + DataParamEntry endDate = StrToTime("2025.03.05 23:23"); + DataParamEntry enable = true; + DataParamEntry limit = 5; + DataParamEntry doubleVal = 7.5; buff_params.Add(pair, 1); buff_params.Add(startDate, 2); diff --git a/tests/StrategyTest-RSI.mq5 b/tests/StrategyTest-RSI.mq5 index 52238ffbb..850ed6dd7 100644 --- a/tests/StrategyTest-RSI.mq5 +++ b/tests/StrategyTest-RSI.mq5 @@ -33,7 +33,8 @@ class Stg_RSI : public Strategy { public: // Class constructor. - void Stg_RSI(StgParams &_sparams, TradeParams &_tparams, ChartParams &_cparams, string _name = "") : Strategy(_sparams, _tparams, chart_params_defaults, _name) {} + void Stg_RSI(StgParams &_sparams, TradeParams &_tparams, ChartParams &_cparams, string _name = "") + : Strategy(_sparams, _tparams, chart_params_defaults, _name) {} static Stg_RSI *Init(ENUM_TIMEFRAMES _tf = NULL, long _magic_no = NULL, ENUM_LOG_LEVEL _log_level = V_INFO) { ChartParams _cparams(_tf); @@ -97,7 +98,7 @@ int OnInit() { * Implements OnTick(). */ void OnTick() { - if (stg_rsi.TickFilter(SymbolInfo::GetTick(_Symbol), 1)) { + if (stg_rsi.TickFilter(SymbolInfoStatic::GetTick(_Symbol), 1)) { StrategySignal _signal = stg_rsi.ProcessSignals(); if (_signal.CheckSignals(STRAT_SIGNAL_BUY_OPEN)) { assertTrueOrExit(_signal.GetOpenDirection() == 1, "Wrong order open direction!"); diff --git a/tests/StrategyTest.mq5 b/tests/StrategyTest.mq5 index f5d44334a..f89159a0a 100644 --- a/tests/StrategyTest.mq5 +++ b/tests/StrategyTest.mq5 @@ -36,7 +36,8 @@ struct DataParamEntry; class Stg1 : public Strategy { public: // Class constructor. - void Stg1(StgParams &_params, string _name = "") : Strategy(_params, trade_params_defaults, chart_params_defaults, _name) {} + void Stg1(StgParams &_params, string _name = "") + : Strategy(_params, trade_params_defaults, chart_params_defaults, _name) {} void OnInit() { trade.tparams.SetMagicNo(1234); } bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method, float _level, int _shift) { return _method % 2 == 0; } @@ -55,7 +56,8 @@ class Stg1 : public Strategy { class Stg2 : public Strategy { public: // Class constructor. - void Stg2(StgParams &_params, string _name = "") : Strategy(_params, trade_params_defaults, chart_params_defaults, _name) {} + void Stg2(StgParams &_params, string _name = "") + : Strategy(_params, trade_params_defaults, chart_params_defaults, _name) {} void OnInit() { ddata.Set(1, 1.1); fdata.Set(1, 1.1f); @@ -84,7 +86,7 @@ Strategy *strat2; */ int OnInit() { // Initial market tests. - assertTrueOrFail(SymbolInfo::GetAsk(_Symbol) > 0, "Invalid Ask price!"); + assertTrueOrFail(SymbolInfoStatic::GetAsk(_Symbol) > 0, "Invalid Ask price!"); /* Test 1st strategy. */ diff --git a/tests/SymbolInfoTest.mq5 b/tests/SymbolInfoTest.mq5 index ec7160d0a..ca84f524d 100644 --- a/tests/SymbolInfoTest.mq5 +++ b/tests/SymbolInfoTest.mq5 @@ -35,9 +35,8 @@ int OnInit() { SymbolInfo *si = new SymbolInfo(); // Symbol test. assertTrueOrFail(si.GetSymbol() == _Symbol, "Invalid class symbol!"); - assertTrueOrFail(si.GetCurrentSymbol() == _Symbol, "Invalid current chart symbol!"); // Tick test. - MqlTick stick = SymbolInfo::GetTick(_Symbol); + MqlTick stick = SymbolInfoStatic::GetTick(_Symbol); MqlTick dtick = si.GetTick(); MqlTick ltick = si.GetLastTick(); assertTrueOrFail(dtick.ask > 0 && dtick.ask == ltick.ask, "Invalid: Current Ask price"); @@ -56,66 +55,69 @@ int OnInit() { assertTrueOrFail(si.GetLastBid() == ltick.bid, "Invalid: GetLastBid()!"); assertTrueOrFail(si.GetLastVolume() == ltick.volume, "Invalid: GetLastVolume()!"); // Test prices. - assertTrueOrFail(si.GetAsk() == SymbolInfo::GetAsk(_Symbol), "Invalid: GetAsk()!"); - assertTrueOrFail(si.GetBid() == SymbolInfo::GetBid(_Symbol), "Invalid: GetBid()!"); - assertTrueOrFail(si.GetVolume() == SymbolInfo::GetVolume(_Symbol), "Invalid: GetVolume()!"); - assertTrueOrFail(si.GetSessionVolume() == SymbolInfo::GetSessionVolume(_Symbol), "Invalid: GetSessionVolume()!"); + assertTrueOrFail(si.GetAsk() == SymbolInfoStatic::GetAsk(_Symbol), "Invalid: GetAsk()!"); + assertTrueOrFail(si.GetBid() == SymbolInfoStatic::GetBid(_Symbol), "Invalid: GetBid()!"); + assertTrueOrFail(si.GetVolume() == SymbolInfoStatic::GetVolume(_Symbol), "Invalid: GetVolume()!"); + assertTrueOrFail(si.GetSessionVolume() == SymbolInfoStatic::GetSessionVolume(_Symbol), + "Invalid: GetSessionVolume()!"); // Test Ask/Bid open prices. - assertTrueOrFail(si.GetQuoteTime() > 0 && si.GetQuoteTime() == SymbolInfo::GetQuoteTime(_Symbol), + assertTrueOrFail(si.GetQuoteTime() > 0 && si.GetQuoteTime() == SymbolInfoStatic::GetQuoteTime(_Symbol), "Invalid: GetQuoteTime()!"); assertTrueOrFail(si.GetCloseOffer(ORDER_TYPE_BUY) == dtick.bid && - si.GetCloseOffer(ORDER_TYPE_BUY) == SymbolInfo::GetCloseOffer(_Symbol, ORDER_TYPE_BUY), + si.GetCloseOffer(ORDER_TYPE_BUY) == SymbolInfoStatic::GetCloseOffer(_Symbol, ORDER_TYPE_BUY), "Invalid: GetCloseOffer()!"); assertTrueOrFail(si.GetCloseOffer(ORDER_TYPE_SELL) == dtick.ask && - si.GetCloseOffer(ORDER_TYPE_SELL) == SymbolInfo::GetCloseOffer(_Symbol, ORDER_TYPE_SELL), + si.GetCloseOffer(ORDER_TYPE_SELL) == SymbolInfoStatic::GetCloseOffer(_Symbol, ORDER_TYPE_SELL), "Invalid: GetCloseOffer()!"); assertTrueOrFail(si.GetOpenOffer(ORDER_TYPE_BUY) == dtick.ask && - si.GetOpenOffer(ORDER_TYPE_BUY) == SymbolInfo::GetOpenOffer(_Symbol, ORDER_TYPE_BUY), + si.GetOpenOffer(ORDER_TYPE_BUY) == SymbolInfoStatic::GetOpenOffer(_Symbol, ORDER_TYPE_BUY), "Invalid: GetOpenOffer()!"); assertTrueOrFail(si.GetOpenOffer(ORDER_TYPE_SELL) == dtick.bid && - si.GetOpenOffer(ORDER_TYPE_SELL) == SymbolInfo::GetOpenOffer(_Symbol, ORDER_TYPE_SELL), + si.GetOpenOffer(ORDER_TYPE_SELL) == SymbolInfoStatic::GetOpenOffer(_Symbol, ORDER_TYPE_SELL), "Invalid: GetOpenOffer()!"); // Test point, pip and tick sizes. - assertTrueOrFail(si.GetPipSize() == SymbolInfo::GetPipSize(_Symbol), "Invalid: GetPipSize()!"); - assertTrueOrFail(si.GetPointSize() == SymbolInfo::GetPointSize(_Symbol), "Invalid: GetPointSize()!"); - assertTrueOrFail(si.GetTickSize() == SymbolInfo::GetTickSize(_Symbol), "Invalid: GetTickSize()!"); - assertTrueOrFail(si.GetTickValue() == SymbolInfo::GetTickValue(_Symbol), "Invalid: GetTickValue()!"); - assertTrueOrFail(si.GetTickValueLoss() == SymbolInfo::GetTickValueLoss(_Symbol), "Invalid: GetTickValueLoss()!"); - assertTrueOrFail(si.GetTickValueProfit() == SymbolInfo::GetTickValueProfit(_Symbol), + assertTrueOrFail(si.GetPipSize() == SymbolInfoStatic::GetPipSize(_Symbol), "Invalid: GetPipSize()!"); + assertTrueOrFail(si.GetPointSize() == SymbolInfoStatic::GetPointSize(_Symbol), "Invalid: GetPointSize()!"); + assertTrueOrFail(si.GetTickSize() == SymbolInfoStatic::GetTickSize(_Symbol), "Invalid: GetTickSize()!"); + assertTrueOrFail(si.GetTickValue() == SymbolInfoStatic::GetTickValue(_Symbol), "Invalid: GetTickValue()!"); + assertTrueOrFail(si.GetTickValueLoss() == SymbolInfoStatic::GetTickValueLoss(_Symbol), + "Invalid: GetTickValueLoss()!"); + assertTrueOrFail(si.GetTickValueProfit() == SymbolInfoStatic::GetTickValueProfit(_Symbol), "Invalid: GetTickValueProfit()!"); - assertTrueOrFail(si.GetTradeTickSize() == SymbolInfo::GetTradeTickSize(_Symbol), "Invalid: GetTradeTickSize()!"); + assertTrueOrFail(si.GetTradeTickSize() == SymbolInfoStatic::GetTradeTickSize(_Symbol), + "Invalid: GetTradeTickSize()!"); - assertTrueOrFail(si.GetPipDigits() > 0 && si.GetPipDigits() == SymbolInfo::GetPipDigits(_Symbol), + assertTrueOrFail(si.GetPipDigits() > 0 && si.GetPipDigits() == SymbolInfoStatic::GetPipDigits(_Symbol), "Invalid GetPipDigits()!"); // assertTrueOrFail(market.GetPipValue() > 0, "Invalid GetPipValue()!"); - assertTrueOrFail(si.GetSpreadInPts() >= 0 && si.GetSpreadInPts() == SymbolInfo::GetSpreadInPts(_Symbol), + assertTrueOrFail(si.GetSpreadInPts() >= 0 && si.GetSpreadInPts() == SymbolInfoStatic::GetSpreadInPts(_Symbol), "Invalid GetSpreadInPts()!"); - assertTrueOrFail(si.GetSpreadInPct() >= 0 && si.GetSpreadInPct() == SymbolInfo::GetSpreadInPct(_Symbol), + assertTrueOrFail(si.GetSpreadInPct() >= 0 && si.GetSpreadInPct() == SymbolInfoStatic::GetSpreadInPct(_Symbol), "Invalid GetSpreadInPct()!"); - assertTrueOrFail(si.GetPointsPerPip() > 0 && si.GetPointsPerPip() == SymbolInfo::GetPointsPerPip(_Symbol), + assertTrueOrFail(si.GetPointsPerPip() > 0 && si.GetPointsPerPip() == SymbolInfoStatic::GetPointsPerPip(_Symbol), "Invalid GetPointsPerPip()!"); - assertTrueOrFail(si.GetVolumeDigits() > 0 && si.GetVolumeDigits() == SymbolInfo::GetVolumeDigits(_Symbol), + assertTrueOrFail(si.GetVolumeDigits() > 0 && si.GetVolumeDigits() == SymbolInfoStatic::GetVolumeDigits(_Symbol), "Invalid GetVolumeDigits()!"); // Test digits, spreads and trade stops. - assertTrueOrFail(si.GetDigits() == SymbolInfo::GetDigits(_Symbol), "Invalid: GetDigits()!"); - assertTrueOrFail(si.GetRealSpread() == SymbolInfo::GetRealSpread(_Symbol), "Invalid: GetRealSpread()!"); - assertTrueOrFail(si.GetSpread() == SymbolInfo::GetSpread(_Symbol), "Invalid: GetSpread()!"); - assertTrueOrFail(si.GetTradeContractSize() == SymbolInfo::GetTradeContractSize(_Symbol), + assertTrueOrFail(si.GetDigits() == SymbolInfoStatic::GetDigits(_Symbol), "Invalid: GetDigits()!"); + assertTrueOrFail(si.GetRealSpread() == SymbolInfoStatic::GetRealSpread(_Symbol), "Invalid: GetRealSpread()!"); + assertTrueOrFail(si.GetSpread() == SymbolInfoStatic::GetSpread(_Symbol), "Invalid: GetSpread()!"); + assertTrueOrFail(si.GetTradeContractSize() == SymbolInfoStatic::GetTradeContractSize(_Symbol), "Invalid: GetTradeContractSize()!"); - assertTrueOrFail(si.GetTradeStopsLevel() == SymbolInfo::GetTradeStopsLevel(_Symbol), + assertTrueOrFail(si.GetTradeStopsLevel() == SymbolInfoStatic::GetTradeStopsLevel(_Symbol), "Invalid: GetTradeStopsLevel()!"); // Test volumes. - assertTrueOrFail(si.GetVolumeMax() == SymbolInfo::GetVolumeMax(_Symbol), "Invalid: GetVolumeMax()!"); - assertTrueOrFail(si.GetVolumeMin() == SymbolInfo::GetVolumeMin(_Symbol), "Invalid: GetVolumeMin()!"); - assertTrueOrFail(si.GetVolumeStep() == SymbolInfo::GetVolumeStep(_Symbol), "Invalid: GetVolumeStep()!"); + assertTrueOrFail(si.GetVolumeMax() == SymbolInfoStatic::GetVolumeMax(_Symbol), "Invalid: GetVolumeMax()!"); + assertTrueOrFail(si.GetVolumeMin() == SymbolInfoStatic::GetVolumeMin(_Symbol), "Invalid: GetVolumeMin()!"); + assertTrueOrFail(si.GetVolumeStep() == SymbolInfoStatic::GetVolumeStep(_Symbol), "Invalid: GetVolumeStep()!"); // Test freeze level. - assertTrueOrFail(si.GetFreezeLevel() == SymbolInfo::GetFreezeLevel(_Symbol), "Invalid: GetFreezeLevel()!"); + assertTrueOrFail(si.GetFreezeLevel() == SymbolInfoStatic::GetFreezeLevel(_Symbol), "Invalid: GetFreezeLevel()!"); // Test swap and margin values. - assertTrueOrFail(si.GetSwapLong() == SymbolInfo::GetSwapLong(_Symbol), "Invalid: GetSwapLong()!"); - assertTrueOrFail(si.GetSwapShort() == SymbolInfo::GetSwapShort(_Symbol), "Invalid: GetSwapShort()!"); - assertTrueOrFail(si.GetMarginInit() == SymbolInfo::GetMarginInit(_Symbol), "Invalid: GetMarginInit()!"); - assertTrueOrFail(si.GetMarginMaintenance() == SymbolInfo::GetMarginMaintenance(_Symbol), + assertTrueOrFail(si.GetSwapLong() == SymbolInfoStatic::GetSwapLong(_Symbol), "Invalid: GetSwapLong()!"); + assertTrueOrFail(si.GetSwapShort() == SymbolInfoStatic::GetSwapShort(_Symbol), "Invalid: GetSwapShort()!"); + assertTrueOrFail(si.GetMarginInit() == SymbolInfoStatic::GetMarginInit(_Symbol), "Invalid: GetMarginInit()!"); + assertTrueOrFail(si.GetMarginMaintenance() == SymbolInfoStatic::GetMarginMaintenance(_Symbol), "Invalid: GetMarginMaintenance()!"); // Test saving ticks. si.SaveTick(dtick); @@ -126,8 +128,8 @@ int OnInit() { assertTrueOrFail(_entry.bid == dtick.bid, __FUNCTION_LINE__); assertTrueOrFail(_entry.ask == dtick.ask, __FUNCTION_LINE__); assertTrueOrFail(_entry.last == dtick.last, __FUNCTION_LINE__); - assertTrueOrFail(_entry.spread == SymbolInfo::GetSpread(_Symbol), __FUNCTION_LINE__); - assertTrueOrFail(_entry.volume == SymbolInfo::GetVolume(_Symbol), __FUNCTION_LINE__); + assertTrueOrFail(_entry.spread == SymbolInfoStatic::GetSpread(_Symbol), __FUNCTION_LINE__); + assertTrueOrFail(_entry.volume == SymbolInfoStatic::GetVolume(_Symbol), __FUNCTION_LINE__); // Print. Print("MARKET: ", si.ToString()); Print("CSV (Header): ", si.ToCSV(true)); diff --git a/tests/TradeTest.mq5 b/tests/TradeTest.mq5 index 02155973e..602511625 100644 --- a/tests/TradeTest.mq5 +++ b/tests/TradeTest.mq5 @@ -36,7 +36,7 @@ struct DataParamEntry; */ int OnInit() { // Initial market tests. - assertTrueOrFail(SymbolInfo::GetAsk(_Symbol) > 0, "Invalid Ask price!"); + assertTrueOrFail(SymbolInfoStatic::GetAsk(_Symbol) > 0, "Invalid Ask price!"); // Test 1. ChartParams _cparams_m1(PERIOD_M1, _Symbol); @@ -53,11 +53,11 @@ int OnInit() { assertTrueOrFail( trade1.GetTradeDistanceInPts() >= 0 && trade1.GetTradeDistanceInPts() == Trade::GetTradeDistanceInPts(_Symbol), "Invalid GetTradeDistanceInPts()!"); - assertTrueOrFail(trade1.GetTradeDistanceInPips() >= 0 && - trade1.GetTradeDistanceInPips() == Trade::GetTradeDistanceInPips(_Symbol), - "Invalid GetTradeDistanceInPips()!"); + assertTrueOrFail( + trade1.GetTradeDistanceInPips() >= 0 && trade1.GetTradeDistanceInPips() == Trade::GetTradeDistanceInPips(_Symbol), + "Invalid GetTradeDistanceInPips()!"); assertTrueOrFail(trade1.GetTradeDistanceInValue() >= 0 && - (float) trade1.GetTradeDistanceInValue() == (float) Trade::GetTradeDistanceInValue(_Symbol), + (float)trade1.GetTradeDistanceInValue() == (float)Trade::GetTradeDistanceInValue(_Symbol), "Invalid GetTradeDistanceInValue()!"); Print("Trade1: ", trade1.ToString()); // Clean up.