Indicator · Pine Script v6 · Own pane

Sniper

by TamTH-Dev· code credited to tamth_

Sniper is a custom oscillator indicator that derives Bullish and Bearish lines from close and open prices using a smoothing factor based on trend length.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code143
Settings14inputs
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

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

Sniper.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("Sniper", "Sniper", overlay = false, precision = 2, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 1000, max_bars_back = 1000)


//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
// Colors
color TRANSPARENT_COLOR = color.new(#000000, 100)
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
//-----------------------------------------------------------------------------
// Bar index and input
series int barIdx = bar_index

//-----------------------------------------------------------------------------
// Common Methods
//-----------------------------------------------------------------------------
// Debug label function
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)

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


//-----------------------------------------------------------------------------
// Oscillator
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
oscGrp      = "Oscillator"
oscTrendLen = input.int(50, "Trend Length", group = oscGrp)
oscSigLen   = input(9, "Signal Length", group = oscGrp)

//-----------------------------------------------------------------------------
// Calculate
//-----------------------------------------------------------------------------
var oscAlpha = 2 / (oscTrendLen + 1)
var oscUp1 = 0., var oscUp2 = 0.
var oscDn1 = 0., var oscDn2 = 0.

oscClose = close
oscOpen = open

oscUp1 := nz(math.max(oscClose, oscOpen, oscUp1[1] - (oscUp1[1] - oscClose) * oscAlpha), oscClose)
oscUp2 := nz(math.max(oscClose * oscClose, oscOpen * oscOpen, oscUp2[1] - (oscUp2[1] - oscClose * oscClose) * oscAlpha), oscClose * oscClose)

oscDn1 := nz(math.min(oscClose, oscOpen, oscDn1[1] + (oscClose - oscDn1[1]) * oscAlpha), oscClose)
oscDn2 := nz(math.min(oscClose * oscClose, oscOpen * oscOpen, oscDn2[1] + (oscClose * oscClose - oscDn2[1]) * oscAlpha), oscClose * oscClose)

oscBull = math.sqrt(oscDn2 - oscDn1 * oscDn1)
oscBear = math.sqrt(oscUp2 - oscUp1 * oscUp1)
oscSig = ta.ema(math.max(oscBull, oscBear), oscSigLen)

//-----------------------------------------------------------------------------
// Render
//-----------------------------------------------------------------------------
plot(oscBull, 'Bullish Line', AQUA_COLOR, display = display.pane)
plot(oscBear, 'Bearish Line', PURPLE_COLOR, display = display.pane)
plot(oscSig, 'Signal Line', ORANGE_COLOR, display = display.pane)

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


//-----------------------------------------------------------------------------
// KAMAs
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
kamaGrp         = "Kaufman Adaptive Moving Average"
kamaShowed      = input.bool(true, "Show", group = kamaGrp)
kamaSrc         = input.source(close, title = "Source", group = kamaGrp)

kama1Grp        = "K1"
kama1Showed     = input.bool(true, title = "K1", group = kamaGrp, inline = kama1Grp)
kama1Tf         = input.timeframe("", title = "", group = kamaGrp, inline = kama1Grp)
kama1Len        = input.int(21, title = "", group = kamaGrp, inline = kama1Grp)
kama1FastEmaLen = input.int(2, title = "", group = kamaGrp, inline = kama1Grp)
kama1SlowEmaLen = input.int(30, title = "", group = kamaGrp, inline = kama1Grp)

kama2Grp        = "K2"
kama2Showed     = input.bool(true, title = "K2", group = kamaGrp, inline = kama2Grp)
kama2Tf         = input.timeframe("", title = "", group = kamaGrp, inline = kama2Grp)
kama2Len        = input.int(21, title = "", group = kamaGrp, inline = kama2Grp)
kama2FastEmaLen = input.int(2, title = "", group = kamaGrp, inline = kama2Grp)
kama2SlowEmaLen = input.int(30, title = "", group = kamaGrp, inline = kama2Grp)

//-----------------------------------------------------------------------------
// Methods
//-----------------------------------------------------------------------------
getKama(src, len, fastEmaLen, slowEmaLen) =>
    mom = math.abs(ta.change(src, len))
    volatility = math.sum(math.abs(ta.change(src)), len)
    efficiencyRatio = volatility != 0 ? mom / volatility : 0
    fastAlpha = 2 / (fastEmaLen + 1)
    slowAlpha = 2 / (slowEmaLen + 1)
    alpha = math.pow(efficiencyRatio * (fastAlpha - slowAlpha) + slowAlpha, 2)
    kama = 0.0
    kama := alpha * src + (1 - alpha) * nz(kama[1], src)

getDefHtf() =>
    switch timeframe.period
        "3"   => "30"
        "5"   => "60"
        "15"  => "240"
        "30"  => "480"
        "60"  => "D"
        "240" => "W"
        "1D"  => "M"
        "1M"  => "12M"

//-----------------------------------------------------------------------------
// Calculate
//-----------------------------------------------------------------------------
kama1 = request.security(syminfo.tickerid, kama1Tf, getKama(kamaSrc, kama1Len, kama1FastEmaLen, kama1SlowEmaLen), gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off)
kama2 = request.security(syminfo.tickerid, kama2Tf != "" ? kama2Tf : getDefHtf(), getKama(kamaSrc, kama2Len, kama2FastEmaLen, kama2SlowEmaLen), gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off)

//-----------------------------------------------------------------------------
// Render
//-----------------------------------------------------------------------------
plot(kamaShowed and kama1Showed ? kama1 : na, title = "KAMA 1", linewidth = 1, color = AQUA_COLOR, display = display.pane, force_overlay = true)
plot(kamaShowed and kama2Showed ? kama2 : na, title = "KAMA 2", linewidth = 1, color = PURPLE_COLOR, display = display.pane, force_overlay = true)

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

Overview

These lines feed into a signal line calculated as EMA over the signal length. The indicator plots Bullish Line, Bearish Line and Signal Line in a separate pane to highlight momentum shifts. Main settings control trend length and signal length for responsiveness. It draws only on the price chart oscillator pane without additional overlays.

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

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
Trend Lengthint50oscTrendLen
Signal Lengthint9oscSigLen
ShowbooltruekamaShowed
SourcesourceclosekamaSrc
K1booltruekama1Showed
kama1Tftimeframekama1Tf
kama1Lenint21kama1Len
kama1FastEmaLenint2kama1FastEmaLen
kama1SlowEmaLenint30kama1SlowEmaLen
K2booltruekama2Showed
kama2Tftimeframekama2Tf
kama2Lenint21kama2Len
Show all 14 settings
SettingTypeDefaultVariable
kama2FastEmaLenint2kama2FastEmaLen
kama2SlowEmaLenint30kama2SlowEmaLen
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