Indicator · Pine Script v6 · Own pane

Indicator Oscillator Template

by MoDarK-MK· code credited to {{SHORTTITLE}}

This template provides a foundational structure for building momentum oscillators in a separate pane below the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code189
Settings8inputs
LicenceMPL-2.0
Last update7 weeks ago4 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

189 lines of Pine Script v6 from assets/templates/indicator_oscillator_template.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

indicator_oscillator_template.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © {{SHORTTITLE}}

//@version=6
indicator(
     "{{TITLE}}", shorttitle="{{SHORTTITLE}}", overlay=false,
     max_labels_count=500)

// Oscillator panel template — designed for a separate sub-pane.
// Includes: hlines for overbought/oversold levels, histogram plot,
// signal line, gradient coloring, and a live mini-dashboard.
//
// Replace the RSI calculation with your own oscillator logic.
// Keep overlay=false: oscillators that fight with price candles
// are the most common cause of "why does my indicator look wrong".

// ————— Constants
string THEME_DARK  = "Dark"
string THEME_LIGHT = "Light"
string THEME_AUTO  = "Auto"
color  BULL_DARK   = #089981
color  BEAR_DARK   = #f23645
color  BULL_LIGHT  = #00796b
color  BEAR_LIGHT  = #c62828

// ————— Inputs
int    lengthInput     = input.int(
     14, "Length", minval=2, maxval=500, group="Settings",
     tooltip="Oscillator lookback period.")
float  sourceInput     = input.source(
     close, "Source", group="Settings",
     tooltip="Price series to feed the oscillator.")
int    obLevelInput    = input.int(
     70, "Overbought Level", minval=51, maxval=99, group="Levels",
     tooltip="Readings above this are considered overbought.")
int    osLevelInput    = input.int(
     30, "Oversold Level", minval=1, maxval=49, group="Levels",
     tooltip="Readings below this are considered oversold.")
bool   showSignalInput = input.bool(
     true, "Show Signal Line", group="Settings",
     tooltip="Plots a smoothed signal line over the oscillator.")
int    signalLenInput  = input.int(
     9, "Signal Length", minval=1, group="Settings",
     tooltip="EMA length for the signal line.")
string themeInput      = input.string(
     THEME_DARK, "Theme", options=[THEME_DARK, THEME_LIGHT, THEME_AUTO],
     group="Appearance",
     tooltip="Match to your chart. Auto reads the chart background.")
bool   showDashInput   = input.bool(
     true, "Show Mini Dashboard", group="Appearance",
     tooltip="Small panel showing current value and state.")

// ————— Function declarations

// @function Returns true when chart background luminance suggests a light chart.
_isLightChart() =>
    r = color.r(chart.bg_color)
    g = color.g(chart.bg_color)
    b = color.b(chart.bg_color)
    r * 0.299 + g * 0.587 + b * 0.114 > 128.0

// @function Bull color for the selected theme.
getBullColor(string theme) =>
    switch theme
        THEME_LIGHT => BULL_LIGHT
        THEME_AUTO  => _isLightChart() ? BULL_LIGHT : BULL_DARK
        =>             BULL_DARK

// @function Bear color for the selected theme.
getBearColor(string theme) =>
    switch theme
        THEME_LIGHT => BEAR_LIGHT
        THEME_AUTO  => _isLightChart() ? BEAR_LIGHT : BEAR_DARK
        =>             BEAR_DARK

// @function Primary text color for the selected theme.
// library-sync-exempt: this variant supports a third theme, THEME_AUTO, which
// follows the chart's own light/dark setting. The library has only two, because
// a published library cannot read the chart it is imported into.
getTextColor(string theme) =>
    switch theme
        THEME_LIGHT => #131722
        THEME_AUTO  => _isLightChart() ? #131722 : #d1d4dc
        =>             #d1d4dc

// @function Muted text color for the selected theme.
// library-sync-exempt: this variant supports a third theme, THEME_AUTO, which
// follows the chart's own light/dark setting. The library has only two, because
// a published library cannot read the chart it is imported into.
getMutedColor(string theme) =>
    switch theme
        THEME_LIGHT => #4a4e58
        THEME_AUTO  => _isLightChart() ? #4a4e58 : #b2b5be
        =>             #b2b5be

// @function Panel background for the selected theme.
// library-sync-exempt: this variant supports a third theme, THEME_AUTO, which
// follows the chart's own light/dark setting. The library has only two, because
// a published library cannot read the chart it is imported into.
getPanelColor(string theme, int transp) =>
    color base = switch theme
        THEME_LIGHT => #ffffff
        THEME_AUTO  => _isLightChart() ? #ffffff : #131722
        =>             #131722
    color.new(base, transp)

// @function One label/value row in a table.
dashRow(table t, int row, string lbl, string val, color lblCol, color valCol) =>
    table.cell(t, 0, row, lbl, text_color=lblCol, text_size=size.small,
         text_halign=text.align_left)
    table.cell(t, 1, row, val, text_color=valCol, text_size=size.small,
         text_halign=text.align_right)

// ————— Calculations
color bullColor  = getBullColor(themeInput)
color bearColor  = getBearColor(themeInput)
color textColor  = getTextColor(themeInput)
color mutedColor = getMutedColor(themeInput)

// ── Replace this block with your own oscillator ──────────────────────
float oscValue   = ta.rsi(sourceInput, lengthInput)
// ─────────────────────────────────────────────────────────────────────

float signalLine = ta.ema(oscValue, signalLenInput)
float histogram  = oscValue - signalLine

