diff --git a/.github/workflows/test-platform.yml b/.github/workflows/test-platform.yml index b93eaa308..87bca78e7 100644 --- a/.github/workflows/test-platform.yml +++ b/.github/workflows/test-platform.yml @@ -37,6 +37,7 @@ jobs: strategy: matrix: test: + - Backtest.test - Order.test - OrderQuery.test - Orders.test diff --git a/Platform/Backtest.h b/Platform/Backtest.h new file mode 100644 index 000000000..e19567798 --- /dev/null +++ b/Platform/Backtest.h @@ -0,0 +1,62 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * 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 + * Implements Backtest class for internally backtesting strategies. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Includes. +#include "../EA.mqh" + +class Backtest { + protected: + // Class variables. + EA *ea; + + /** + * Init code (called on constructor). + */ + void Init() { + // ... + } + + public: + /** + * Class constructor. + */ + Backtest() { + Init(); + } + + /** + * Class constructor. + */ + Backtest(EAParams &_eparam) : ea(new EA(_eparam)) { + Init(); + } +}; diff --git a/Platform/tests/Backtest.test.cpp b/Platform/tests/Backtest.test.cpp new file mode 100644 index 000000000..24122286f --- /dev/null +++ b/Platform/tests/Backtest.test.cpp @@ -0,0 +1,34 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * 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 C++ compilation of Backtest class. + */ + +// Includes. +#include "../Backtest.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Platform/tests/Backtest.test.mq4 b/Platform/tests/Backtest.test.mq4 new file mode 100644 index 000000000..1546b901d --- /dev/null +++ b/Platform/tests/Backtest.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * 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 Backtest class. + */ + +// Includes. +#include "Backtest.test.mq5" diff --git a/Platform/tests/Backtest.test.mq5 b/Platform/tests/Backtest.test.mq5 new file mode 100644 index 000000000..170d97c70 --- /dev/null +++ b/Platform/tests/Backtest.test.mq5 @@ -0,0 +1,50 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * 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 Backtest class. + */ + +// Includes. +#include "../../Test.mqh" +#include "../Backtest.h" + +// Test Backtest. +bool TestBacktest01() { + bool _result = true; + // @todo + return _result; +} + +/** + * Implements OnInit(). + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(TestBacktest01(), "Fail!"); + return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED; +} + +/** + * Implements Tick event handler. + */ +void OnTick() {} diff --git a/Trade.enum.h b/Trade.enum.h index 89190879e..b34c681e9 100644 --- a/Trade.enum.h +++ b/Trade.enum.h @@ -80,6 +80,7 @@ enum ENUM_TRADE_CONDITION { // Defines enumeration for trade parameters. enum ENUM_TRADE_PARAM { TRADE_PARAM_BARS_MIN = 0, // Bars minimum + TRADE_PARAM_DUMMY, // Dummy trading // @todo: Move to TRADE_MODE TRADE_PARAM_LOG_LEVEL, // Log level TRADE_PARAM_LOT_SIZE, // Lot size TRADE_PARAM_MAGIC_NO, // Magic number diff --git a/Trade.mqh b/Trade.mqh index d849be21b..ea539bbac 100644 --- a/Trade.mqh +++ b/Trade.mqh @@ -805,6 +805,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. break; } Order *_order = new Order(_request, _oparams); + OnOrderOpen(_oparams); _result = OrderAdd(_order); if (_result) { OnOrderOpen(PTR_TO_REF(_order)); @@ -1761,6 +1762,16 @@ HistorySelect(0, TimeCurrent()); // Select history for access. /* Event methods */ + + /** + * Event on trade's order open. + * + * @param + * _order OrderParams instance of order struct to be open. + */ + virtual void OnOrderOpen(const OrderParams &_oparams) { + } + /** * Event on trade's order open. * diff --git a/Trade.struct.h b/Trade.struct.h index fa3fad96e..b196a60d5 100644 --- a/Trade.struct.h +++ b/Trade.struct.h @@ -129,6 +129,7 @@ struct TradeStats { /* Structure for trade parameters. */ struct TradeParams { + bool dummy; // Whether trades should be opened as dummy (fake orders). float lot_size; // Default lot size. float max_spread; // Maximum spread to trade (in pips). float risk_margin; // Maximum account margin to risk (in %). @@ -141,6 +142,7 @@ struct TradeParams { // Constructors. TradeParams(float _lot_size = 0, float _risk_margin = 1.0f, unsigned int _slippage = 0, ENUM_LOG_LEVEL _ll = V_INFO) : bars_min(100), + dummy(false), order_comment(""), log_level(_ll), lot_size(_lot_size), @@ -151,6 +153,7 @@ struct TradeParams { } TradeParams(uint64 _magic_no, ENUM_LOG_LEVEL _ll = V_INFO) : bars_min(100), + dummy(false), lot_size(0), order_comment(""), log_level(_ll),