ConditionalVolatility
How volatile the next bars have typically been after price sat this close to its recent low and high.
Each bar it measures how far the close sits above the lowest low of the last low_window bars and below the highest high of the last high_window bars, as fractions (0.0004 is 0.04%). That pair picks a cell in a grid whose width is bin_size. It also records the standard deviation of the next forward_bars one-minute returns and files it under the cell the bar was in, once those bars have closed. Expected vol is the average of everything filed in the current cell, shown only after min_samples filings. Nothing is looked ahead: a cell learns only from windows that have already finished.
How to read it
- Each output draws in its own pane below the price; none of them sit on the price scale.
- The distance lines are fractions near zero on SPY. 0 means the close is exactly on the recent low or high; the median reading is about 0.04%.
- Expected vol is a per-bar return spread. On SPY, 90% of readings sat between 0.000138 and 0.000151, so a higher line means bars after this kind of position were more volatile.
- Read the sample count before trusting expected vol: it stays blank until the cell has min_samples filings and only grows over the chart.
What it outputs
- Dist from low
- How far the close sits above the lowest low of the last low_window bars, as a fraction. Zero means the close is on that low.
- Dist from high
- How far the highest high of the last high_window bars sits above the close, as a fraction. Zero means the close is on that high.
- Expected vol
- Average standard deviation of the next forward_bars one-minute returns, over past bars in the same cell. Blank until the cell has min_samples.
- Sample count
- How many completed observations feed the current cell. It only rises over the chart unless decay is set above zero.
Settings
- low_window
- Bars back for the lowest low the close is measured against. Longer windows reach a lower low, so the distance from low grows and moves into higher cells; shorter windows keep it small.
- high_window
- Bars back for the highest high the close is measured against. Longer windows reach a higher high, so the distance from high grows; shorter windows keep it small.
- forward_bars
- How many bars ahead each volatility reading looks. Longer gives a steadier spread but files each observation later, so expected vol learns slowly. At 1 the spread is over a single return, which is always zero, so expected vol reads 0.
- bin_size
- Width of each cell as a fraction; 0.01 is 1%. Raising it packs more distances into the same cell, lowering it separates them. Zero or negative values break the cell lookup, so keep it positive.
- num_bins
- Cells per axis. Any distance past num_bins times bin_size lands in the last cell. More cells separate far distances; fewer lump them together.
- min_samples
- Filings a cell needs before expected vol shows. Raising it leaves the start of the chart and rare cells blank for longer; at 1 a single filing is enough, so the value can be noisy.
- decay
- How fast old filings fade; 0 keeps all history. Above 0, every cell shrinks each time a bar completes, so expected vol follows recent volatility sooner. At 0.2 or more, a cell filed on every bar stays under min_samples of 5 and expected vol goes blank.
Pitfalls
- At default bin_size 0.01, every bar in the SPY sample fell into the same cell, since no distance reached 1%. Expected vol is then one running average and barely moves with position.
- The expected vol band is narrow: it is a learned baseline that changes slowly, not a forecast that reacts to the current bar.
- Negative decay is accepted by the range but does nothing, and forward_bars of 1 reads zero. Keep decay at 0 or above and forward_bars at 2 or more.