Indicator · Pine Script v6 · On the chart

Advance Trading Script

by devgaganin

This overlay indicator applies a recursive multi-pole filter to a chosen price source and is set up to scale that filter with a filtered true range.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code161
Settings6inputs
LicenceGPL-3.0
Last update1 year ago30 Jan 2025

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

161 lines of Pine Script v6 from TradingView/ATMA v6.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

ATMA v6.pine
//@version=6
indicator(title="Advance Trading Script v6 © devgagan.in", shorttitle="ATMA v6", overlay=true)

// Filter function 
f_filt9x (_a, _s, _i) =>
    int _m2 = 0
    int _m3 = 0
    int _m4 = 0
    int _m5 = 0
    int _m6 = 0
    int _m7 = 0
    int _m8 = 0
    int _m9 = 0
    float _f = .0
    _x = (1 - _a)
    
    // Weights.
    if _i == 9
        _m2 := 36
        _m3 := 84
        _m4 := 126
        _m5 := 126
        _m6 := 84
        _m7 := 36
        _m8 := 9
        _m9 := 1
    else if _i == 8
        _m2 := 28
        _m3 := 56
        _m4 := 70
        _m5 := 56
        _m6 := 28
        _m7 := 8
        _m8 := 1
    else if _i == 7
        _m2 := 21
        _m3 := 35
        _m4 := 35
        _m5 := 21
        _m6 := 7
        _m7 := 1
    else if _i == 6
        _m2 := 15
        _m3 := 20
        _m4 := 15
        _m5 := 6
        _m6 := 1
        _m7 := 0
    else if _i == 5
        _m2 := 10
        _m3 := 10
        _m4 := 5
        _m5 := 1
        _m6 := 0
    else if _i == 4
        _m2 := 6
        _m3 := 4
        _m4 := 1
        _m5 := 0
    else if _i == 3
        _m2 := 3
        _m3 := 1
        _m4 := 0
    else if _i == 2
        _m2 := 1
        _m3 := 0
    else
        _m2 := 0

    // Filter
    _f := math.pow(_a, _i) * nz(_s) +
          _i * _x * nz(_f[1]) -
          (_i >= 2 ? _m2 * math.pow(_x, 2) * nz(_f[2]) : 0) + 
          (_i >= 3 ? _m3 * math.pow(_x, 3) * nz(_f[3]) : 0) - 
          (_i >= 4 ? _m4 * math.pow(_x, 4) * nz(_f[4]) : 0) + 
          (_i >= 5 ? _m5 * math.pow(_x, 5) * nz(_f[5]) : 0) - 
          (_i >= 6 ? _m6 * math.pow(_x, 6) * nz(_f[6]) : 0) + 
          (_i >= 7 ? _m7 * math.pow(_x, 7) * nz(_f[7]) : 0) - 
          (_i >= 8 ? _m8 * math.pow(_x, 8) * nz(_f[8]) : 0) + 
          (_i == 9 ? _m9 * math.pow(_x, 9) * nz(_f[9]) : 0)

    _f

// 9 var declaration function
f_pole (_a, _s, _i) =>
    _f1 = f_filt9x(_a, _s, 1)
    _f2 = (_i >= 2 ? f_filt9x(_a, _s, 2) : 0)
    _f3 = (_i >= 3 ? f_filt9x(_a, _s, 3) : 0)
    _f4 = (_i >= 4 ? f_filt9x(_a, _s, 4) : 0)
    _f5 = (_i >= 5 ? f_filt9x(_a, _s, 5) : 0)
    _f6 = (_i >= 6 ? f_filt9x(_a, _s, 6) : 0)
    _f7 = (_i >= 2 ? f_filt9x(_a, _s, 7) : 0)
    _f8 = (_i >= 8 ? f_filt9x(_a, _s, 8) : 0)
    _f9 = (_i == 9 ? f_filt9x(_a, _s, 9) : 0)
    _fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 :
         _i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 :
         _i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
    [_fn, _f1]

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
src = input.source(hlc3, title="Source")
N = input.int(4, title="Poles", minval=1, maxval=9)
per = input.int(144, title="Sampling Period", minval=2)
mult = input.float(1.414, title="Filtered True Range Multiplier", minval=0)
modeLag = input.bool(false, title="Reduced Lag Mode")
modeFast = input.bool(false, title="Fast Response Mode")

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
beta  = (1 - math.cos(4 * math.asin(1) / per)) / (math.pow(1.414, 2 / N) - 1)
alpha = -beta + math.sqrt(math.pow(beta, 2) + 2 * beta)
lag = (per - 1) / (2 * N)

srcdata = modeLag ? src + (src - src[lag]) : src
trdata  = modeLag ? ta.tr(true) + (ta.tr(true) - ta.tr(true)[lag]) : ta.tr(true)

[filtn, filt1] = f_pole(alpha, srcdata, N)
[filtntr, filt1tr] = f_pole(alpha, trdata, N)

filt = modeFast ? (filtn + filt1) / 2 : filtn
filttr = modeFast ? (filtntr + filt1tr) / 2 : filtntr

hband = filt + filttr * mult
lband = filt - filttr * mult

color1   = #0aff68
color2   = #00752d
color3   = #ff0a5a
color4   = #990032
fcolor   = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc
barcolor = (src > src[1]) and (src > filt) and (src < hband) ? #0aff68 : (src > src[1]) and (src >= hband) ? #0aff1b : (src <= src[1]) and (src > filt) ? #00752d : 
           (src < src[1]) and (src < filt) and (src > lband) ? #ff0a5a : (src < src[1]) and (src <= lband) ? #ff0a11 : (src >= src[1]) and (src < filt) ? #990032 : #cccccc

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Outputs : Visit my github -- https://github.com/devgaganin
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
bg_label = label.new(x=bar_index, y=na, text="ATMA V6\n© devgaganin", color=color.new(color.white, 0), style=label.style_label_down, size=size.small, textcolor=color.black, 
                     xloc=xloc.bar_index, yloc=yloc.price)
label.set_xy(bg_label, bar_index, (high + low) / 2)

filtplot = plot(filt, title="Filter", color=fcolor, linewidth=3)
hbandplot = plot(hband, title="Filtered True Range High Band", color=fcolor)
lbandplot = plot(lband, title="Filtered True Range Low Band", color=fcolor)
fill(hbandplot, lbandplot, title="Channel Fill", color=color.new(fcolor, 80))

barcolor(barcolor)



source = close
fastFilter = f_filt9x(alpha, source, 1)
slowFilter = f_filt9x(alpha, source, 9)

buySignal = ta.crossover(fastFilter, slowFilter)
sellSignal = ta.crossunder(fastFilter, slowFilter)

plotshape(buySignal, style=shape.labelup, color=color.green, size=size.large, location=location.belowbar, text="BUY-Gagan", textcolor=color.white)
plotshape(sellSignal, style=shape.labeldown, color=color.red, size=size.large, location=location.abovebar, text="SELL-Gagan", textcolor=color.white)

Overview

The pole count selects the filter order from one to nine, while the sampling period controls how quickly the smoother follows price. Reduced lag and fast response modes change the filter response. A multiplier sets the width of the filtered true range. The visible code does not define entries, exits, or alerts.

Details

Published by

devgaganin on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages, 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.

Settings

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

SettingTypeDefaultVariable
Sourcesourcehlc3src
Polesint4N
Sampling Periodint144per
Filtered True Range Multiplierfloat1.414mult
Reduced Lag ModeboolfalsemodeLag
Fast Response ModeboolfalsemodeFast
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

318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
219 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of Adaptive MA Slope

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