Skip to content
All library documents

Tracking Expert Advisor Results by Setup with Wilson Confidence Bounds

Article MQL5 code base

Summary

This document describes a MetaTrader 5 ledger for evaluating an Expert Advisor’s trade setups separately. Each setup receives a persistent identifier encoded in the order’s magic number. When positions close, the ledger groups history by position so partial exits count as one trade, adds profit, swap, and commission to calculate net results, and reports wins, losses, raw win rate, and net performance. It also compares a Wilson lower confidence bound for the win rate with the breakeven rate implied by the reward-to-risk ratio. This is intended to stop small samples, such as a few early wins, from appearing more convincing than they are.

The example shows separate results for bullish and bearish order block setups and stresses reconciling per-setup counts and net totals with the tester’s overall output. Setup registration order must remain stable because identifiers are stored in historical magic numbers. The ledger has limits: it associates each position with one setup, supports a bounded number of setups, and measures realized execution outcomes rather than the quality of a trading idea. Its author cautions that a ledger built from an in-sample backtest does not replace out-of-sample validation.

Key ideas

  • Assign each trade setup a stable identifier and encode it in the order’s magic number.
  • Aggregate closed deals by position so partial exits do not inflate trade counts.
  • Include profit, swap, and commission when measuring each position’s net result.
  • Use a Wilson lower confidence bound to judge whether a setup’s observed win rate clears its breakeven threshold with enough evidence.
  • Keep setup registration order unchanged and reconcile the ledger against overall tester totals.
  • Treat ledger results as descriptive evidence, not as a substitute for out-of-sample testing.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.