diff --git a/DateTime.extern.h b/DateTime.extern.h index 1ffb17098..2f3bd3526 100644 --- a/DateTime.extern.h +++ b/DateTime.extern.h @@ -44,7 +44,7 @@ class datetime { public: datetime() { dt = 0; } - datetime(const long& _time) { dt = _time; } + datetime(const int64& _time) { dt = _time; } // datetime(const int& _time); bool operator==(const int _time) const = delete; bool operator==(const datetime& _time) const { return dt == _time; } @@ -52,7 +52,7 @@ class datetime { bool operator>(const int _time) const = delete; bool operator<(const datetime& _time) const { return dt < _time; } bool operator>(const datetime& _time) const { return dt > _time; } - operator long() const { return dt; } + operator int64() const { return dt; } }; extern int CopyTime(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, @@ -71,16 +71,7 @@ extern datetime TimeGMT(MqlDateTime& dt_struct); extern datetime TimeTradeServer(); extern datetime TimeTradeServer(MqlDateTime& dt_struct); extern datetime StringToTime(const string& value); -string TimeToString(datetime value, int mode = TIME_DATE | TIME_MINUTES) { - /* - auto now = std::chrono::time_point(); - auto in_time_t = std::chrono::system_clock::to_time_t(now); - */ - std::stringstream ss; - ss << __FUNCTION__ << " is not yet implemented!"; - // ss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d %X"); - return ss.str(); -} +extern string TimeToString(datetime value, int mode = TIME_DATE | TIME_MINUTES); template datetime operator"" _D(); diff --git a/DictBase.mqh b/DictBase.mqh index 413894115..2d99174c2 100644 --- a/DictBase.mqh +++ b/DictBase.mqh @@ -61,6 +61,7 @@ class DictBase { _current_id = 0; _mode = DictModeUnknown; _flags = 0; + overflow_listener = nullptr; } /** diff --git a/Indicator/Indicator.h b/Indicator/Indicator.h index 6f84b10e8..1083523a8 100644 --- a/Indicator/Indicator.h +++ b/Indicator/Indicator.h @@ -116,6 +116,7 @@ class Indicator : public IndicatorData { : IndicatorData(IndicatorDataParams::GetInstance()) { iparams.SetIndicatorType(_itype); iparams.SetShift(_shift); + SetName(_name); Init(); } diff --git a/Indicator/IndicatorCandle.h b/Indicator/IndicatorCandle.h index 0f6c70ea6..d9fe084a2 100644 --- a/Indicator/IndicatorCandle.h +++ b/Indicator/IndicatorCandle.h @@ -94,7 +94,7 @@ class IndicatorCandle : public Indicator { /** * Class constructor. */ - IndicatorCandle(const TS& _icparams, const IndicatorDataParams& _idparams, IndicatorBase* _indi_src = NULL, + IndicatorCandle(const TS& _icparams, const IndicatorDataParams& _idparams, IndicatorData* _indi_src = NULL, int _indi_mode = 0) : Indicator(_icparams, _idparams, _indi_src, _indi_mode), history(INDI_CANDLE_HISTORY_SIZE) { Init(); diff --git a/Indicator/IndicatorTf.h b/Indicator/IndicatorTf.h index 69f319706..9f0aea621 100644 --- a/Indicator/IndicatorTf.h +++ b/Indicator/IndicatorTf.h @@ -59,34 +59,20 @@ class IndicatorTf : public IndicatorCandle { public: - IndicatorTfDummy(unsigned int _spc) : IndicatorTf(_spc) {} - IndicatorTfDummy(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorTf(_tf) {} - IndicatorTfDummy(ENUM_TIMEFRAMES_INDEX _tfi = (ENUM_TIMEFRAMES_INDEX)0) : IndicatorTf(_tfi) {} + /* + @todo - string GetName() override { return "IndicatorTfDummy(" + IntegerToString(iparams.spc) + ")"; } + IndicatorTfDummy(unsigned int _spc) : IndicatorTf(_spc) {} + */ + + IndicatorTfDummy(ENUM_TIMEFRAMES _tf) : IndicatorTf(IndicatorTfDummyParams(_tf), IndicatorDataParams()) {} + IndicatorTfDummy(ENUM_TIMEFRAMES_INDEX _tfi) + : IndicatorTf(IndicatorTfDummyParams(ChartTf::IndexToTf(_tfi)), IndicatorDataParams()) {} + + string GetName() override { return "IndicatorTfDummy(" + iparams.tf.GetString() + ")"; } void OnDataSourceEntry(IndicatorDataEntry& entry) override { // When overriding OnDataSourceEntry() we have to remember to call parent diff --git a/Indicators/Tick/Indi_TickProvider.h b/Indicators/Tick/Indi_TickProvider.h index 4f1f531b2..84fdf5439 100644 --- a/Indicators/Tick/Indi_TickProvider.h +++ b/Indicators/Tick/Indi_TickProvider.h @@ -64,7 +64,10 @@ class Indi_TickProvider : public IndicatorTick. + * + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Defines. +#define PLATFORM_WRONG_SYMBOL "" +#define PLATFORM_WRONG_TIMEFRAME ((ENUM_TIMEFRAMES)INT_MAX) diff --git a/Platform.extern.h b/Platform.extern.h index fabde3d0b..11edea715 100644 --- a/Platform.extern.h +++ b/Platform.extern.h @@ -67,9 +67,9 @@ extern int CopyLow(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, extern int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, ARRAY_REF(double, close_array)); -extern unsigned long PositionGetTicket(int _index); +extern unsigned int64 PositionGetTicket(int _index); -extern long PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id); +extern int64 PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id); extern double PositionGetDouble(ENUM_POSITION_PROPERTY_DOUBLE property_id); @@ -77,13 +77,13 @@ extern string PositionGetString(ENUM_POSITION_PROPERTY_STRING property_id); extern int HistoryDealsTotal(); -extern unsigned long HistoryDealGetTicket(int index); +extern unsigned int64 HistoryDealGetTicket(int index); -extern long HistoryDealGetInteger(unsigned long ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id); +extern int64 HistoryDealGetInteger(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id); -extern double HistoryDealGetDouble(unsigned long ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id); +extern double HistoryDealGetDouble(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id); -extern string HistoryDealGetString(unsigned long ticket_number, ENUM_DEAL_PROPERTY_STRING property_id); +extern string HistoryDealGetString(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_STRING property_id); extern bool OrderSelect(int index); @@ -95,25 +95,25 @@ extern bool OrderSend(const MqlTradeRequest& request, MqlTradeResult& result); extern bool OrderCheck(const MqlTradeRequest& request, MqlTradeCheckResult& result); -extern unsigned long OrderGetTicket(int index); +extern unsigned int64 OrderGetTicket(int index); -extern unsigned long HistoryOrderGetTicket(int index); +extern unsigned int64 HistoryOrderGetTicket(int index); -extern bool HistorySelectByPosition(long position_id); +extern bool HistorySelectByPosition(int64 position_id); -extern bool HistoryDealSelect(unsigned long ticket); +extern bool HistoryDealSelect(unsigned int64 ticket); -extern long OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id); +extern int64 OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id); -extern long HistoryOrderGetInteger(unsigned long ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id); +extern int64 HistoryOrderGetInteger(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id); extern double OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE property_id); -extern double HistoryOrderGetDouble(unsigned long ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id); +extern double HistoryOrderGetDouble(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id); string OrderGetString(ENUM_ORDER_PROPERTY_STRING property_id); -string HistoryOrderGetString(unsigned long ticket_number, ENUM_ORDER_PROPERTY_STRING property_id); +string HistoryOrderGetString(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_STRING property_id); extern int PositionsTotal(); @@ -124,10 +124,10 @@ extern int HistoryOrdersTotal(); extern int OrdersTotal(); extern int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, - ARRAY_REF(long, arr)); + ARRAY_REF(int64, arr)); extern int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, - ARRAY_REF(long, arr)); + ARRAY_REF(int64, arr)); extern int ChartID(); @@ -135,38 +135,38 @@ extern bool OrderCalcMargin(ENUM_ORDER_TYPE _action, string _symbol, double _vol extern double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE property_id); -extern long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property_id); +extern int64 AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property_id); extern string AccountInfoInteger(ENUM_ACCOUNT_INFO_STRING property_id); extern string Symbol(); -extern string ObjectName(long _chart_id, int _pos, int _sub_window = -1, int _type = -1); +extern string ObjectName(int64 _chart_id, int _pos, int _sub_window = -1, int _type = -1); -extern int ObjectsTotal(long chart_id, int type = EMPTY, int window = -1); +extern int ObjectsTotal(int64 chart_id, int type = EMPTY, int window = -1); extern bool PlotIndexSetString(int plot_index, int prop_id, string prop_value); extern bool PlotIndexSetInteger(int plot_index, int prop_id, int prop_value); -extern bool ObjectSetInteger(long chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, long prop_value); +extern bool ObjectSetInteger(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, int64 prop_value); -extern bool ObjectSetInteger(long chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, int prop_modifier, - long prop_value); +extern bool ObjectSetInteger(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, int prop_modifier, + int64 prop_value); -extern bool ObjectSetDouble(long chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, double prop_value); +extern bool ObjectSetDouble(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, double prop_value); -extern bool ObjectSetDouble(long chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, int prop_modifier, +extern bool ObjectSetDouble(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, int prop_modifier, double prop_value); -extern bool ObjectCreate(long _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1); -extern bool ObjectCreate(long _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1, +extern bool ObjectCreate(int64 _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1); +extern bool ObjectCreate(int64 _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1, datetime _t2, double _p2); -extern bool ObjectMove(long chart_id, string name, int point_index, datetime time, double price); +extern bool ObjectMove(int64 chart_id, string name, int point_index, datetime time, double price); -extern bool ObjectDelete(long chart_id, string name); +extern bool ObjectDelete(int64 chart_id, string name); -extern int ObjectFind(long chart_id, string name); +extern int ObjectFind(int64 chart_id, string name); #endif diff --git a/Platform.h b/Platform.h index 703278ab1..9e4af58c7 100644 --- a/Platform.h +++ b/Platform.h @@ -27,6 +27,7 @@ // Includes. #include "Deal.enum.h" #include "Order.struct.h" +#include "Platform.define.h" /** * Extern declarations for C++. @@ -85,6 +86,12 @@ class Platform { // Result of the last tick. static bool last_tick_result; + // Symbol of the currently ticking indicator. + static string symbol; + + // Timeframe of the currently ticking indicator. + static ENUM_TIMEFRAMES period; + public: /** * Initializes platform. @@ -96,9 +103,6 @@ class Platform { } initialized = true; - - // Starting from current timestamp. - time.Update(); } /** @@ -110,6 +114,10 @@ class Platform { * Performs tick on every added indicator. */ static void Tick() { + // @todo Should update time for each ticking indicator and only when it signal a tick. + PlatformTime::Tick(); + time.Update(); + // Checking starting periods and updating time to current one. time_flags = time.GetStartedPeriods(); time.Update(); @@ -119,13 +127,37 @@ class Platform { last_tick_result = false; for (_iter = indis.Begin(); _iter.IsValid(); ++_iter) { + // Updating current symbol and timeframe to the ones used by ticking indicator and its parents. + symbol = _iter.Value() REF_DEREF GetSymbol(); + period = _iter.Value() REF_DEREF GetTf(); + +#ifdef __debug__ + PrintFormat("Tick #%d for %s for symbol %s and period %s", global_tick_index, + C_STR(_iter.Value() REF_DEREF GetFullName()), C_STR(symbol), C_STR(ChartTf::TfToString(period))); +#endif + last_tick_result |= _iter.Value() REF_DEREF Tick(global_tick_index); } for (_iter = indis_dflt.Begin(); _iter.IsValid(); ++_iter) { + // Updating current symbol and timeframe to the ones used by ticking indicator and its parents. + symbol = (_iter.Value() REF_DEREF GetTick(false) != nullptr) ? _iter.Value() REF_DEREF GetSymbol() + : PLATFORM_WRONG_SYMBOL; + period = (_iter.Value() REF_DEREF GetCandle(false) != nullptr) ? _iter.Value() REF_DEREF GetTf() + : PLATFORM_WRONG_TIMEFRAME; + +#ifdef __debug__ + PrintFormat("Tick #%d for %s for symbol %s and period %s", global_tick_index, + C_STR(_iter.Value() REF_DEREF GetFullName()), C_STR(symbol), C_STR(ChartTf::TfToString(period))); +#endif + last_tick_result |= _iter.Value() REF_DEREF Tick(global_tick_index); } + // Clearing symbol and period in order to signal retrieving symbol/period outside the ticking indicator. + symbol = PLATFORM_WRONG_SYMBOL; + period = PLATFORM_WRONG_TIMEFRAME; + // Will check for new time periods in consecutive Platform::UpdateTime(). time_clear_flags = true; @@ -280,13 +312,13 @@ class Platform { /** * Returns default Candle-compatible indicator for current platform for given symbol and TF. */ - static IndicatorData *FetchDefaultCandleIndicator(string _symbol = "", ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) { - if (_symbol == "") { - _symbol = _Symbol; + static IndicatorData *FetchDefaultCandleIndicator(string _symbol, ENUM_TIMEFRAMES _tf) { + if (_symbol == PLATFORM_WRONG_SYMBOL) { + RUNTIME_ERROR("Cannot fetch default candle indicator for unknown symbol!"); } - if (_tf == PERIOD_CURRENT) { - _tf = (ENUM_TIMEFRAMES)Period(); + if (_tf == PERIOD_CURRENT || _tf == PLATFORM_WRONG_TIMEFRAME) { + RUNTIME_ERROR("Cannot fetch default candle indicator for unknown period/timeframe!"); } // Candle is per symbol and TF. Single Candle indicator can't handle multiple TFs. @@ -311,9 +343,9 @@ class Platform { /** * Returns default Tick-compatible indicator for current platform for given symbol. */ - static IndicatorData *FetchDefaultTickIndicator(string _symbol = "") { - if (_symbol == "") { - _symbol = _Symbol; + static IndicatorData *FetchDefaultTickIndicator(string _symbol) { + if (_symbol == PLATFORM_WRONG_SYMBOL) { + RUNTIME_ERROR("Cannot fetch default tick indicator for unknown symbol!"); } string _key = Util::MakeKey("PlatformIndicatorTick", _symbol); @@ -366,6 +398,39 @@ class Platform { } return _result; } + + /** + * Returns symbol of the currently ticking indicator. + **/ + static string GetSymbol() { + if (symbol == PLATFORM_WRONG_SYMBOL) { + RUNTIME_ERROR("Retrieving symbol outside the OnTick() of the currently ticking indicator is prohibited!"); + } + return symbol; + } + + /** + * Returns timeframe of the currently ticking indicator. + **/ + static ENUM_TIMEFRAMES GetPeriod() { + if (period == PLATFORM_WRONG_TIMEFRAME) { + RUNTIME_ERROR( + "Retrieving period/timeframe outside the OnTick() of the currently ticking indicator is prohibited!"); + } + + return period; + } + + private: + /** + * Sets symbol of the currently ticking indicator. + **/ + static void SetSymbol(string _symbol) { symbol = _symbol; } + + /** + * Sets timeframe of the currently ticking indicator. + **/ + static void SetPeriod(ENUM_TIMEFRAMES _period) { period = _period; } }; bool Platform::initialized = false; @@ -374,6 +439,8 @@ DateTime Platform::time = (datetime)0; unsigned int Platform::time_flags = 0; bool Platform::time_clear_flags = true; int Platform::global_tick_index = 0; +string Platform::symbol = PLATFORM_WRONG_SYMBOL; +ENUM_TIMEFRAMES Platform::period = PLATFORM_WRONG_TIMEFRAME; DictStruct> Platform::indis; DictStruct> Platform::indis_dflt; @@ -399,12 +466,12 @@ int CopyBuffer(int indicator_handle, int buffer_num, int start_pos, int count, A return 0; } -unsigned long PositionGetTicket(int _index) { +unsigned int64 PositionGetTicket(int _index) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -long PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id) { +int64 PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -424,22 +491,22 @@ int HistoryDealsTotal() { return 0; } -unsigned long HistoryDealGetTicket(int index) { +unsigned int64 HistoryDealGetTicket(int index) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -long HistoryDealGetInteger(unsigned long ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id) { +int64 HistoryDealGetInteger(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -double HistoryDealGetDouble(unsigned long ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id) { +double HistoryDealGetDouble(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -string HistoryDealGetString(unsigned long ticket_number, ENUM_DEAL_PROPERTY_STRING property_id) { +string HistoryDealGetString(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_STRING property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns empty string."); return 0; } @@ -469,32 +536,32 @@ bool OrderCheck(const MqlTradeRequest &request, MqlTradeCheckResult &result) { return false; } -unsigned long OrderGetTicket(int index) { +unsigned int64 OrderGetTicket(int index) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -unsigned long HistoryOrderGetTicket(int index) { +unsigned int64 HistoryOrderGetTicket(int index) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -bool HistorySelectByPosition(long position_id) { +bool HistorySelectByPosition(int64 position_id) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } -bool HistoryDealSelect(unsigned long ticket) { +bool HistoryDealSelect(unsigned int64 ticket) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } -long OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id) { +int64 OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -long HistoryOrderGetInteger(unsigned long ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id) { +int64 HistoryOrderGetInteger(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -504,7 +571,7 @@ double OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE property_id) { return 0; } -double HistoryOrderGetDouble(unsigned long ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id) { +double HistoryOrderGetDouble(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -514,7 +581,7 @@ string OrderGetString(ENUM_ORDER_PROPERTY_STRING property_id) { return 0; } -string HistoryOrderGetString(unsigned long ticket_number, ENUM_ORDER_PROPERTY_STRING property_id) { +string HistoryOrderGetString(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_STRING property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns empty string."); return 0; } @@ -559,12 +626,12 @@ int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int return 0; } -int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, ARRAY_REF(long, arr)) { +int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, ARRAY_REF(int64, arr)) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, ARRAY_REF(long, arr)) { +int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, ARRAY_REF(int64, arr)) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -581,7 +648,7 @@ double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE property_id) { return false; } -long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property_id) { +int64 AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return false; } @@ -596,12 +663,12 @@ string Symbol() { return ""; } -string ObjectName(long _chart_id, int _pos, int _sub_window, int _type) { +string ObjectName(int64 _chart_id, int _pos, int _sub_window, int _type) { Print("Not yet implemented: ", __FUNCTION__, " returns empty string."); return ""; } -int ObjectsTotal(long chart_id, int type, int window) { +int ObjectsTotal(int64 chart_id, int type, int window) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -616,45 +683,45 @@ bool PlotIndexSetInteger(int plot_index, int prop_id, int prop_value) { return false; } -bool ObjectSetInteger(long chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, long prop_value) { +bool ObjectSetInteger(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, int64 prop_value) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } -bool ObjectSetInteger(long chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, int prop_modifier, - long prop_value) { +bool ObjectSetInteger(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, int prop_modifier, + int64 prop_value) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } -bool ObjectSetDouble(long chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, double prop_value) { +bool ObjectSetDouble(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, double prop_value) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } -bool ObjectSetDouble(long chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, int prop_modifier, +bool ObjectSetDouble(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, int prop_modifier, double prop_value) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } -bool ObjectCreate(long _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1) { +bool ObjectCreate(int64 _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } -bool ObjectCreate(long _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1, datetime _t2, +bool ObjectCreate(int64 _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1, datetime _t2, double _p2) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } -bool ObjectMove(long chart_id, string name, int point_index, datetime time, double price) { +bool ObjectMove(int64 chart_id, string name, int point_index, datetime time, double price) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } -bool ObjectDelete(long chart_id, string name) { +bool ObjectDelete(int64 chart_id, string name) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } @@ -663,29 +730,77 @@ int GetLastError() { return _LastError; } void ResetLastError() { _LastError = 0; } -int ObjectFind(long chart_id, string name) { +int ObjectFind(int64 chart_id, string name) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -bool TimeToStruct(datetime dt, MqlDateTime &dt_struct) { - Print("Not yet implemented: ", __FUNCTION__, " returns false."); - return false; -} +string TimeToString(datetime value, int mode) { + static std::stringstream ss; + ss.clear(); + ss.str(""); -SymbolGetter::operator string() { - Print("Not yet implemented: ", __FUNCTION__, " returns empty string."); - return ""; + std::time_t time = value; + std::tm *ptm = std::localtime(&time); + char date[16], minutes[16], seconds[16]; + std::strftime(date, 32, "%Y.%m.%d", ptm); + std::strftime(minutes, 32, "%H:%M", ptm); + std::strftime(seconds, 32, "%S", ptm); + + if (mode | TIME_DATE) ss << date; + + if (mode | TIME_MINUTES) { + if (mode | TIME_DATE) { + ss << " "; + } + ss << minutes; + } + + if (mode | TIME_SECONDS) { + if (mode | TIME_DATE && !(mode | TIME_MINUTES)) { + ss << " "; + } else if (mode | TIME_MINUTES) { + ss << ":"; + } + ss << seconds; + } + + return ss.str(); } -ENUM_TIMEFRAMES Period() { - Print("Not yet implemented: ", __FUNCTION__, " returns 0."); - return (ENUM_TIMEFRAMES)0; +bool TimeToStruct(datetime dt, MqlDateTime &dt_struct) { + time_t now = (time_t)dt; + + tm *ltm = localtime(&now); + + dt_struct.day = ltm->tm_mday; + dt_struct.day_of_week = ltm->tm_wday; + dt_struct.day_of_year = ltm->tm_yday; + dt_struct.hour = ltm->tm_hour; + dt_struct.min = ltm->tm_min; + dt_struct.mon = ltm->tm_mon; + dt_struct.sec = ltm->tm_sec; + dt_struct.year = ltm->tm_year; + + return true; } +SymbolGetter::operator string() { return Platform::GetSymbol(); } + +ENUM_TIMEFRAMES Period() { return Platform::GetPeriod(); } + datetime StructToTime(MqlDateTime &dt_struct) { - Print("Not yet implemented: ", __FUNCTION__, " returns empty datetime (0)."); - return (datetime)0; + tm ltm; + ltm.tm_mday = dt_struct.day; + ltm.tm_wday = dt_struct.day_of_week; + ltm.tm_yday = dt_struct.day_of_year; + ltm.tm_hour = dt_struct.hour; + ltm.tm_min = dt_struct.min; + ltm.tm_mon = dt_struct.mon; + ltm.tm_sec = dt_struct.sec; + ltm.tm_year = dt_struct.year; + + return mktime(<m); } #endif diff --git a/PlatformTime.h b/PlatformTime.h index 6b54aeffb..b67cc43dc 100644 --- a/PlatformTime.h +++ b/PlatformTime.h @@ -39,21 +39,21 @@ class PlatformTime { static MqlDateTime current_time; - static long current_timestamp_s; - static long current_timestamp_ms; + static int64 current_timestamp_s; + static int64 current_timestamp_ms; public: - static long CurrentTimestamp() { return current_timestamp_s; } - static long CurrentTimestampMs() { return current_timestamp_ms; } + static int64 CurrentTimestamp() { return current_timestamp_s; } + static int64 CurrentTimestampMs() { return current_timestamp_ms; } static MqlDateTime CurrentTime() { return current_time; } void static Tick() { #ifdef __MQL__ - static long _last_timestamp_ms = 0; + static int64 _last_timestamp_ms = 0; current_timestamp_s = ::TimeCurrent(current_time); - current_timestamp_ms = (long)GetTickCount(); + current_timestamp_ms = (int64)GetTickCount(); if (_last_timestamp_ms != 0 && current_timestamp_ms < _last_timestamp_ms) { // Overflow occured (49.7 days passed). @@ -64,11 +64,11 @@ class PlatformTime { _last_timestamp_ms = current_timestamp_ms; #else using namespace std::chrono; - current_timestamp_s = (long)duration_cast(system_clock::now().time_since_epoch()).count(); - current_timestamp_ms = (long)duration_cast(system_clock::now().time_since_epoch()).count(); + current_timestamp_s = (int64)duration_cast(system_clock::now().time_since_epoch()).count(); + current_timestamp_ms = (int64)duration_cast(system_clock::now().time_since_epoch()).count(); using namespace std::chrono; - std::time_t t = std::time(0); + std::time_t t = current_timestamp_s; std::tm* now = std::localtime(&t); current_time.day = now->tm_mday; current_time.day_of_week = now->tm_wday; @@ -83,5 +83,5 @@ class PlatformTime { }; MqlDateTime PlatformTime::current_time = {0, 0, 0, 0, 0, 0, 0, 0}; -long PlatformTime::current_timestamp_s = 0; -long PlatformTime::current_timestamp_ms = 0; +int64 PlatformTime::current_timestamp_s = 0; +int64 PlatformTime::current_timestamp_ms = 0; diff --git a/Serializer/SerializerConverter.h b/Serializer/SerializerConverter.h index 350cf0763..8774f5f95 100644 --- a/Serializer/SerializerConverter.h +++ b/Serializer/SerializerConverter.h @@ -39,7 +39,7 @@ class SerializerNode; #include "SerializerDict.h" #include "SerializerNode.h" -#ifdef __debug__ +#ifdef __debug_verbose__ #include "SerializerJson.h" #endif @@ -72,7 +72,7 @@ class SerializerConverter { _serializer.FreeRootNodeOwnership(); _serializer.PassObject(_value, "", _value, SERIALIZER_FIELD_FLAG_VISIBLE); SerializerConverter _converter(_serializer.GetRoot(), serializer_flags); -#ifdef __debug__ +#ifdef __debug_verbose__ Print("FromObject(): serializer flags: ", serializer_flags); Print("FromObject(): result: ", _serializer.GetRoot() != NULL ? _serializer.GetRoot() PTR_DEREF ToString(SERIALIZER_JSON_NO_WHITESPACES) @@ -87,7 +87,7 @@ class SerializerConverter { _serializer.FreeRootNodeOwnership(); _serializer.PassObject(_value, "", _value, SERIALIZER_FIELD_FLAG_VISIBLE); SerializerConverter _converter(_serializer.GetRoot(), serializer_flags); -#ifdef __debug__ +#ifdef __debug_verbose__ Print("FromObject(): serializer flags: ", serializer_flags); Print("FromObject(): result: ", _serializer.GetRoot() != NULL ? _serializer.GetRoot() PTR_DEREF ToString(SERIALIZER_JSON_NO_WHITESPACES) @@ -119,7 +119,7 @@ class SerializerConverter { template static SerializerConverter FromString(string arg) { SerializerConverter _converter(((C*)NULL)PTR_DEREF Parse(arg), 0); -#ifdef __debug__ +#ifdef __debug_verbose__ Print("FromString(): result: ", _converter.Node() != NULL ? _converter.Node() PTR_DEREF ToString(SERIALIZER_JSON_NO_WHITESPACES) : "NULL"); #endif diff --git a/Serializer/SerializerCsv.h b/Serializer/SerializerCsv.h index 47d6f2c03..3390865ba 100644 --- a/Serializer/SerializerCsv.h +++ b/Serializer/SerializerCsv.h @@ -114,7 +114,7 @@ class SerializerCsv { } } -#ifdef __debug__ +#ifdef __debug_verbose__ Print("Stub: ", _stub PTR_DEREF Node() PTR_DEREF ToString()); Print("Data: ", _root PTR_DEREF ToString()); Print("Size: ", _num_columns, " x ", _num_rows); diff --git a/Std.h b/Std.h index 190ad3af6..13ffe0869 100644 --- a/Std.h +++ b/Std.h @@ -56,6 +56,7 @@ #define MAKE_REF_FROM_PTR(TYPE, NAME, PTR) TYPE* NAME = PTR #define nullptr NULL #define REF_DEREF .Ptr(). +#define int64 long #else #define THIS_ATTR this-> #define THIS_PTR (this) @@ -66,6 +67,7 @@ #define PTR_TO_REF(PTR) (*PTR) #define MAKE_REF_FROM_PTR(TYPE, NAME, PTR) TYPE& NAME = PTR #define REF_DEREF .Ptr()-> +#define int64 long long #endif // References. diff --git a/Tick/Tick.struct.h b/Tick/Tick.struct.h index 4493d31ce..708f4fc3c 100644 --- a/Tick/Tick.struct.h +++ b/Tick/Tick.struct.h @@ -40,14 +40,14 @@ * 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. + 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. + int64 time_msc; // Time of a price last update in milliseconds. + unsigned int flags; // Tick flags. + unsigned int64 volume; // Volume for the current last price. // Default constructor. MqlTick() {} @@ -84,26 +84,26 @@ struct DoubleTickAB : TickAB {}; */ template struct TickTAB : TickAB { - long time_ms; // Time of the last prices update. + int64 time_ms; // Time of the last prices update. // Struct constructors. - TickTAB(long _time_ms = 0, T _ask = 0, T _bid = 0) : TickAB(_ask, _bid), time_ms(_time_ms) {} + TickTAB(int64 _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. */ - long GetTimeMs() { return time_ms; } + int64 GetTimeMs() { return time_ms; } /** * Returns time as timestamp (in seconds). */ - long GetTimestamp() { return time_ms; } + int64 GetTimestamp() { return time_ms / 1000; } /** * Method used by ItemsHistory. */ - long GetLengthMs() { + int64 GetLengthMs() { // Ticks have length of 0ms, so next tick could be at least 1ms after the previous tick. return 0; }