Indicator · Pine Script v6 · Own pane

Stochastic Momentum Index (SMI)

by mihakralj

This indicator calculates the Stochastic Momentum Index in a separate pane.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code89
Settings5inputs
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

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

smi.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Stochastic Momentum Index (SMI)", "SMI", overlay=false)

//@function Calculates Stochastic Momentum Index oscillator
//@param source Source series to calculate SMI for
//@param k_period Lookback period for high/low range calculation
//@param k_smooth First smoothing period for raw SMI values
//@param d_smooth Second smoothing period for signal line
//@param blau Use Blau method (true) or Chande/Kroll method (false)
//@returns [%K, %D] values of Stochastic Momentum Index
smi(series float source, simple int k_period, simple int k_smooth, simple int d_smooth, simple bool blau) =>
    if k_period <= 0 or k_smooth <= 0 or d_smooth <= 0
        runtime.error("All periods must be positive")
    float src_clean = na(source) ? 0 : source
    if na(source)
        [na, na]
    else
        var array<float> high_buffer = array.new_float(0), var array<float> low_buffer = array.new_float(0)
        array.push(high_buffer, nz(high)), array.push(low_buffer, nz(low))
        if array.size(high_buffer) > k_period
            array.shift(high_buffer)
        if array.size(low_buffer) > k_period
            array.shift(low_buffer)
        highest_high = array.max(high_buffer), lowest_low = array.min(low_buffer)
        midpoint = (highest_high + lowest_low) / 2, range_half = (highest_high - lowest_low) / 2
        float a1 = 2.0 / (k_smooth + 1), float a2 = 2.0 / (k_smooth + 1), float a3 = 2.0 / (d_smooth + 1)
        var float e1 = 1.0, var float e2 = 1.0, var float e3 = 1.0, var bool warmup = true
        var float ema1_raw = 0.0, var float ema2_raw = 0.0, var float ema3_raw = 0.0
        var float first_ema = 0.0, var float k_value = 0.0, var float d_value = 0.0
        if blau
            raw_smi = range_half > 0 ? 100 * (src_clean - midpoint) / range_half : 0
            ema1_raw := a1 * (raw_smi - ema1_raw) + ema1_raw
            if warmup
                e1 *= (1 - a1), e2 *= (1 - a2), e3 *= (1 - a3)
                float c1 = 1.0 / (1.0 - e1), float c2 = 1.0 / (1.0 - e2), float c3 = 1.0 / (1.0 - e3)
                first_ema := ema1_raw * c1
                ema2_raw := a2 * (first_ema - ema2_raw) + ema2_raw
                k_value := ema2_raw * c2
                ema3_raw := a3 * (k_value - ema3_raw) + ema3_raw
                d_value := ema3_raw * c3
                warmup := math.max(math.max(e1, e2), e3) > 1e-10
            else
                first_ema := ema1_raw
                ema2_raw := a2 * (first_ema - ema2_raw) + ema2_raw
                k_value := ema2_raw
                ema3_raw := a3 * (k_value - ema3_raw) + ema3_raw
                d_value := ema3_raw
        else
            var float num_ema1 = 0.0, var float num_ema2 = 0.0, var float den_ema1 = 0.0, var float den_ema2 = 0.0
            var float num_first = 0.0, var float den_first = 0.0
            numerator = src_clean - midpoint, denominator = range_half
            ema1_raw := a1 * (numerator - ema1_raw) + ema1_raw
            num_ema1 := a1 * (denominator - num_ema1) + num_ema1
            if warmup
                e1 *= (1 - a1), e2 *= (1 - a2), e3 *= (1 - a3)
                float c1 = 1.0 / (1.0 - e1), float c2 = 1.0 / (1.0 - e2), float c3 = 1.0 / (1.0 - e3)
                num_first := ema1_raw * c1, den_first := num_ema1 * c1
                num_ema2 := a2 * (num_first - num_ema2) + num_ema2
                den_ema2 := a2 * (den_first - den_ema2) + den_ema2
                k_value := den_ema2 > 0 ? 100 * (num_ema2 * c2) / (den_ema2 * c2) : 0
                ema3_raw := a3 * (k_value - ema3_raw) + ema3_raw
                d_value := ema3_raw * c3
                warmup := math.max(math.max(e1, e2), e3) > 1e-10
            else
                num_first := ema1_raw, den_first := num_ema1
                num_ema2 := a2 * (num_first - num_ema2) + num_ema2
                den_ema2 := a2 * (den_first - den_ema2) + den_ema2
                k_value := den_ema2 > 0 ? 100 * num_ema2 / den_ema2 : 0
                ema3_raw := a3 * (k_value - ema3_raw) + ema3_raw
                d_value := ema3_raw
        [k_value, d_value]

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

// Inputs
i_k_period = input.int(10, "%K Period", minval=1, maxval=100, tooltip="Lookback period for high/low range calculation")
i_k_smooth = input.int(3, "%K Smooth", minval=1, maxval=20, tooltip="First smoothing period for raw SMI values")
i_d_smooth = input.int(3, "%D Smooth", minval=1, maxval=20, tooltip="Second smoothing period for signal line")
i_source = input.source(close, "Source", tooltip="Price series to analyze")
i_blau = input.bool(true, "Blau Method", tooltip="True: Blau (smooth raw SMI ratio), False: Chande/Kroll (smooth numerator & denominator first)")

// Calculation
[k_value, d_value] = smi(i_source, i_k_period, i_k_smooth, i_d_smooth, i_blau)

// Plots
plot(k_value, "SMI %K", color=color.yellow, linewidth=2)
plot(d_value, "SMI %D", color=color.blue, linewidth=2)

Overview

Stochastic Momentum Index (SMI) finds the highest high and lowest low over a lookback, measures the source relative to the range midpoint, and double-smooths that result into a %K line and a further-smoothed %D signal. The Blau method smooths the ratio directly; turning it off uses the Chande/Kroll method of smoothing the numerator and denominator separately. Period, smoothing, and source inputs change the calculation. It plots the oscillator only and does not issue trade entries or exits.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum

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
%K Periodint10i_k_period
%K Smoothint3i_k_smooth
%D Smoothint3i_d_smooth
Sourcesourceclosei_source
Blau Methodbooltruei_blau
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

Asymmetrical RSI

by everget
948 stars

Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t

Indicator v4 Oscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
261 stars

This indicator demonstrates an experimental graph-style scatter visualization within a separate pane using Pine Script arrays. It tracks two features across recent bars: the single-bar price change and a scaled 14-period Relative Strength Index. Values are loa

Indicator v4 Oscillators & momentum
Updated 4 years ago · None stated GitHub repository of Example: Graph Style - 4th Dimension RSI

KD指標

by TaichiS
219 stars

This script calculates and plots a Stochastic Oscillator (KD indicator) in a separate chart pane. It determines the fast stochastic value over a 9-period lookback, then applies a 3-period Simple Moving Average (SMA) to create the %K line, and a second 3-period

Indicator v4 Oscillators & momentum
Updated 5 years ago · None stated GitHub repository of KD指標

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