bool  isOverbought = oscValue >= obLevelInput
bool  isOversold   = oscValue <= osLevelInput
bool  isBullish    = oscValue > 50

// ————— Visuals

// Horizontal reference lines
hline(obLevelInput, "Overbought", color=color.new(bearColor, 50),
     linestyle=hline.style_dashed, linewidth=1)
hline(osLevelInput, "Oversold",   color=color.new(bullColor, 50),
     linestyle=hline.style_dashed, linewidth=1)
hline(50, "Midline", color=color.new(color.gray, 60),
     linestyle=hline.style_dotted, linewidth=1)

// Gradient oscillator line — color intensity shows distance from midline
color gradientColor = color.from_gradient(oscValue, osLevelInput, obLevelInput,
     bearColor, bullColor)
oscPlot = plot(oscValue, "Oscillator", color=gradientColor, linewidth=2)

// Signal line
plot(showSignalInput ? signalLine : na, "Signal",
     color=color.new(textColor, 30), linewidth=1)

// Histogram bars — above midline = bull, below = bear
histColor = histogram > 0
     ? (histogram > histogram[1] ? bullColor : color.new(bullColor, 50))
     : (histogram < histogram[1] ? bearColor : color.new(bearColor, 50))
plot(histogram, "Histogram", style=plot.style_columns,
     color=histColor, linewidth=1)

// Midline plot for fill()  — must be a plot ID
midPlot = plot(50, "Mid (fill)", display=display.none)

// Fill area between oscillator and midline
fill(oscPlot, midPlot,
     color = isBullish ? color.new(bullColor, 88) : color.new(bearColor, 88),
     title = "Oscillator Fill")

// Extreme zone backgrounds
bgcolor(isOverbought ? color.new(bearColor, 92) : na, title="Overbought Zone")
bgcolor(isOversold   ? color.new(bullColor, 92) : na, title="Oversold Zone")

// Mini dashboard
var table dash = table.new(position.top_right, 2, 3,
     bgcolor=getPanelColor(themeInput, 15),
     border_color=getPanelColor(themeInput, 80), border_width=1,
     frame_color=color.new(mutedColor, 70), frame_width=1)

if showDashInput and barstate.islast
    string stateStr = isOverbought ? "Overbought" : isOversold ? "Oversold" : "Neutral"
    color  stateCol = isOverbought ? bearColor : isOversold ? bullColor : mutedColor
    table.cell(dash, 0, 0, "{{SHORTTITLE}}", text_color=textColor,
         text_size=size.normal, text_halign=text.align_center)
    table.cell(dash, 1, 0, "", text_color=textColor)
    table.merge_cells(dash, 0, 0, 1, 0)
    dashRow(dash, 1, "Value", str.tostring(oscValue, "#.00"), mutedColor, textColor)
    dashRow(dash, 2, "State", stateStr, mutedColor, stateCol)

// ————— Alerts
alertcondition(ta.crossover(oscValue, osLevelInput),  "Oversold Exit",   "Oscillator crossed above oversold level")
alertcondition(ta.crossunder(oscValue, obLevelInput), "Overbought Exit", "Oscillator crossed below overbought level")
alertcondition(ta.crossover(oscValue, 50),            "Midline Bull",    "Oscillator crossed above midline")
alertcondition(ta.crossunder(oscValue, 50),           "Midline Bear",    "Oscillator crossed below midline")

Overview

Indicator Oscillator Template features configurable lookback periods, overbought and oversold horizontal reference levels, and an optional EMA signal line. Dynamic theme adjustments support dark, light, and automatic chart detection. An optional mini dashboard displays real-time oscillator values and market status directly on the chart panel.

Details

Published by

MoDarK-MK on GitHub

Code credit

{{SHORTTITLE}}, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Screeners & dashboards

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

ci-cdindicatorslinterpine-scriptpythonstrategiestradingview

Settings

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

SettingTypeDefaultVariable
Lengthint14lengthInput
SourcesourceclosesourceInput
Overbought Levelint70obLevelInput
Oversold Levelint30osLevelInput
Show Signal LinebooltrueshowSignalInput
Signal Lengthint9signalLenInput
ThemestringTHEME_DARKthemeInput
Show Mini DashboardbooltrueshowDashInput
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 scans a pasted list of symbols for RSI directional momentum and shows matching long and short signals in a table in a separate pane. The user chooses continuous break, continuous retracement, flip break, flip retracement, divergence, or hidden d

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

This indicator plots the RSI oscillator on the main chart and displays its value distribution in a table positioned at the top right. The script calculates the relative strength index using the input source and length, then plots horizontal lines at 0, 50, and

Indicator v4 Oscillators & momentumScreeners & dashboards
Updated 4 years ago · None stated GitHub repository of Tables-003 Oscillator Distribution

Market Speedometer

by TradersPost
218 stars

Market Speedometer plots a 0-100 market speed reading in a separate pane. It measures movement by bar-to-bar change, true range, or a short average of recent bars, then ranks that movement against ATR and a percentile lookback. An EMA smooths the reading, and

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Market Speedometer

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama
114 stars

Calculates normalized reversal metrics across up to ten Forex currency pairs using user-selected moving average methods, including HarmonicMA, EMA, SMA, or WMA. The indicator identifies overbought, oversold, and mean-crossing conditions using a configurable th

Indicator v4 Screeners & dashboardsMean reversion
Updated 1 year ago · None stated GitHub repository of Multi-Pair Trend Reversal Widget

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