From aea74bc101348bf54f5f2a71454c7f6827c7637c Mon Sep 17 00:00:00 2001 From: kenorb Date: Mon, 9 Sep 2024 22:11:29 +0100 Subject: [PATCH] Adds BacktestEa and BacktestStrategy initial classes --- .github/workflows/test-platform-backtest.yml | 2 + Platform/Backtest/Backtest.h | 9 +-- Platform/Backtest/BacktestEa.h | 63 +++++++++++++++++++ Platform/Backtest/BacktestStrategy.h | 63 +++++++++++++++++++ Platform/Backtest/tests/BacktestEa.test.cpp | 34 ++++++++++ Platform/Backtest/tests/BacktestEa.test.mq4 | 28 +++++++++ Platform/Backtest/tests/BacktestEa.test.mq5 | 50 +++++++++++++++ .../Backtest/tests/BacktestStrategy.test.cpp | 34 ++++++++++ .../Backtest/tests/BacktestStrategy.test.mq4 | 28 +++++++++ .../Backtest/tests/BacktestStrategy.test.mq5 | 50 +++++++++++++++ tests/CompileTest.mq5 | 2 + 11 files changed, 355 insertions(+), 8 deletions(-) create mode 100644 Platform/Backtest/BacktestEa.h create mode 100644 Platform/Backtest/BacktestStrategy.h create mode 100644 Platform/Backtest/tests/BacktestEa.test.cpp create mode 100644 Platform/Backtest/tests/BacktestEa.test.mq4 create mode 100644 Platform/Backtest/tests/BacktestEa.test.mq5 create mode 100644 Platform/Backtest/tests/BacktestStrategy.test.cpp create mode 100644 Platform/Backtest/tests/BacktestStrategy.test.mq4 create mode 100644 Platform/Backtest/tests/BacktestStrategy.test.mq5 diff --git a/.github/workflows/test-platform-backtest.yml b/.github/workflows/test-platform-backtest.yml index ac3824d91..85fbba876 100644 --- a/.github/workflows/test-platform-backtest.yml +++ b/.github/workflows/test-platform-backtest.yml @@ -38,6 +38,8 @@ jobs: matrix: test: - Backtest.test + - BacktestEa.test + - BacktestStrategy.test version: [5] max-parallel: 4 steps: diff --git a/Platform/Backtest/Backtest.h b/Platform/Backtest/Backtest.h index c9ed6503e..7f6437f79 100644 --- a/Platform/Backtest/Backtest.h +++ b/Platform/Backtest/Backtest.h @@ -22,7 +22,7 @@ /** * @file - * Implements Backtest class for internally backtesting strategies. + * Implements Backtest class for internally backtesting. */ #ifndef __MQL__ @@ -36,7 +36,6 @@ class Backtest { protected: // Class variables. - EA *ea; /** * Init code (called on constructor). @@ -53,10 +52,4 @@ class Backtest { Init(); } - /** - * Class constructor. - */ - Backtest(EAParams &_eparam) : ea(new EA(_eparam)) { - Init(); - } }; diff --git a/Platform/Backtest/BacktestEa.h b/Platform/Backtest/BacktestEa.h new file mode 100644 index 000000000..bad5e86d5 --- /dev/null +++ b/Platform/Backtest/BacktestEa.h @@ -0,0 +1,63 @@ +//+------------------------------------------------------------------+ +//| 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 BacktestEa class for internally backtesting EA. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Includes. +#include "Backtest.h" +#include "../../EA.mqh" + +class BacktestEa : public Backtest { + protected: + // Class variables. + EA *ea; + + /** + * Init code (called on constructor). + */ + void Init() { + // ... + } + + public: + /** + * Class constructor. + */ + BacktestEa() { + Init(); + } + + /** + * Class constructor. + */ + BacktestEa(EAParams &_eparam) : ea(new EA(_eparam)) { + Init(); + } +}; diff --git a/Platform/Backtest/BacktestStrategy.h b/Platform/Backtest/BacktestStrategy.h new file mode 100644 index 000000000..d31005a3f --- /dev/null +++ b/Platform/Backtest/BacktestStrategy.h @@ -0,0 +1,63 @@ +//+------------------------------------------------------------------+ +//| 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 BacktestStrategy class for internally backtesting strategy. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Includes. +#include "Backtest.h" +#include "../../Strategy.mqh" + +class BacktestStrategy : public Backtest { + protected: + // Class variables. + Strategy *strat; + + /** + * Init code (called on constructor). + */ + void Init() { + // ... + } + + public: + /** + * Class constructor. + */ + BacktestStrategy() { + Init(); + } + + /** + * Class constructor. + */ + BacktestStrategy(Strategy *_strat) : strat(_strat) { + Init(); + } +}; diff --git a/Platform/Backtest/tests/BacktestEa.test.cpp b/Platform/Backtest/tests/BacktestEa.test.cpp new file mode 100644 index 000000000..24122286f --- /dev/null +++ b/Platform/Backtest/tests/BacktestEa.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/Backtest/tests/BacktestEa.test.mq4 b/Platform/Backtest/tests/BacktestEa.test.mq4 new file mode 100644 index 000000000..b3d87e70f --- /dev/null +++ b/Platform/Backtest/tests/BacktestEa.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 BacktestEa class. + */ + +// Includes. +#include "BacktestEa.test.mq5" diff --git a/Platform/Backtest/tests/BacktestEa.test.mq5 b/Platform/Backtest/tests/BacktestEa.test.mq5 new file mode 100644 index 000000000..9195684db --- /dev/null +++ b/Platform/Backtest/tests/BacktestEa.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 BacktestEa class. + */ + +// Includes. +#include "../../../Test.mqh" +#include "../BacktestEa.h" + +// Test BacktestEa. +bool TestBacktestEa01() { + bool _result = true; + // @todo + return _result; +} + +/** + * Implements OnInit(). + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(TestBacktestEa01(), "Fail!"); + return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED; +} + +/** + * Implements Tick event handler. + */ +void OnTick() {} diff --git a/Platform/Backtest/tests/BacktestStrategy.test.cpp b/Platform/Backtest/tests/BacktestStrategy.test.cpp new file mode 100644 index 000000000..24122286f --- /dev/null +++ b/Platform/Backtest/tests/BacktestStrategy.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/Backtest/tests/BacktestStrategy.test.mq4 b/Platform/Backtest/tests/BacktestStrategy.test.mq4 new file mode 100644 index 000000000..fa065e52f --- /dev/null +++ b/Platform/Backtest/tests/BacktestStrategy.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 BacktestStrategy class. + */ + +// Includes. +#include "BacktestStrategy.test.mq5" diff --git a/Platform/Backtest/tests/BacktestStrategy.test.mq5 b/Platform/Backtest/tests/BacktestStrategy.test.mq5 new file mode 100644 index 000000000..9c1bec961 --- /dev/null +++ b/Platform/Backtest/tests/BacktestStrategy.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 BacktestStrategy class. + */ + +// Includes. +#include "../../../Test.mqh" +#include "../BacktestStrategy.h" + +// Test BacktestStrategy. +bool TestBacktestStrategy01() { + bool _result = true; + // @todo + return _result; +} + +/** + * Implements OnInit(). + */ +int OnInit() { + bool _result = true; + assertTrueOrFail(TestBacktestStrategy01(), "Fail!"); + return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED; +} + +/** + * Implements Tick event handler. + */ +void OnTick() {} diff --git a/tests/CompileTest.mq5 b/tests/CompileTest.mq5 index bfa819eb3..12ac6c449 100644 --- a/tests/CompileTest.mq5 +++ b/tests/CompileTest.mq5 @@ -47,6 +47,8 @@ struct IndicatorParams; #include "../Storage/Dict/Buffer/BufferFXT.h" #include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Platform/Backtest/Backtest.h" +#include "../Platform/Backtest/BacktestEa.h" +#include "../Platform/Backtest/BacktestStrategy.h" #include "../Platform/Chart/Chart.h" #include "../Config.mqh" #include "../Convert.mqh"