Skip to content

Rolling Stdev

Math · Rolling

Rolling Stdev node on the canvas

Population standard deviation of the trailing N bars (ddof=0, matching Pine's ta.stdev). Pairs with Rolling Mean for z-scores and Bollinger-style bands on any series.

Rolling Stdev measures how spread-out a series has been over the last N bars — its statistical volatility. Low values mean the input has been calm and tightly clustered; high values mean it's been swinging. It's the dispersion half of any z-score or Bollinger-style band you want to build on your own data.

How it works

Each bar it takes the trailing window values and computes their population standard deviation (ddof = 0) — deliberately matching Pine's ta.stdev so an exported strategy behaves identically. Population (not sample) means it divides by N, not N−1. The first window − 1 bars are NaN while the window fills. It's lookahead-free.

When to use it

Use it to turn any series into a volatility reading, or as the width term in a custom band. Pair it with Rolling Mean to build a z-score — (value − mean) ÷ stdev — which normalises how far the current value sits from its recent average in units of its own volatility. That's the honest way to compare "how stretched" two different series are.

Example

Home-grown Bollinger Bands on any series: take Rolling Mean (the mid-line) and Rolling Stdev over the same window, multiply the stdev by 2 with Multiply, then Add / Subtract it to the mean for the upper and lower edges. Works on an RSI or a spread, not just price.

Tips & gotchas

  • Population stdev (ddof = 0) — matches Pine's ta.stdev, so exports stay faithful.
  • A flat window → 0, which can divide-by-zero in a z-score; guard it if needed.
  • First window − 1 bars are NaN.
  • It's a width, not a direction — pair with a mean to know which side of normal you're on.

Inputs

Socket Type What to wire in
In series / bars Source series. BARS input uses close.

Outputs

Output Type Plots as Description
stdev series Line · sub-pane Per-bar rolling standard deviation.

Parameters

Parameter Type Default What it does
Window (bars) number · 2–500 14 Bars in the rolling window.

Reference auto-generated from the block catalog · category Math.