Volatility expansion detector
Marks when recent bars' high-low ranges run at least 1.5 times wider than the bars just before them.
For each one-minute bar the indicator records the high-low range and keeps the last `window` ranges (bars with zero range are skipped). It splits that history in half and divides the average of the recent half by the average of the older half. When that ratio reaches `expansion_threshold`, the ratio is emitted and drawn; otherwise nothing is drawn. It measures only how wide bars are, not which way price moves or what follows.
How to read it
- Markers sit on the candles where the test passes. A run of consecutive markers is one widening episode.
- On the September 2026 SPY sample with defaults, markers appear on about one bar in eight, roughly 50 episodes a day, each about 2 to 3 bars long.
- A marker says the recent bars are wider than the earlier ones. It does not say price will move, or which way.
What it outputs
- Range expansion
- The recent half's average high-low range divided by the older half's. Drawn only at or above the threshold; a higher number means a sharper widening.
When it fires
The recent half of the window averages at least the threshold times the older half's bar range, with the current bar included. It means bars have been widening over the recent stretch. Nothing in the test says price will move next.
Settings
- window
- Bars of range history, split into an older and a recent half (odd windows give the extra bar to the recent half). Shorter reacts within minutes and marks more often; longer reacts later. Below 2 the Python code raises ZeroDivisionError.
- expansion_threshold
- Minimum recent-to-older range ratio for a marker. At 2 only bars with recent range double the older one mark, so markers get rarer and stronger. Near 1 they mark whenever the recent half is wider. At 0 or below, every bar marks once the window fills.
Pitfalls
- It measures bar width, not direction or follow-through. The docstring says it tracks exponential expansion that precedes explosive moves; the code is a plain ratio of two averages and checks no later move.
- Bars with zero high-low range are skipped, not counted, so on quiet data the window reaches further back in time than its bar count suggests.
- The first window's worth of nonzero-range bars draw nothing while history fills. Keep window at 2 or more.