From 9dc53b29b1cf953381f74ed70fce477ad6f9c0d4 Mon Sep 17 00:00:00 2001 From: kenorb Date: Thu, 5 Mar 2020 11:22:44 +0000 Subject: [PATCH 1/6] BufferFXT: Adds initial class structure --- BufferFXT.mqh | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 BufferFXT.mqh diff --git a/BufferFXT.mqh b/BufferFXT.mqh new file mode 100644 index 000000000..49f14a47b --- /dev/null +++ b/BufferFXT.mqh @@ -0,0 +1,69 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2020, 31337 Investments 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 . + */ + +// Prevents processing this includes file for the second time. +#ifndef BUFFER_FXT_MQH +#define BUFFER_FXT_MQH + +// Includes. +#include "DictStruct.mqh" + +// Structs. +struct BufferFXTEntry { + public: + bool operator==(const BufferFXTEntry& _s) { + // @fixme + return false; + } + string ToJSON() { + // @fixme + return "{}"; + } +}; + +string ToJSON(BufferFXTEntry& _value, const bool, const unsigned int) { return _value.ToJSON(); }; + +/** + * Implements class to store tick data. + */ +class BufferFXT : public DictStruct { + public: + BufferFXT() {} + + /** + * Adds new value. + */ + void Add(BufferFXTEntry& _value, long _dt = 0) { + _dt = _dt > 0 ? _dt : TimeCurrent(); + Set(_dt, _value); + } + + /** + * Save data into file. + */ + void SaveToFile() { + // @todo: foreach BufferFXTEntry + // @see: https://docs.mql4.com/files/filewritestruct + } + +}; + +#endif // BUFFER_FXT_MQH From cf5c37f4c38b3ff82a5e728673819d941115edb7 Mon Sep 17 00:00:00 2001 From: kenorb Date: Thu, 5 Mar 2020 11:38:14 +0000 Subject: [PATCH 2/6] BufferFXT: Adds BufferFXTHeader and defines --- BufferFXT.mqh | 117 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/BufferFXT.mqh b/BufferFXT.mqh index 49f14a47b..a370d5457 100644 --- a/BufferFXT.mqh +++ b/BufferFXT.mqh @@ -39,6 +39,122 @@ struct BufferFXTEntry { } }; +// FXT file header. +struct BufferFXTHeader { + int version; // Header version: 405 + char copyright[64]; // Copyright/description. + char description[128]; // Account server name. + // 196 + char symbol[12]; // Symbol pair. + int period; // Period of data aggregation in minutes (timeframe). + int model; // Model type: 0 - every tick, 1 - control points, 2 - bar open. + int bars; // Bars - number of modeled bars in history. + int fromdate; // Modelling start date - date of the first tick. + int todate; // Modelling end date - date of the last tick. + int totalTicks; // Total ticks. Add 4 bytes to align to the next double? + double modelquality; // Modeling quality (max. 99.9). + // 240 + // Market symbol properties. + char currency[12]; // Base currency (12 bytes). Same as: StringLeft(symbol, 3) + int spread; // Spread in points. Same as: MarketInfo(MODE_SPREAD) + int digits; // Digits (default: 5). Same as: MarketInfo(MODE_DIGITS) + int padding1; // Padding space - add 4 bytes to align to the next double. + double point; // Point size (e.g. 0.00001). Same as: MarketInfo(MODE_POINT) + int lot_min; // Minimal lot size in centi lots (hundredths). Same as: MarketInfo(MODE_MINLOT)*100 + int lot_max; // Maximal lot size in centi lots (hundredths). Same as: MarketInfo(MODE_MAXLOT)*100 + int lot_step; // Lot step in centi lots (hundredths). Same as: MarketInfo(MODE_LOTSTEP)*100 + int stops_level; // Stops level value (orders stop distance in points). Same as: MarketInfo(MODE_STOPLEVEL) + int gtc_pendings; // GTC (Good till cancel) - instruction to close pending orders at end of day (default: False). + int padding2; // Padding space - add 4 bytes to align to the next double. + // 296 + // Profit calculation parameters. + double contract_size; // Contract size (e.g. 100000). Same as: MarketInfo(MODE_LOTSIZE) + double tick_value; // Tick value in quote currency (empty). Same as: MarketInfo(MODE_TICKVALUE) + double tick_size; // Size of one tick (empty). Same as: MarketInfo(MODE_TICKSIZE) + int profit_mode; // Profit calculation mode { PROFIT_CALC_FOREX=0, PROFIT_CALC_CFD=1, PROFIT_CALC_FUTURES=2 }. Same + // as: MarketInfo(MODE_PROFITCALCMODE) + // 324 + // Swap calculation. + int swap_enable; // Enable swaps (default: True). + int swap_type; // Type of swap { SWAP_BY_POINTS=0, SWAP_BY_BASECURRENCY=1, SWAP_BY_INTEREST=2, + // SWAP_BY_MARGINCURRENCY=3 }. Same as: MarketInfo(MODE_SWAPTYPE) + int padding3; // Padding space - add 4 bytes to align to the next double. + double swap_long; // Swap of the buy order - long overnight swap value. Same as: MarketInfo(MODE_SWAPLONG) + double swap_short; // Swap of the sell order - short overnight swap value. Same as: MarketInfo(MODE_SWAPSHORT) + int swap_rollover3days; // Day of week to charge 3 days swap rollover. Default: WEDNESDAY (3). Same as: + // MarketInfo(SYMBOL_SWAP_ROLLOVER3DAYS) + // 356 + // Margin calculation. + int leverage; // Account leverage (default: 100). Same as: AccountLeverage() + int free_margin_mode; // Free margin calculation mode { MARGIN_DONT_USE=0, MARGIN_USE_ALL=1, MARGIN_USE_PROFIT=2, + // MARGIN_USE_LOSS=3 }. Same as: AccountFreeMarginMode() + int margin_mode; // Margin calculation mode { MARGIN_CALC_FOREX=0, MARGIN_CALC_CFD=1, MARGIN_CALC_FUTURES=2, + // MARGIN_CALC_CFDINDEX=3 }. Same as: MarketInfo(MODE_MARGINCALCMODE) + int margin_stopout; // Margin Stop Out level (default: 30). Same as: AccountStopoutLevel() + + int margin_stopout_mode; // Check mode for Stop Out level { MARGIN_TYPE_PERCENT=0, MARGIN_TYPE_CURRENCY=1 }. Same as: + // AccountStopoutMode() + double margin_initial; // Initial margin requirement (in units). Same as: MarketInfo(MODE_MARGININIT) + double margin_maintenance; // Maintenance margin requirement (in units). Same as: MarketInfo(MODE_MARGINMAINTENANCE) + double margin_hedged; // Hedged margin requirement for positions (in units). Same as: MarketInfo(MODE_MARGINHEDGED) + double margin_divider; // Margin divider used for leverage calculation. + char margin_currency[12]; // Margin currency. Same as: AccountCurrency(). + int padding4; // Padding space - add 4 bytes to align to the next double. + // 424 + // Commission calculation. + double comm_base; // Basic commission rate. + int comm_type; // Basic commission type { COMM_TYPE_MONEY=0, COMM_TYPE_PIPS=1, COMM_TYPE_PERCENT=2 }. + int comm_lots; // Commission per lot or per deal { COMMISSION_PER_LOT=0, COMMISSION_PER_DEAL=1 } + // 440 + // For internal use. + int from_bar; // Index of the first bar at which modeling started (0 for the first bar). + int to_bar; // Index of the last bar at which modeling started (0 for the last bar). + int start_period_m1; // Bar index where modeling started using M1 bars (0 for the first bar). + int start_period_m5; // Bar index where modeling started using M5 bars (0 for the first bar). + int start_period_m15; // Bar index where modeling started using M15 bars (0 for the first bar). + int start_period_m30; // Bar index where modeling started using M30 bars (0 for the first bar). + int start_period_h1; // Bar index where modeling started using H1 bars (0 for the first bar). + int start_period_h4; // Bar index where modeling started using H4 bars (0 for the first bar). + int set_from; // Begin date from tester settings (must be zero). + int set_to; // End date from tester settings (must be zero). + // 480 + //---- + int freeze_level; // Order freeze level in points. Same as: MarketInfo(MODE_FREEZELEVEL) + int generating_errors; // Number of errors during model generation which needs to be fixed before testing. + // 488 + //---- + int reserved[60]; // Reserved - space for future use. +}; + +// Defines. +#define FXT_VERSION 405 +// Profit calculation mode. +#define PROFIT_CALC_FOREX 0 // Default. +#define PROFIT_CALC_CFD 1 +#define PROFIT_CALC_FUTURES 2 +// Type of swap. +#define SWAP_BY_POINTS 0 // Default. +#define SWAP_BY_BASECURRENCY 1 +#define SWAP_BY_INTEREST 2 +#define SWAP_BY_MARGINCURRENCY 3 +// Free margin calculation mode. +#define MARGIN_DONT_USE 0 +#define MARGIN_USE_ALL 1 // Default. +#define MARGIN_USE_PROFIT 2 +#define MARGIN_USE_LOSS 3 +// Margin calculation mode. +#define MARGIN_CALC_FOREX 0 // Default. +#define MARGIN_CALC_CFD 1 +#define MARGIN_CALC_FUTURES 2 +#define MARGIN_CALC_CFDINDEX 3 +// Basic commission type. +#define COMM_TYPE_MONEY 0 +#define COMM_TYPE_PIPS 1 +#define COMM_TYPE_PERCENT 2 +// Commission per lot or per deal. +#define COMMISSION_PER_LOT 0 +#define COMMISSION_PER_DEAL 1 + string ToJSON(BufferFXTEntry& _value, const bool, const unsigned int) { return _value.ToJSON(); }; /** @@ -63,7 +179,6 @@ class BufferFXT : public DictStruct { // @todo: foreach BufferFXTEntry // @see: https://docs.mql4.com/files/filewritestruct } - }; #endif // BUFFER_FXT_MQH From d50ab7a30bd53889b9abb04a3d541a18423857cc Mon Sep 17 00:00:00 2001 From: kenorb Date: Thu, 5 Mar 2020 11:47:29 +0000 Subject: [PATCH 3/6] BufferFXTTest: Adds tests --- BufferFXT.mqh | 21 +++++++++++++++-- tests/BufferFXTTest.mq4 | 28 ++++++++++++++++++++++ tests/BufferFXTTest.mq5 | 51 ++++++++++++++++++++++++++++++++++++++++ tests/docker-compose.yml | 9 +++++++ 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 tests/BufferFXTTest.mq4 create mode 100644 tests/BufferFXTTest.mq5 diff --git a/BufferFXT.mqh b/BufferFXT.mqh index a370d5457..fda252eee 100644 --- a/BufferFXT.mqh +++ b/BufferFXT.mqh @@ -28,6 +28,15 @@ // Structs. struct BufferFXTEntry { + datetime otm; // Bar datetime. + double open; // OHLCV values. + double high; + double low; + double close; + long volume; + int ctm; // The current time within a bar. + int flag; // Flag to launch an expert (0 - bar will be modified, but the expert will not be launched). + public: bool operator==(const BufferFXTEntry& _s) { // @fixme @@ -165,18 +174,26 @@ class BufferFXT : public DictStruct { BufferFXT() {} /** - * Adds new value. + * Adds new entry. */ void Add(BufferFXTEntry& _value, long _dt = 0) { _dt = _dt > 0 ? _dt : TimeCurrent(); Set(_dt, _value); } + /** + * Adds new entry. + */ + void Add(MqlTick& _value) { + // @todo: Parse MqlTick. + //Set(_dt, _value); + } + /** * Save data into file. */ void SaveToFile() { - // @todo: foreach BufferFXTEntry + // @todo: Save BufferFXTHeader, then foreach BufferFXTEntry. // @see: https://docs.mql4.com/files/filewritestruct } }; diff --git a/tests/BufferFXTTest.mq4 b/tests/BufferFXTTest.mq4 new file mode 100644 index 000000000..94bbf9cf4 --- /dev/null +++ b/tests/BufferFXTTest.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2020, 31337 Investments 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 + * Test functionality of BufferFXT class. + */ + +// Includes. +#include "BufferFXTTest.mq5" diff --git a/tests/BufferFXTTest.mq5 b/tests/BufferFXTTest.mq5 new file mode 100644 index 000000000..207900565 --- /dev/null +++ b/tests/BufferFXTTest.mq5 @@ -0,0 +1,51 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2020, 31337 Investments 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 + * Test functionality of Buffer class. + */ + +// Includes +#include "../BufferFXT.mqh" +#include "../Test.mqh" + +BufferFXT *ticks; + +/** + * Implements OnInit(). + */ +int OnInit() { + ticks = new BufferFXT(); + // Test 1. + // @todo + return (GetLastError() > 0 ? INIT_FAILED : INIT_SUCCEEDED); +} + +/** + * Implements OnTick(). + */ +void OnTick() {} + +/** + * Implements OnDeinit(). + */ +void OnDeinit(const int reason) { delete ticks; } diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index a7dae24e1..c17236344 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -25,6 +25,15 @@ services: BT_DAYS: 1-4 BT_MONTHS: 1 OPT_VERBOSE: 1 + BufferFXTTest: + command: run_backtest -e BufferFXTTest.mq4 + image: ea31337/ea-tester:EURUSD-2018-DS + volumes: + - ../:/opt/src + environment: + BT_DAYS: 10-12 + BT_MONTHS: 1 + OPT_VERBOSE: 1 BufferTest: command: run_backtest -e BufferTest.mq4 image: ea31337/ea-tester:EURUSD-2019-DS From 913011122f2de250e2b91efe7207078e29fd2f39 Mon Sep 17 00:00:00 2001 From: kenorb Date: Thu, 5 Mar 2020 22:28:14 +0000 Subject: [PATCH 4/6] BufferFXT: Adds BufferFXTParams and constructor for BufferFXTEntry --- BufferFXT.mqh | 146 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 118 insertions(+), 28 deletions(-) diff --git a/BufferFXT.mqh b/BufferFXT.mqh index fda252eee..6f0146a95 100644 --- a/BufferFXT.mqh +++ b/BufferFXT.mqh @@ -24,7 +24,42 @@ #define BUFFER_FXT_MQH // Includes. +#include "Account.mqh" #include "DictStruct.mqh" +#include "Market.mqh" +#include "Object.mqh" + +// Defines. +#define FXT_VERSION 405 +// Profit calculation mode. +#define PROFIT_CALC_FOREX 0 // Default. +#define PROFIT_CALC_CFD 1 +#define PROFIT_CALC_FUTURES 2 +// Type of swap. +#define SWAP_BY_POINTS 0 // Default. +#define SWAP_BY_BASECURRENCY 1 +#define SWAP_BY_INTEREST 2 +#define SWAP_BY_MARGINCURRENCY 3 +// Free margin calculation mode. +#define MARGIN_DONT_USE 0 +#define MARGIN_USE_ALL 1 // Default. +#define MARGIN_USE_PROFIT 2 +#define MARGIN_USE_LOSS 3 +// Margin calculation mode. +#define MARGIN_CALC_FOREX 0 // Default. +#define MARGIN_CALC_CFD 1 +#define MARGIN_CALC_FUTURES 2 +#define MARGIN_CALC_CFDINDEX 3 +// Check mode for Stop Out level (AccountStopoutMode). +#define MARGIN_TYPE_PERCENT 0 +#define MARGIN_TYPE_CURRENCY 1 +// Basic commission type. +#define COMM_TYPE_MONEY 0 +#define COMM_TYPE_PIPS 1 +#define COMM_TYPE_PERCENT 2 +// Commission per lot or per deal. +#define COMMISSION_PER_LOT 0 +#define COMMISSION_PER_DEAL 1 // Structs. struct BufferFXTEntry { @@ -133,36 +168,76 @@ struct BufferFXTHeader { // 488 //---- int reserved[60]; // Reserved - space for future use. + // Struct constructor. + BufferFXTHeader(Market *_m, Account *_a) : + version(405), + period(PERIOD_CURRENT), + model(0), + bars(0), + fromdate(0), + todate(0), + totalTicks(0), + modelquality(0), + spread(0), + digits(5), + point(0.00001), + lot_min(0), + lot_max(0), + lot_step(0), + stops_level(0), + gtc_pendings(false), + contract_size(10000), + tick_value(0), + tick_size(0), + profit_mode(PROFIT_CALC_FOREX), + swap_enable(true), + swap_type(SWAP_BY_POINTS), + swap_long(0), + swap_short(0), + swap_rollover3days(3), + leverage(100), + free_margin_mode(MARGIN_DONT_USE), + margin_mode(MARGIN_CALC_FOREX), + margin_stopout(0), + margin_stopout_mode(MARGIN_TYPE_PERCENT), + margin_initial(0), + margin_maintenance(0), + margin_hedged(0), + margin_divider(0), + comm_base(0.0), + comm_type(COMM_TYPE_MONEY), + comm_lots(COMMISSION_PER_LOT), + from_bar(0), + to_bar(0), + start_period_m1(0), + start_period_m5(0), + start_period_m15(0), + start_period_m30(0), + start_period_h1(0), + start_period_h4(0), + set_from(0), + set_to(0), + freeze_level(0), + generating_errors(0) { + ArrayInitialize(copyright, 0); + ArrayInitialize(currency, 0); + ArrayInitialize(description, 0); + ArrayInitialize(margin_currency, 0); + ArrayInitialize(reserved, 0); + ArrayInitialize(symbol, 0); + } }; -// Defines. -#define FXT_VERSION 405 -// Profit calculation mode. -#define PROFIT_CALC_FOREX 0 // Default. -#define PROFIT_CALC_CFD 1 -#define PROFIT_CALC_FUTURES 2 -// Type of swap. -#define SWAP_BY_POINTS 0 // Default. -#define SWAP_BY_BASECURRENCY 1 -#define SWAP_BY_INTEREST 2 -#define SWAP_BY_MARGINCURRENCY 3 -// Free margin calculation mode. -#define MARGIN_DONT_USE 0 -#define MARGIN_USE_ALL 1 // Default. -#define MARGIN_USE_PROFIT 2 -#define MARGIN_USE_LOSS 3 -// Margin calculation mode. -#define MARGIN_CALC_FOREX 0 // Default. -#define MARGIN_CALC_CFD 1 -#define MARGIN_CALC_FUTURES 2 -#define MARGIN_CALC_CFDINDEX 3 -// Basic commission type. -#define COMM_TYPE_MONEY 0 -#define COMM_TYPE_PIPS 1 -#define COMM_TYPE_PERCENT 2 -// Commission per lot or per deal. -#define COMMISSION_PER_LOT 0 -#define COMMISSION_PER_DEAL 1 +struct BufferFXTParams { + Account *account; + Market *market; + // Struct constructor. + void BufferFXTParams(Market *_market = NULL, Account *_account = NULL) + : account(Object::IsValid(_account) ? _account : new Account), + market(Object::IsValid(_market) ? _market : new Market) {} + // Struct deconstructor. + void ~BufferFXTParams() { delete account; delete market; } +}; string ToJSON(BufferFXTEntry& _value, const bool, const unsigned int) { return _value.ToJSON(); }; @@ -170,8 +245,23 @@ string ToJSON(BufferFXTEntry& _value, const bool, const unsigned int) { return _ * Implements class to store tick data. */ class BufferFXT : public DictStruct { + protected: + + BufferFXTParams params; + public: + + /** + * Class constructor. + */ BufferFXT() {} + BufferFXT(const BufferFXTParams &_params) { params = _params; } + + /** + * Class deconstructor. + */ + ~BufferFXT() { + } /** * Adds new entry. From 86f5e12dcb21d2417b601e0c9acd394d9d1a0f8e Mon Sep 17 00:00:00 2001 From: kenorb Date: Thu, 5 Mar 2020 23:26:30 +0000 Subject: [PATCH 5/6] BufferFXT: Initialize BufferFXTHeader using Chart instance --- BufferFXT.mqh | 55 ++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/BufferFXT.mqh b/BufferFXT.mqh index 6f0146a95..5d46002e9 100644 --- a/BufferFXT.mqh +++ b/BufferFXT.mqh @@ -25,8 +25,8 @@ // Includes. #include "Account.mqh" +#include "Chart.mqh" #include "DictStruct.mqh" -#include "Market.mqh" #include "Object.mqh" // Defines. @@ -169,39 +169,39 @@ struct BufferFXTHeader { //---- int reserved[60]; // Reserved - space for future use. // Struct constructor. - BufferFXTHeader(Market *_m, Account *_a) : + BufferFXTHeader(Chart *_c, Account *_a) : version(405), - period(PERIOD_CURRENT), + period(_c.GetTf()), model(0), bars(0), fromdate(0), todate(0), totalTicks(0), modelquality(0), - spread(0), - digits(5), - point(0.00001), - lot_min(0), - lot_max(0), - lot_step(0), - stops_level(0), + spread((int) _c.GetSpread()), + digits((int) _c.GetDigits()), + point(_c.GetPointSize()), + lot_min(int(_c.GetVolumeMin() * 100)), + lot_max(int(_c.GetVolumeMax() * 100)), + lot_step(int(_c.GetVolumeStep() * 100)), + stops_level(0), // @todo: Add MODE_STOPLEVEL to Account. gtc_pendings(false), contract_size(10000), - tick_value(0), - tick_size(0), + tick_value(_c.GetTickValue()), + tick_size(_c.GetTickSize()), profit_mode(PROFIT_CALC_FOREX), swap_enable(true), - swap_type(SWAP_BY_POINTS), - swap_long(0), - swap_short(0), + swap_type(SWAP_BY_POINTS), // @todo: Add _c.GetSwapType() to SymbolInfo. + swap_long(_c.GetSwapLong()), + swap_short(_c.GetSwapShort()), swap_rollover3days(3), - leverage(100), + leverage((int) _a.GetLeverage()), free_margin_mode(MARGIN_DONT_USE), margin_mode(MARGIN_CALC_FOREX), - margin_stopout(0), - margin_stopout_mode(MARGIN_TYPE_PERCENT), - margin_initial(0), - margin_maintenance(0), + margin_stopout(30), // @fixme: _a.GetStopoutLevel() based on ACCOUNT_MARGIN_SO_CALL. + margin_stopout_mode(_a.GetStopoutMode()), + margin_initial(_c.GetMarginInit()), + margin_maintenance(_c.GetMarginMaintenance()), margin_hedged(0), margin_divider(0), comm_base(0.0), @@ -217,26 +217,26 @@ struct BufferFXTHeader { start_period_h4(0), set_from(0), set_to(0), - freeze_level(0), + freeze_level((int) _c.GetFreezeLevel()), generating_errors(0) { ArrayInitialize(copyright, 0); - ArrayInitialize(currency, 0); + //currency = StringSubstr(_m.GetSymbol(), 0, 3); // @fixme ArrayInitialize(description, 0); ArrayInitialize(margin_currency, 0); ArrayInitialize(reserved, 0); - ArrayInitialize(symbol, 0); + //symbol = _m.GetSymbol(); // @fixme } }; struct BufferFXTParams { Account *account; - Market *market; + Chart *chart; // Struct constructor. - void BufferFXTParams(Market *_market = NULL, Account *_account = NULL) + void BufferFXTParams(Chart *_chart = NULL, Account *_account = NULL) : account(Object::IsValid(_account) ? _account : new Account), - market(Object::IsValid(_market) ? _market : new Market) {} + chart(Object::IsValid(_chart) ? _chart : new Chart) {} // Struct deconstructor. - void ~BufferFXTParams() { delete account; delete market; } + void ~BufferFXTParams() { delete account; delete chart; } }; string ToJSON(BufferFXTEntry& _value, const bool, const unsigned int) { return _value.ToJSON(); }; @@ -283,6 +283,7 @@ class BufferFXT : public DictStruct { * Save data into file. */ void SaveToFile() { + BufferFXTHeader header(params.chart, params.account); // @todo: Save BufferFXTHeader, then foreach BufferFXTEntry. // @see: https://docs.mql4.com/files/filewritestruct } From 8b1853678021533181e9f88cdfa9a21f4bf6eb49 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 11 Sep 2021 12:18:03 +0100 Subject: [PATCH 6/6] BufferFXT: Code reformats --- BufferFXT.mqh | 154 +++++++++++++++++++++++++------------------------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/BufferFXT.mqh b/BufferFXT.mqh index 5d46002e9..143b803f9 100644 --- a/BufferFXT.mqh +++ b/BufferFXT.mqh @@ -63,17 +63,17 @@ // Structs. struct BufferFXTEntry { - datetime otm; // Bar datetime. - double open; // OHLCV values. - double high; - double low; - double close; - long volume; - int ctm; // The current time within a bar. - int flag; // Flag to launch an expert (0 - bar will be modified, but the expert will not be launched). + datetime otm; // Bar datetime. + double open; // OHLCV values. + double high; + double low; + double close; + long volume; + int ctm; // The current time within a bar. + int flag; // Flag to launch an expert (0 - bar will be modified, but the expert will not be launched). public: - bool operator==(const BufferFXTEntry& _s) { + bool operator==(const BufferFXTEntry &_s) { // @fixme return false; } @@ -169,63 +169,63 @@ struct BufferFXTHeader { //---- int reserved[60]; // Reserved - space for future use. // Struct constructor. - BufferFXTHeader(Chart *_c, Account *_a) : - version(405), - period(_c.GetTf()), - model(0), - bars(0), - fromdate(0), - todate(0), - totalTicks(0), - modelquality(0), - spread((int) _c.GetSpread()), - digits((int) _c.GetDigits()), - point(_c.GetPointSize()), - lot_min(int(_c.GetVolumeMin() * 100)), - lot_max(int(_c.GetVolumeMax() * 100)), - lot_step(int(_c.GetVolumeStep() * 100)), - stops_level(0), // @todo: Add MODE_STOPLEVEL to Account. - gtc_pendings(false), - contract_size(10000), - tick_value(_c.GetTickValue()), - tick_size(_c.GetTickSize()), - profit_mode(PROFIT_CALC_FOREX), - swap_enable(true), - swap_type(SWAP_BY_POINTS), // @todo: Add _c.GetSwapType() to SymbolInfo. - swap_long(_c.GetSwapLong()), - swap_short(_c.GetSwapShort()), - swap_rollover3days(3), - leverage((int) _a.GetLeverage()), - free_margin_mode(MARGIN_DONT_USE), - margin_mode(MARGIN_CALC_FOREX), - margin_stopout(30), // @fixme: _a.GetStopoutLevel() based on ACCOUNT_MARGIN_SO_CALL. - margin_stopout_mode(_a.GetStopoutMode()), - margin_initial(_c.GetMarginInit()), - margin_maintenance(_c.GetMarginMaintenance()), - margin_hedged(0), - margin_divider(0), - comm_base(0.0), - comm_type(COMM_TYPE_MONEY), - comm_lots(COMMISSION_PER_LOT), - from_bar(0), - to_bar(0), - start_period_m1(0), - start_period_m5(0), - start_period_m15(0), - start_period_m30(0), - start_period_h1(0), - start_period_h4(0), - set_from(0), - set_to(0), - freeze_level((int) _c.GetFreezeLevel()), - generating_errors(0) { - ArrayInitialize(copyright, 0); - //currency = StringSubstr(_m.GetSymbol(), 0, 3); // @fixme - ArrayInitialize(description, 0); - ArrayInitialize(margin_currency, 0); - ArrayInitialize(reserved, 0); - //symbol = _m.GetSymbol(); // @fixme - } + BufferFXTHeader(Chart *_c, Account *_a) + : version(405), + period(_c.GetTf()), + model(0), + bars(0), + fromdate(0), + todate(0), + totalTicks(0), + modelquality(0), + spread((int)_c.GetSpread()), + digits((int)_c.GetDigits()), + point(_c.GetPointSize()), + lot_min(int(_c.GetVolumeMin() * 100)), + lot_max(int(_c.GetVolumeMax() * 100)), + lot_step(int(_c.GetVolumeStep() * 100)), + stops_level(0), // @todo: Add MODE_STOPLEVEL to Account. + gtc_pendings(false), + contract_size(10000), + tick_value(_c.GetTickValue()), + tick_size(_c.GetTickSize()), + profit_mode(PROFIT_CALC_FOREX), + swap_enable(true), + swap_type(SWAP_BY_POINTS), // @todo: Add _c.GetSwapType() to SymbolInfo. + swap_long(_c.GetSwapLong()), + swap_short(_c.GetSwapShort()), + swap_rollover3days(3), + leverage((int)_a.GetLeverage()), + free_margin_mode(MARGIN_DONT_USE), + margin_mode(MARGIN_CALC_FOREX), + margin_stopout(30), // @fixme: _a.GetStopoutLevel() based on ACCOUNT_MARGIN_SO_CALL. + margin_stopout_mode(_a.GetStopoutMode()), + margin_initial(_c.GetMarginInit()), + margin_maintenance(_c.GetMarginMaintenance()), + margin_hedged(0), + margin_divider(0), + comm_base(0.0), + comm_type(COMM_TYPE_MONEY), + comm_lots(COMMISSION_PER_LOT), + from_bar(0), + to_bar(0), + start_period_m1(0), + start_period_m5(0), + start_period_m15(0), + start_period_m30(0), + start_period_h1(0), + start_period_h4(0), + set_from(0), + set_to(0), + freeze_level((int)_c.GetFreezeLevel()), + generating_errors(0) { + ArrayInitialize(copyright, 0); + // currency = StringSubstr(_m.GetSymbol(), 0, 3); // @fixme + ArrayInitialize(description, 0); + ArrayInitialize(margin_currency, 0); + ArrayInitialize(reserved, 0); + // symbol = _m.GetSymbol(); // @fixme + } }; struct BufferFXTParams { @@ -233,24 +233,25 @@ struct BufferFXTParams { Chart *chart; // Struct constructor. void BufferFXTParams(Chart *_chart = NULL, Account *_account = NULL) - : account(Object::IsValid(_account) ? _account : new Account), - chart(Object::IsValid(_chart) ? _chart : new Chart) {} + : account(Object::IsValid(_account) ? _account : new Account), + chart(Object::IsValid(_chart) ? _chart : new Chart) {} // Struct deconstructor. - void ~BufferFXTParams() { delete account; delete chart; } + void ~BufferFXTParams() { + delete account; + delete chart; + } }; -string ToJSON(BufferFXTEntry& _value, const bool, const unsigned int) { return _value.ToJSON(); }; +string ToJSON(BufferFXTEntry &_value, const bool, const unsigned int) { return _value.ToJSON(); }; /** * Implements class to store tick data. */ class BufferFXT : public DictStruct { protected: - BufferFXTParams params; public: - /** * Class constructor. */ @@ -260,13 +261,12 @@ class BufferFXT : public DictStruct { /** * Class deconstructor. */ - ~BufferFXT() { - } + ~BufferFXT() {} /** * Adds new entry. */ - void Add(BufferFXTEntry& _value, long _dt = 0) { + void Add(BufferFXTEntry &_value, long _dt = 0) { _dt = _dt > 0 ? _dt : TimeCurrent(); Set(_dt, _value); } @@ -274,9 +274,9 @@ class BufferFXT : public DictStruct { /** * Adds new entry. */ - void Add(MqlTick& _value) { + void Add(MqlTick &_value) { // @todo: Parse MqlTick. - //Set(_dt, _value); + // Set(_dt, _value); } /**