Bollinger Bands
Is the price stretched compared with its usual range?
A 20-day average with a band 2 standard deviations above and below it, so the band widens when the price swings more.
Bollinger Bands on a chart of past prices
Settings: move a slider and the chart redraws
How many closes the average and the spread are measured over.
Wider bands are touched less often.
What it measures
The middle line is the 20-day simple moving average of the close. The upper and lower bands sit 2 standard deviations above and below it.
Standard deviation measures how widely the last 20 closes are spread around their average, in ₹. When the price swings a lot the bands widen; when it is quiet they squeeze together.
Most closes land inside the bands, so a close outside them is unusual: either a strong breakout or a stretched price.
How traders read it
- A close below the lower band: unusually low compared with the last 20 days. Above the upper band: unusually high.
- The classic beginner's rule, tested here: buy a close below the lower band, sell when the price gets back above the middle line. Marked on the chart.
- A squeeze (very narrow bands) means volatility is low. A bigger move often follows, in either direction.
- In a strong trend the price can walk along a band, closing at or outside it day after day.
The traps
Below the band is not “cheap”
In a sharp fall the price can close below the lower band again and again. Buying the first close below it can mean catching a falling price.
A squeeze has no direction
Narrow bands say a big move may be coming, not which way.
Not a probability
Price moves are not neatly bell-shaped, so 'about 95% inside the bands' is a rule of thumb. Count how often the price leaves the bands on this chart.
Test the classic rule: Bollinger bounce
Waiting for prices…
Quick check
Waiting for prices…
Use it in a script
function run(bars, ta, helpers) {
const closes = helpers.closes(bars);
const mid = ta.sma(closes, 20), sd = ta.stdev(closes, 20);
const signals = [];
for (let i = 0; i < bars.length; i++) {
const lower = mid[i] - 2 * sd[i];
if (closes[i] < lower) signals.push(helpers.buy(i)); // closed below the lower band
else if (closes[i] > mid[i]) signals.push(helpers.sell(i)); // back above the middle line
}
return helpers.finalize(signals);
}This is the rule tested above, with the settings on your sliders, and it gives exactly the same buy and sell candles. Paste it into the Scripts drawer of the chart workbench, or save it and compare it across stocks in the Strategy Lab. New to scripts? The Writing strategies track starts from zero.