MeanReversionScore
How stretched price is from its recent average, and how often such stretches have pulled back toward it.
Measures how far the close sits from its rolling mean over mean_window bars, as a signed fraction. It files each bar into a band by the absolute distance, then learns per band how often price came closer to the mean forward_bars later and by how much. The four outputs are the distance, the band, that learned chance and the average size of a pullback.
How to read it
- Each output is drawn in its own pane below the price. The distance pane shows a fraction: 0.001 is 0.1% above the mean, -0.001 is 0.1% below.
- Over the sample month at defaults, 90% of bars sat within ±0.12% of the mean, and the extremes reached -0.69% and +0.48%.
- The chance pane sits near 0.38: a stretch of this size came back toward the mean about 38% of the time.
- The size pane stays near 0.0002, so an average pullback is about 0.02% of price at defaults.
What it outputs
- Distance from mean
- Close minus its rolling mean over mean_window bars, divided by that mean. Positive means above the mean, negative below.
- Distance band
- Which band the absolute distance falls in: bin 0 is under one bin_size, bin 1 the next band. The sign is dropped, so above and below share bands.
- Chance of reverting
- Share of past bars in the same band where price was closer to the mean forward_bars later than at entry. Blank during warm-up and until the band has 5 outcomes. About 0.38 at defaults.
- Average reversion size
- Average shrink in distance from the mean on the outcomes that reverted, as a fraction of price. About 0.0002 at defaults, roughly 0.02%.
Settings
- mean_window
- Length of the rolling mean the distance is measured from. Raising it slows the mean, so distances swing wider and last longer. Lowering it tightens the mean to price, so distances shrink toward zero. The first bars show no value until the window fills.
- forward_bars
- How many bars pass before a stretch is judged. Raising it gives price more time to come back, so the chance and size describe slower moves. Lowering it judges after a few bars, so the chance reflects very short moves.
- bin_size
- Width of each distance band as a fraction. At the default 0.005 (0.5%) nearly all bars land in bin 0, so bands barely separate stretches. Smaller values split stretches into more bands. Zero divides by zero; negative values write into the wrong bins.
- num_bins
- How many bands exist; distances beyond the last band are lumped into it. At defaults only bins 0 and 1 are reached, so raising it changes nothing visible. Lowering it to 1 pools every stretch into one band.
- decay
- Forgetting for old outcomes. At 0 every outcome since the start counts equally. Above 0, each new outcome shrinks all bands by that fraction, so recent behaviour weighs more. Negative values are ignored and act like 0.
Pitfalls
- Direction is lost: a stretch 0.2% above the mean and one 0.2% below share a band and a chance, so the indicator says how stretched price is, not which way it will move.
- At defaults the bands barely separate anything: bin 0 holds at least about 95% of bars, so the chance is effectively one number for the whole chart.
- With decay at 0 the bands learn from the first loaded bar onward, so values depend on how much history is loaded and drift slowly across the chart.