Skip to content

MtApi5: expose TesterDeposit and TesterWithdrawal for backtesting#302

Open
biohazardxxx wants to merge 5 commits into
vdemydiuk:devfrom
biohazardxxx:feat/mql5-tester-money
Open

MtApi5: expose TesterDeposit and TesterWithdrawal for backtesting#302
biohazardxxx wants to merge 5 commits into
vdemydiuk:devfrom
biohazardxxx:feat/mql5-tester-money

Conversation

@biohazardxxx

Copy link
Copy Markdown

Summary

Exposes the MQL5 strategy-tester money functions through the MtApi5 connector so backtesting EAs driven from .NET can simulate deposits and withdrawals. MQL5 provides TesterDeposit/TesterWithdrawal natively, but neither was reachable from the C# client.

C# client (MtApi5) — 2 methods on MtApi5Client:

Command id Method
370 bool TesterDeposit(double money)
371 bool TesterWithdrawal(double money)

MQL5 EA (mq5/MtApi5.mq5)Execute_TesterDeposit/Execute_TesterWithdrawal handlers + executor registrations. mq5/MtApi5.ex5 recompiled (0 errors).

TestClientTesterDeposit/TesterWithdrawal buttons for manual exercising (hardcoded 1000.0 amount, logs the bool result).

Implementation notes

  • Command ids 370/371 are identical in the C# Mt5CommandType enum and the mq5 ADD_EXECUTOR table; no collisions with existing ids.
  • The C# methods send {"Money": <double>} and deserialize a JSON bool; the response path is the same proven pattern as the existing IsTesting command.
  • The EA handlers call the MQL5 built-ins directly and guard with IsTesting(): outside the strategy tester they return CreateErrorResponse(-1, "... can be used only for backtesting"), exactly mirroring the existing Execute_TesterStop/Execute_UnlockTicks precedent. On the C# side that means a call outside the tester throws ExecutionException rather than returning false; inside the tester the built-in's bool result is returned. This is documented in the XML doc comments.
  • TesterStatistics was deliberately not included: it is only callable from OnTester/OnDeinit, which makes it unusable over this OnTimer/OnTick RPC bridge.

Testing

  • MtApi5 and MtApi5TestClient build clean in Release (MtApi5 with 0 warnings; the TestClient's 334 nullable-reference warnings are pre-existing and none are in the new code).
  • MtApi5.mq5 compiles via MetaEditor with "Result: 0 errors"; the recompiled MtApi5.ex5 is included.
  • Not runtime-tested: the feature has not been exercised against a live MT5 terminal / strategy tester session — verification is build/compile only.

Branch is based on dev and contains tester-money changes only; the diff is purely additive with no changes to existing behavior.

🤖 Generated with Claude Code

biohazardxxx and others added 5 commits July 3, 2026 23:57
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Strategy-tester-only money operations; documented like the existing
TesterStop/IsTesting backtesting precedent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant