Loading…

Sample Size Confidence Teacher

A win rate printed on a statement looks like a fact. It is really a point estimate with a margin of error that shrinks only slowly - roughly with the square root of the sample size, not in proportion to it. This script prints the Wilson score interval around a given (or measured) win rate at a growing series of sample sizes, so the difference between "20 trades" and "500 trades" evidence is visible as a number, not a feeling. Wilson's interval is used rather than the more commonly taught plain normal approximation deliberately: the normal approximation can produce a lower bound below 0% or an upper bound above 100% at small sample sizes or extreme win rates (for example 2 wins out of 2 trades), which is not a valid probability. Wilson's interval stays inside [0,100] at every sample size, including the small ones where this lesson matters most. The win rate fed into the table can come from a plain manual input (project a hypothetical rate forward) or from this account's own real closed-trade history, scoped by the same magic/symbol filter used elsewhere in this catalogue - so a trader can ask "how wide is the interval around what my own strategy has actually shown so far". Notes and limitations - This is a statistical teaching tool, not a trading signal. It does not say whether a strategy is good; it says how much a given win rate at a given sample size does or does not prove. - Account-history mode measures ONLY the win rate (wins/total by profit sign); it says nothing about the size of wins versus losses, which matters just as much for whether a positive win rate is actually profitable. - Wilson's interval assumes each trade's win/loss outcome is drawn independently from the same underlying probability. A strategy whose edge genuinely changes over time (regime change, parameter drift) will not satisfy that assumption, and the interval should be read as illustrative rather than exact in that case.

Script · MT4 · v1.0 · Free

About Sample Size Confidence Teacher

Sample Size Confidence Teacher is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 8 settings, such as Use account history, Magic filter and Symbol filter. MQL source code included.

Files in the download: SampleSizeConfidenceTeacher.mq4, SampleSizeConfidenceTeacher.txt.

Settings

SettingDefaultWhat it does
Use account historyfalseIf true, ignore InpObservedWinRate and use this account's real closed-trade win rate
Magic filter-1Account-history mode only: magic filter (-1 = all)
Symbol filterAccount-history mode only: symbol filter ("" = all)
Observed win rate55.0Manual mode: hypothetical win rate to project, percent
Start sample size10Table's first sample size
Max sample size500Table's last sample size
Step sample size20Sample-size increment between table rows
Confidence z1.96Z-score for the confidence level (1.96 = 95%, 1.645 = 90%, 2.576 = 99%)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria