Indicator · Pine Script v6 · Own pane

Oscillator

by TamTH-Dev· code credited to tamth_

This indicator calculates price midpoints derived from the highest high and lowest low over a customizable base period.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code123
Settings1inputs
LicenceNone statedfile: MPL-2.0
Last update5 weeks ago18 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

123 lines of Pine Script v6 from strategies/strategies5/Oscillator.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Oscillator.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tamth_

//@version=6
indicator("Oscillator", overlay = false, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500, max_bars_back = 5000)


//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
// Colors
color TRANSPARENT_COLOR = #ffffff00
color WHITE_COLOR       = #dee2e6
color BLACK_COLOR       = #000000
color RED_COLOR         = #F72585
color ORANGE_COLOR      = #fb5607
color YELLOW_COLOR      = #ffbe0b
color GREEN_COLOR       = #2a9d8f
color AQUA_COLOR        = #4CC9F0
color BLUE_COLOR        = #4361ee
color PURPLE_COLOR      = #3F37C9
color PINK_COLOR        = #B5179E
color LIGHT_GRAY_COLOR  = #364156
color DARK_GRAY_COLOR   = #212d40
color TEXT_COLOR        = #ced4da

//-----------------------------------------------------------------------------
// Common Variables
//-----------------------------------------------------------------------------
series int barIdx = bar_index

//-----------------------------------------------------------------------------
// Common Methods
//-----------------------------------------------------------------------------
debug(simple string txt) =>
    var label lbl = label.new(barIdx, na, txt, xloc.bar_index, yloc.price, color(na), label.style_none, WHITE_COLOR, size.large, text.align_left)
    label.set_xy(lbl, barIdx, ta.highest(10)[1])
    label.set_text(lbl, txt)

//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
baseLength = input.int(14, title = "Base Length", minval = 1)

//-----------------------------------------------------------------------------
// Methods
//-----------------------------------------------------------------------------
calcMidPoint(h, l) => (h + l) / 2

getHTF2x(tf) =>
    switch tf
        "1"     => "2"
        "3"     => "6"
        "5"     => "10"
        "15"    => "30"
        "30"    => "60"
        "60"    => "120"
        "120"   => "240"
        "240"   => "480"
        "1D"    => "2D"
        "1W"    => "2W"
        "1M"    => "2M"
        "4M"    => "8M"
        => na

getHTF4x(tf) =>
    switch tf
        "1"     => "4"
        "3"     => "12"
        "5"     => "20"
        "15"    => "60"
        "30"    => "120"
        "60"    => "240"
        "120"   => "480"
        "240"   => "960"
        "1D"    => "4D"
        "1W"    => "1M"
        "1M"    => "4M"
        "4M"    => "16M"
        => na

//-----------------------------------------------------------------------------
// Calculate
//-----------------------------------------------------------------------------
curHigh = ta.highest(high, baseLength)
curLow = ta.lowest(low, baseLength)
curMidPoint = calcMidPoint(curHigh, curLow)

htf2x = not na(getHTF4x(timeframe.period)) ? getHTF2x(timeframe.period) : timeframe.period
htf2xHigh = request.security(syminfo.tickerid, htf2x, ta.highest(high, baseLength))
htf2xLow = request.security(syminfo.tickerid, htf2x, ta.lowest(low, baseLength))
htf2xMidPoint = calcMidPoint(htf2xHigh, htf2xLow)

htf4x = not na(getHTF4x(timeframe.period)) ? getHTF4x(timeframe.period) : timeframe.period
htf4xHigh = request.security(syminfo.tickerid, htf4x, ta.highest(high, baseLength))
htf4xLow = request.security(syminfo.tickerid, htf4x, ta.lowest(low, baseLength))
htf4xMidPoint = calcMidPoint(htf4xHigh, htf4xLow)

divergence = close - curMidPoint
htf2xDivergence = close - htf2xMidPoint
htf4xDivergence = close - htf4xMidPoint

ltfColorUp = color.new(AQUA_COLOR, 60)
ltfColorDown = color.new(PURPLE_COLOR, 60)

htf2xColorUp = color.new(AQUA_COLOR, 60)
htf2xColorDown = color.new(PURPLE_COLOR, 60)

htf4xColorUp = color.new(AQUA_COLOR, 60)
htf4xColorDown = color.new(PURPLE_COLOR, 60)

//-----------------------------------------------------------------------------
// Render
//-----------------------------------------------------------------------------
plot(divergence, title = "LTF Divergence", color = (divergence >= 0 ? ltfColorUp : ltfColorDown), style = plot.style_columns, linewidth = 3, display = display.pane)
plot(htf2xDivergence, title = "HTF 2x Divergence", color = (htf2xDivergence >= 0 ? htf2xColorUp : htf2xColorDown), style = plot.style_columns, linewidth = 3, display = display.pane)
plot(htf4xDivergence, title = "HTF 4x Divergence", color = (htf4xDivergence >= 0 ? htf4xColorUp : htf4xColorDown), style = plot.style_columns, linewidth = 3, display = display.pane)
hline(0, "Middle Line", color = color.new(PINK_COLOR, 60), linestyle = hline.style_solid)

//-----------------------------------------------------------------------------

Overview

Oscillator evaluates these range boundaries across the current chart timeframe as well as dynamically scaled 2x and 4x higher timeframes via multi-timeframe requests. Rendered in a separate pane below the chart, it allows traders to compare localized price extremes and equilibrium points against broader timeframe structure. The primary setting configures the lookback period length.

Details

Published by

TamTH-Dev on GitHub

Code credit

tamth_, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Support & resistance

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.

Settings

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

SettingTypeDefaultVariable
Base Lengthint14baseLength
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

114 stars

This indicator combines a scaled Forecast Oscillator with a Point of Force state detector. The Forecast Oscillator calculates the percentage deviation of price from its linear regression curve and normalizes the output between 0 and 1, plotting a line in a sep

Indicator v4 Oscillators & momentumSupport & resistance Repaints

CCI DC

by be-thomas
65 stars

This indicator plots the Commodity Channel Index in a separate pane and surrounds it with a Donchian channel whose lookback length changes with volatility. It measures volatility as a ratio of short and long ATR values, then ranks that ratio and shortens or le

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 days ago · GPL-3.0 GitHub repository of CCI DC

WaveTrend 3D

by nersent
29 stars

WaveTrend 3D is a redesigned oscillator that implements the classic WaveTrend algorithm with kernel-based regression for trend reversal confirmation and multi-timeframe support. It calculates a smoothed oscillator line and displays a symmetrical three-dimensio

Indicator v5 Oscillators & momentumDivergence
Updated 11 months ago · Custom licence GitHub repository of WaveTrend 3D

Benso Pendulum

by benso87
24 stars

Benso Pendulum is an indicator that plots a customizable Relative Strength Index (RSI) oscillator in a separate pane on the price chart. It calculates the RSI using the specified source and period, applying dynamic colors that change based on overbought and ov

Indicator v5 Oscillators & momentumSupport & resistance
Updated 4 years ago · MPL-2.0 GitHub repository of Benso Pendulum
9 stars

This indicator plots currency strength values for EUR, USD, JPY, GBP, CHF, AUD, CAD, NZD and optionally XAU or XAG on a separate pane. It computes strength by comparing current pair closes to daily closes using broker-specific data from OANDA, FX or FOREXCOM.

Indicator v4 Oscillators & momentumSupport & resistance Repaints
Updated 5 years ago · None stated GitHub repository of 4th Dimension Currency Strength

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