Discussing the article: "Per-Setup Trade Ledger in MQL5: Find Out Which of Your EA's Entries Is Losing Money"

Check out the new article: Per-Setup Trade Ledger in MQL5: Find Out Which of Your EA's Entries Is Losing Money.

Most EAs trade more than one setup, yet the Strategy Tester judges them all by a single equity curve. CSetupLedger is a small MQL5 class that stores each trade's setup in its magic number and rebuilds the per-setup record from the account's deal history, so a restart never wipes it. It compares a Wilson interval of each setup's win rate with the breakeven rate implied by that setup's own average win and loss, and gives no verdict before 30 closed trades. Each setup ends up trusted, rejected or still undecided. In two backtests the per-setup totals match the tester exactly. Full source and two working EAs are attached.

I ran my liquidity-sweep scalper over eight months of USDCAD M1, from the first of January to early September. It closed 1,365 trades and gave back roughly two-thirds of a 10,000 USD account. The Strategy Tester summed it up in one line: profit factor 0.88, net loss 6,838.22 USD.

That line is true and almost useless. The EA trades two setups, a bullish order block after a swing low gets swept and the mirror image of it on the sell side. Same entry code, same risk model, same magic number, so as far as the tester is concerned it is one system. It isn't. When I finally split the trades by setup, 82% of the loss came from the bullish side alone. The bearish side lost money too, but less than a quarter as much. I had spent two weeks optimizing inputs that applied to both.

That is what this article fixes. CSetupLedger is a small class that keeps a separate record for every setup type in an EA. It rebuilds itself from the account's own deal history, so a restart or a deleted file doesn't wipe the record. Next to the raw win rate it prints a Wilson score interval, which answers the question I kept asking during testing: has this win rate earned any trust yet, or is it still three lucky trades? Then it compares that interval with the breakeven win rate implied by the setup's own wins and losses. How often a setup wins does not tell you, on its own, whether its trades were worth taking. What comes back is one of four short answers instead of a percentage you have to interpret: too few trades, undecided, trusted or rejected.Everything below comes out of code that runs, and the files are attached at the end of the article.

Author: Ali Akbar