Mean reversion
Flags price pushed past its Bollinger bands; at defaults the oversold and combined flags never switch off.
Combines a Bollinger band check on the close with a long RSI, a balance of volume-weighted up and down moves scaled from -1 to +1. The four outputs are a combined mean-reversion flag, a 0-to-1 stretch reading, an oversold flag and an overbought flag. Oversold means the close is under the lower band or the RSI is below 0.3. Overbought means the close is over the upper band or the RSI is above 0.7. The RSI looks back rsi_window times 100 bars, so the first 1400 bars give no output at defaults.
How to read it
- The flags are drawn on the candles. At defaults the oversold and combined flags sit on every candle after warm-up, so they do not separate entries from noise.
- Overbought is the one flag that comes and goes. It marks brief bursts, mostly closes above the upper band.
- The stretch pane below the price reads zero through the middle of the bands and on the band lines. It climbs toward 1 once price is past a band.
What it outputs
- Mean-reversion flag
- Marks bars where oversold or overbought holds, or an RSI turn near the middle of the bands. At defaults it is on for every bar after warm-up.
- Stretch
- How far price sits past a band, 0 to 1. Zero through the middle 60% of the bands and exactly on the band lines. It rises toward 0.6 near the 20% and 80% points and reaches 1 past a band.
- Oversold
- Marks bars where the close is below the lower band or the RSI is under 0.3. At defaults the RSI keeps it on for every bar after warm-up.
- Overbought
- Marks bars where the close is above the upper band or the RSI is over 0.7. At defaults it fires on about 5% of bars, mostly on closes above the upper band.
When it fires
The overbought flag fires when the close is above the upper band or the RSI is over 0.7. That is a brief push above the band, read as a stretched high. Each burst lasts about two bars. The oversold and combined flags stay on at defaults, so they mark nothing useful.
Settings
- window
- Length of the RSI-turn history. Values of 3 or more change nothing visible, because only the last three RSI readings are used. Values of 1 or 2 switch off the RSI-turn checks behind the combined flag.
- rsi_window
- RSI look-back in units of 100 bars, so the default 14 means 1400 one-minute bars. Raising it slows the RSI and lengthens the warm-up. Lowering it makes the RSI swing faster. The 0.3 and 0.7 cut-offs stay fixed either way.
- bb_window
- Bars behind the Bollinger middle and spread. Shorter bands hug price, so closes break the upper band more often and the overbought flag fires more. Longer bands move slowly and are broken less.
- bb_mult
- Band width in standard deviations. Raising it pushes the bands out, so the overbought flag and the stretch reading fire less. Lowering it narrows the bands. Values below 0 swap the upper and lower bands, which breaks the reading.
Pitfalls
- The RSI runs from -1 to +1, but the 0.3 and 0.7 cut-offs only make sense on a 0-to-1 scale. At defaults the oversold leg is on for every bar, and the combined flag inherits that.
- No output for the first rsi_window times 100 bars, 1400 one-minute bars or about 23 hours at defaults, so a freshly opened chart is blank at the left edge.
- The stretch reading falls back to zero on the band line itself. A price just past the band reads lower than one a little inside it, so the pane is not a steady distance measure.