Indicator · Pine Script v6 · On the chart

Deviation Trend Profile [BigBeluga]

by theonetrade· code credited to BigBeluga

Deviation Trend Profile calculates a Simple Moving Average alongside ATR-based deviation bands to track market trend direction and volatility.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code148
Settings9inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

148 lines of Pine Script v6 from assets/indicator/bit-exact/deviation_trend_profile_bigbeluga_6Wr1CEuo.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

deviation_trend_profile_bigbeluga_6Wr1CEuo.pine
// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International  
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga

//@version=6
indicator("Deviation Trend Profile [BigBeluga]", overlay = true, max_boxes_count = 500, max_bars_back = 5000)


// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{

grp = "Standart Deviation Levels"
length = input.int(50, "SMA Length", group = "SMA")
mult1 = input.int(1, "Standart Deviation 1", group = grp)
mult2 = input.int(2, "Standart Deviation 2", group = grp)
mult3 = input.int(3, "Standart Deviation 3", group = grp)

show_tp = input.bool(true, "Show", group = "Trend Distribution Profile")
bins = input.int(50, "Bins Amount", group = "Trend Distribution Profile")
offset = input.int(30, "Offset", group = "Trend Distribution Profile")

col_up = input.color(color.rgb(18, 209, 235), "", group = "Theme", inline = "c")
col_dn = input.color(color.rgb(250, 40, 86), "", group = "Theme", inline = "c")


var start_index = int(na)
var trend = bool(na)

// }



// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{

avg = ta.sma(close, length)
atr = ta.atr(200)

stdv1 = avg + atr * mult1
stdv2 = avg + atr * mult2
stdv3 = avg + atr * mult3

stdv_1 = avg - atr * mult1
stdv_2 = avg - atr * mult2
stdv_3 = avg - atr * mult3

max = stdv3
min = stdv_3

avg_diff = avg - avg[5]

avg_col = avg_diff / ta.percentile_linear_interpolation(avg_diff, 500, 100)

avg_color = color.from_gradient(avg_col, -0.3, 0.3, col_dn, col_up)


if ta.crossover(avg_col, 0.1) and not trend
    trend := true
    start_index := bar_index

if ta.crossunder(avg_col, -0.1) and trend
    trend := false
    start_index := bar_index

loockback = bar_index - start_index

profile(min, max)=>

    var boxes = array.new<box>()
    var bin = array.new<int>(bins)

    step = (max - min) / bins

    start = bar_index + offset

    if barstate.islast

        if boxes.size() >=0 
            for b in boxes
                box.delete(b)


        for g = 0 to bins-1
            bin.set(g, 0)


        for l = 0 to loockback
            c = close[l]
            a = avg[l]

            mi = min[l]

            s = step[l]

            for i = 0 to bin.size()-1

                lower = mi + s * i
                upper = lower + s 

                if c >= lower-s and c <= upper+s
                    bin.set(i, bin.get(i) + 1)


        for j = 0 to bin.size()-1

            val = bin.get(j)

            lower = min + step * j
            upper = lower + step 
        
            col = color.from_gradient(val, 0, bin.max(), color.new(chart.fg_color, 80), avg_color)

            boxes.push(box.new(start-val, upper, start, lower, bgcolor = col, border_color = val == 0 ? chart.fg_color : chart.bg_color))

        label.delete(label.new(start, max, str.tostring(loockback), textcolor = chart.fg_color, color = color.new(avg_color, 80), tooltip = str.tostring(loockback) + " bars back beginnig of the trend")[1])


draw_stdv(src, mult, mid = false)=>
    if barstate.islast
        if mid
            line.delete(line.new(bar_index, avg, bar_index+5, avg, color = avg_color, width = 2)[1])

        line.delete(line.new(bar_index, src, bar_index+5, src, color = chart.fg_color, width = 2)[1])
        label.delete(label.new(bar_index+5, src, color = color.new(chart.fg_color, 100), textcolor = chart.fg_color, text = mult, style = label.style_label_left)[1])
// }



// PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{

draw_stdv(stdv1, "+1", true)
draw_stdv(stdv2, "+2")
draw_stdv(stdv3, "+3")

draw_stdv(stdv_1, "-1")
draw_stdv(stdv_2, "-2")
draw_stdv(stdv_3, "-3")

if show_tp
    profile(min, max)

plot(avg, color = avg_color, linewidth = 3)

plotshape(trend != trend[1] and trend ? avg : na, "Up", shape.circle, location.absolute, size = size.tiny, color = col_up)
plotshape(trend != trend[1] and trend ? avg : na, "Up", shape.circle, location.absolute, size = size.small, color = color.new(col_up, 50))

plotshape(trend != trend[1] and not trend ? avg : na, "Down", shape.circle, location.absolute, size = size.tiny, color = col_dn)
plotshape(trend != trend[1] and not trend ? avg : na, "Down", shape.circle, location.absolute, size = size.small, color = color.new(col_dn, 50))

// }

Overview

Deviation Trend Profile [BigBeluga] evaluates trend momentum using historical percentile interpolation of SMA differences to dynamically color the central trend line. On the final chart bar, it constructs a price distribution profile using box drawings offset into the future, aggregating price frequency across the current trend duration. Settings allow customization of SMA length, deviation multipliers, profile bin counts, and display offsets. The script draws directly on the main price chart.

Details

Published by

theonetrade on GitHub

Code credit

BigBeluga, as written in the script's header

Draws

On the price chart

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-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
SMA Lengthint50length
Standart Deviation 1int1mult1
Standart Deviation 2int2mult2
Standart Deviation 3int3mult3
Showbooltrueshow_tp
Bins Amountint50bins
Offsetint30offset
col_upcolorcolor.rgb(18, 209, 235)col_up
col_dncolorcolor.rgb(250, 40, 86)col_dn
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

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 5 years ago · None stated GitHub repository of [RS]Donchian Fans

Dynamic Linear Regression

by TradersPost
228 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 4 months ago · None stated GitHub repository of Dynamic Linear Regression

ATR Trailing Stop

by mihakralj
99 stars

Calculates an ATR-based trailing stop overlaid on the price chart to assist with trend identification and stop placement. Using a specified ATR period and multiplier, it projects upper and lower bounds around the closing price. The stop line ratchets up during

Indicator v5 TrendVolatility & bands
Updated 8 weeks ago · Apache-2.0 GitHub repository of ATR Trailing Stop

Moon Dev Lunar Sniper

by moondevonyt
98 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Lunar Sniper

SuperTrend & Pivots

by dcaoyuan
55 stars

This overlay indicator plots a SuperTrend line on the price chart using a fixed ATR length of 10 and a factor of 3. When the trend direction is up it draws a green line and a light green fill toward the candle midpoint; when down it draws a red line and a ligh

Indicator v6 TrendVolatility & bands
Updated 7 months ago · Apache-2.0 GitHub repository of SuperTrend & Pivots

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers