Indicator · Pine Script v6 · Own pane

Standard Deviation (STDDEV)

by mihakralj

The Standard Deviation (STDDEV) indicator calculates the standard deviation of the input source series over a user-defined period.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code41
Settings2inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

41 lines of Pine Script v6 from lib/statistics/stddev/stddev.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

stddev.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Standard Deviation (STDDEV)", "STDDEV", overlay=false)

//@function Calculates the standard deviation using a single pass with a circular buffer.
//@param src {series float} Source series.
//@param len {int} Lookback length. `len` > 0.
//@returns {series float} Standard deviation of `src` for `len` bars back. Returns `na` if not enough data.
stddev(series float src, int len) =>
    if len <= 0
        runtime.error("Period must be greater than 0")
    var int p = math.max(1, len)
    var array<float> buffer = array.new_float(p, na)
    var int head = 0,  var int count = 0
    var float sum = 0.0, var float sumSq = 0.0
    float oldest = array.get(buffer, head)
    if not na(oldest)
        sum -= oldest
        sumSq -= oldest * oldest
        count -= 1
    float val = nz(src)
    sum += val
    sumSq += val * val
    count += 1
    array.set(buffer, head, val)
    head := (head + 1) % p
    count > 1 ? math.sqrt(math.max(0.0, (sumSq / count) - math.pow(sum / count, 2))) : 0.0


// ---------- Main loop ----------

// Inputs
i_period = input.int(14, "Period", minval=1) // Default period 14
i_source = input.source(close, "Source")

// Calculation
stddev_value = stddev(i_source, i_period)

// Plot
plot(stddev_value, "StdDev", color=color.yellow, linewidth=2) // Changed color

Overview

Standard Deviation (STDDEV) employs a circular buffer for O(1) streaming computation, ensuring efficient memory usage. The indicator plots the standard deviation value in a separate pane as a yellow line with a width of 2. The primary setting adjusts the lookback period, defaulting to 14, and selects the data source, which defaults to the closing price. This volatility measure helps identify periods of high and low price dispersion. It does not repaint on the live bar and provides no exit signals as it is an indicator, not a strategy.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Periodint14i_period
Sourcesourceclosei_source
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This indicator calculates the distribution of close-to-close percentage changes using rate of change on closing prices. It bins percentage changes into intervals of 0.25 percent increments from negative to positive values and plots a normalized cumulative hist

Indicator v4 Volatility & bands
Updated 10 days ago · GPL-3.0 GitHub repository of Close-to-Close % Change Distribution

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
330 stars

This indicator plots candle range and open-to-close movement as percentages in a separate pane. Range is the high-low difference divided by the low, and change is the close-open difference divided by the open. Both series draw as columns. Teal columns show ran

Indicator v5 Volatility & bands
Updated 2 months ago · None stated GitHub repository of Percent & Volatility [Alorse]

Mojito v3 Strategy

by namuan
318 stars

The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe

Indicator v5 Volatility & bands
Updated 2 months ago · MIT GitHub repository of Mojito v3 Strategy

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers