From 4e0de34daf8a50e21f6974f694cbc31ab4da53d8 Mon Sep 17 00:00:00 2001 From: biohazardxxx Date: Fri, 3 Jul 2026 23:57:21 +0200 Subject: [PATCH 1/5] MtApi5: add tester money command ids 370-371 Co-Authored-By: Claude Fable 5 --- MtApi5/MtProtocol/Mt5CommandType.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MtApi5/MtProtocol/Mt5CommandType.cs b/MtApi5/MtProtocol/Mt5CommandType.cs index 4af91bdb..51228432 100755 --- a/MtApi5/MtProtocol/Mt5CommandType.cs +++ b/MtApi5/MtProtocol/Mt5CommandType.cs @@ -260,6 +260,9 @@ internal enum Mt5CommandType OrderCheck = 303, Buy = 304, Sell = 305, - GetSymbols = 306 + GetSymbols = 306, + + TesterDeposit = 370, + TesterWithdrawal = 371 } } From 918b1c604a500a4761d207387e323c1806841102 Mon Sep 17 00:00:00 2001 From: biohazardxxx Date: Fri, 3 Jul 2026 23:57:29 +0200 Subject: [PATCH 2/5] MtApi5: add TesterDeposit/TesterWithdrawal client methods Strategy-tester-only money operations; documented like the existing TesterStop/IsTesting backtesting precedent. Co-Authored-By: Claude Fable 5 --- MtApi5/MtApi5Client.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index b75bd2a0..e0d2d54a 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -2286,6 +2286,30 @@ public void TesterStop() SendCommand(ExecutorHandle, Mt5CommandType.TesterStop); } + /// + ///Deposits money to the account of the tested Expert Advisor. + ///Works only in the strategy tester (see IsTesting); fails with an error when the Expert Advisor runs on a live chart. + /// + ///Deposited sum of money. + ///true if successful, otherwise false. + public bool TesterDeposit(double money) + { + Dictionary cmdParams = new() { { "Money", money } }; + return SendCommand(ExecutorHandle, Mt5CommandType.TesterDeposit, cmdParams); + } + + /// + ///Withdraws money from the account of the tested Expert Advisor. + ///Works only in the strategy tester (see IsTesting); fails with an error when the Expert Advisor runs on a live chart. + /// + ///Withdrawn sum of money. + ///true if successful, otherwise false. + public bool TesterWithdrawal(double money) + { + Dictionary cmdParams = new() { { "Money", money } }; + return SendCommand(ExecutorHandle, Mt5CommandType.TesterWithdrawal, cmdParams); + } + #endregion // Common Functions #region Object Functions From ef7a842363e6092d94a699c38840361096a75a1e Mon Sep 17 00:00:00 2001 From: biohazardxxx Date: Fri, 3 Jul 2026 23:57:37 +0200 Subject: [PATCH 3/5] MQL5: add TesterDeposit/TesterWithdrawal handlers (370-371) Direct calls to the MQL5 built-ins; both return an error response outside the strategy tester, matching the TesterStop handler. Co-Authored-By: Claude Fable 5 --- mq5/MtApi5.mq5 | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5 index 18c0b55e..912f8127 100644 --- a/mq5/MtApi5.mq5 +++ b/mq5/MtApi5.mq5 @@ -381,7 +381,10 @@ int preinit() ADD_EXECUTOR(304, Buy); ADD_EXECUTOR(305, Sell); ADD_EXECUTOR(306, GetSymbols); - + + ADD_EXECUTOR(370, TesterDeposit); + ADD_EXECUTOR(371, TesterWithdrawal); + return (0); } @@ -2982,6 +2985,36 @@ string Execute_TesterStop() return CreateSuccessResponse(); } +string Execute_TesterDeposit() +{ + if (!IsTesting()) + { + Print("WARNING: function TesterDeposit can be used only for backtesting"); + return CreateErrorResponse(-1, "TesterDeposit can be used only for backtesting"); + } + + GET_JSON_PAYLOAD(jo); + GET_DOUBLE_JSON_VALUE(jo, "Money", money); + + bool retVal = TesterDeposit(money); + return CreateSuccessResponse(new JSONBool(retVal)); +} + +string Execute_TesterWithdrawal() +{ + if (!IsTesting()) + { + Print("WARNING: function TesterWithdrawal can be used only for backtesting"); + return CreateErrorResponse(-1, "TesterWithdrawal can be used only for backtesting"); + } + + GET_JSON_PAYLOAD(jo); + GET_DOUBLE_JSON_VALUE(jo, "Money", money); + + bool retVal = TesterWithdrawal(money); + return CreateSuccessResponse(new JSONBool(retVal)); +} + string Execute_TerminalInfoInteger() { GET_JSON_PAYLOAD(jo); From 02d3fbf871bb06378ed6feb81dc0ed8449527fcb Mon Sep 17 00:00:00 2001 From: biohazardxxx Date: Fri, 3 Jul 2026 23:57:45 +0200 Subject: [PATCH 4/5] MtApi5TestClient: add TesterDeposit/TesterWithdrawal test actions Co-Authored-By: Claude Fable 5 --- TestClients/MtApi5TestClient/MainWindow.xaml | 2 ++ TestClients/MtApi5TestClient/ViewModel.cs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/TestClients/MtApi5TestClient/MainWindow.xaml b/TestClients/MtApi5TestClient/MainWindow.xaml index c30fe43e..9bed0584 100755 --- a/TestClients/MtApi5TestClient/MainWindow.xaml +++ b/TestClients/MtApi5TestClient/MainWindow.xaml @@ -614,6 +614,8 @@