This article implements a James–Stein and empirical Bayes shrinkage library in MQL5, validates it against hand-checked arithmetic and a Python reference, and applies it to ten years of H1 data across eight symbols. It covers fixed-target and grand-mean forms, unequal variances with a fitted between-group spread, and a proportions wrapper. You finish with a reusable header, a reproducible test script, a walk-forward study, and a chart indicator that shrinks an hour-of-day table.
Every trading workflow produces a table of numbers measured side by side. An optimizer reports the average return of eight Donchian lookbacks. A session study reports the mean return of twenty-four hours of the day. A portfolio review reports the win rate of a dozen symbols. The habit is always the same: sort the table and keep the top row.
That habit has a known failure mode. Each row is a mean estimated from a finite sample, so each carries its own noise, and the largest value in a noisy list is the one whose noise happened to point up. Take the same measurement again on fresh data and the winner regresses. The effect is not subtle: it is the reason an optimizer's best parameter set so rarely repeats out of sample.
In 1961 Willard James and Charles Stein published a result that reads as a paradox on first contact. If you estimate three or more means at the same time, the vector of sample means is not admissible under total squared error. Pull every estimate a little toward a common center and the expected total squared error falls, for every true configuration of the means. The guarantee is an average over repeated samples, not a promise about any single data set: on one draw the shrunk vector can land further from the truth than the raw one, and the article measures how often. The coordinates need not even be related, which is the part that sounds absurd and is nevertheless a theorem.
This article builds that estimator in MQL5, together with the empirical Bayes generalization that handles what an actual trading table always presents: coordinates measured with different precision. It then does the part most treatments skip. The theorem concerns estimation, whereas traders care about selection; these are different questions. The study here asks both on the same data, and the answers come back different enough that the distinction has to be taken seriously.
Check out the new article: James-Stein Shrinkage: Estimating Many Numbers at Once, and Testing What It Buys.
Every trading workflow produces a table of numbers measured side by side. An optimizer reports the average return of eight Donchian lookbacks. A session study reports the mean return of twenty-four hours of the day. A portfolio review reports the win rate of a dozen symbols. The habit is always the same: sort the table and keep the top row.
That habit has a known failure mode. Each row is a mean estimated from a finite sample, so each carries its own noise, and the largest value in a noisy list is the one whose noise happened to point up. Take the same measurement again on fresh data and the winner regresses. The effect is not subtle: it is the reason an optimizer's best parameter set so rarely repeats out of sample.
In 1961 Willard James and Charles Stein published a result that reads as a paradox on first contact. If you estimate three or more means at the same time, the vector of sample means is not admissible under total squared error. Pull every estimate a little toward a common center and the expected total squared error falls, for every true configuration of the means. The guarantee is an average over repeated samples, not a promise about any single data set: on one draw the shrunk vector can land further from the truth than the raw one, and the article measures how often. The coordinates need not even be related, which is the part that sounds absurd and is nevertheless a theorem.
This article builds that estimator in MQL5, together with the empirical Bayes generalization that handles what an actual trading table always presents: coordinates measured with different precision. It then does the part most treatments skip. The theorem concerns estimation, whereas traders care about selection; these are different questions. The study here asks both on the same data, and the answers come back different enough that the distinction has to be taken seriously.
Author: Hammad Dilber