Indicator · Pine Script v6 · On the chart

ATR Fibonacci Trend Envelopes [BigBeluga]

by theonetrade· code credited to BigBeluga

ATR Fibonacci Trend Envelopes [BigBeluga] plots an ATR-expanded envelope around a customizable moving average baseline directly on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code171
Settings17inputs
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

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

atr_fibonacci_trend_envelopes_bigbeluga_16toJPAD.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('ATR Fibonacci Trend Envelopes [BigBeluga]', overlay = true, max_labels_count = 500, max_lines_count = 500)

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

grp_calc  = "Calculation Settings"
maType    = input.string("RMA", "MA Type", options=["SMA", "EMA", "WMA", "HMA", "RMA"], group=grp_calc, tooltip="Select the Moving Average type used to calculate the baseline (Basis).")
maLength  = input.int(100, 'MA Length', group=grp_calc, tooltip="The number of bars used to calculate the trend baseline.")
atrLength = input.int(100, 'ATR Length', group=grp_calc, tooltip="The lookback period for Average True Range, used to determine envelope width.")
atrMult   = input.float(3.0, 'ATR Multiplier', group=grp_calc, tooltip="Multiplies the ATR to expand or contract the Trend Envelopes.")

grp_proj  = "Projection Settings"
showProj  = input.bool(true, "Show Projections", group=grp_proj, tooltip="Toggle the visibility of dotted line projections for the trend and Fibonacci levels.")
projLen   = input.int(50, "Projection Length (Bars)", minval=1, group=grp_proj, tooltip="Determines how many bars into the future the levels are projected.")

grp_color = "Color & Visual Settings"
colorUp   = input.color(color.rgb(36, 192, 212), "Uptrend Color", group=grp_color, tooltip="Color used for the baseline and labels during a bullish trend.")
colorDown = input.color(color.rgb(235, 51, 51), "Downtrend Color", group=grp_color, tooltip="Color used for the baseline and labels during a bearish trend.")
colorMid  = input.color(color.gray, "0.5 Fib Color", group=grp_color, tooltip="Color for the 50% Fibonacci retracement level.")
baseFill  = input.color(color.rgb(255, 123, 0), "Pocket Base Color", group=grp_color, tooltip="Base color for the Dynamic Golden Pocket (0.618 - 0.786).")
sens      = 0.6 // Sensitivity for dynamic transparency

grp_dash  = "Dashboard Settings"
showDash  = input.bool(true, "Show MTF Dashboard", group=grp_dash, tooltip="Toggle the visibility of the Multi-Timeframe status table.")
dashLoc   = input.string(position.bottom_right, "Location", options=[position.top_right, position.bottom_right, position.top_left, position.bottom_left, position.middle_right], group=grp_dash, tooltip="The corner of the chart where the dashboard is displayed.")
dashSize  = input.string(size.small, "Size", options=[size.tiny, size.small, size.normal, size.large], group=grp_dash, tooltip="The scaling size of the dashboard table and its text.")
tf1       = input.timeframe("5", "Timeframe 1", group=grp_dash, tooltip="The first timeframe to track in the dashboard.")
tf2       = input.timeframe("15", "Timeframe 2", group=grp_dash, tooltip="The second timeframe to track in the dashboard.")
tf3       = input.timeframe("60", "Timeframe 3", group=grp_dash, tooltip="The third timeframe to track in the dashboard.")
tf4       = input.timeframe("240", "Timeframe 4", group=grp_dash, tooltip="The fourth timeframe to track in the dashboard.")
// }


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

// Fibonacci Multipliers
fibMid   = 0.5
fibGold1 = 0.618
fibGold2 = 0.786

get_ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "WMA" => ta.wma(source, length)
        "HMA" => ta.hma(source, length)
        "RMA" => ta.rma(source, length)
        => ta.sma(source, length)

// MTF Function to get Trend and Pocket Status
get_status(tf) =>
    request.security(syminfo.tickerid, tf, [close, high, low], lookahead=barmerge.lookahead_off)
    
calc_trend_and_pocket() =>
    b = get_ma(close, maLength, maType)
    a = ta.atr(atrLength)
    u = b + a * atrMult
    l = b - a * atrMult
    var int t = 0
    if ta.crossover(close, u)
        t := 1
    else if ta.crossunder(close, l)
        t := -1
    
    f618 = t == 1 ? l + (u - l) * (1 - fibGold1) : u - (u - l) * (1 - fibGold1)
    f786 = t == 1 ? l + (u - l) * (1 - fibGold2) : u - (u - l) * (1 - fibGold2)
    
    inPocket = (close <= math.max(f618, f786) and close >= math.min(f618, f786))
    [t, inPocket]

// Current TF Data
[trend, inPocket] = calc_trend_and_pocket()

basis     = get_ma(close, maLength, maType)
atrValue  = ta.atr(atrLength)
upperBand = basis + atrValue * atrMult
lowerBand = basis - atrValue * atrMult

fib50  = trend == 1 ? lowerBand + (upperBand - lowerBand) * (1 - fibMid)   : upperBand - (upperBand - lowerBand) * (1 - fibMid)
fib618 = trend == 1 ? lowerBand + (upperBand - lowerBand) * (1 - fibGold1) : upperBand - (upperBand - lowerBand) * (1 - fibGold1)
fib786 = trend == 1 ? lowerBand + (upperBand - lowerBand) * (1 - fibGold2) : upperBand - (upperBand - lowerBand) * (1 - fibGold2)

// Dynamic Color Logic
pocketMid     = (fib618 + fib786) / 2
dist          = math.abs(close - pocketMid)
maxDist       = (upperBand - lowerBand) * 0.5 
rawTransp     = 65 + (dist / maxDist * 30 * sens)
dynamicTransp = math.max(0, math.min(90, rawTransp))
dynamicColor  = color.new(baseFill, dynamicTransp)

// Projection Function
create_proj(lvl, slope, col, txt, baseline = false) =>
    endVal = lvl + (slope * projLen)
    ln = line.new(bar_index, lvl, bar_index + projLen, endVal, xloc.bar_index, extend.none, col, baseline ? line.style_solid : line.style_dotted, baseline ? 3 : 1)
    lb = label.new(bar_index + projLen, endVal, txt, xloc.bar_index, style=label.style_label_left, color=color.new(color.black, 100), textcolor=col, size=dashSize)
    [ln, lb]
// Timeframe Format Helper
format_tf(tf) =>
    float m = str.tonumber(tf)
    if not na(m)
        m >= 1440 ? str.tostring(math.round(m / 1440)) + "D" : 
         m >= 60 ? str.tostring(math.round(m / 60)) + "H" : 
         tf + "m"
    else
        tf
// }

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

trendChange = trend != trend[1]
float level100 = trend == 1 ? lowerBand : upperBand
trendCol    = trend == 1 ? colorUp : colorDown

plot(not trendChange ? level100 : na, 'Trend MA', color = trendCol, linewidth = 3, style = plot.style_linebr)
p1 = plot(trend != 0 and not trendChange ? fib618 : na, 'Fib 0.618', color = dynamicColor, style = plot.style_linebr)
p2 = plot(trend != 0 and not trendChange ? fib786 : na, 'Fib 0.786', color = dynamicColor, style = plot.style_linebr)
plot(trend != 0 ? fib50 : na, 'Fib 0.5', color = colorMid, style = plot.style_linebr)
fill(p1, p2, color = dynamicColor, title = 'Dynamic Golden Pocket')

if trendChange
    level = trend == 1 ? lowerBand : upperBand
    style = trend == 1 ? label.style_label_up : label.style_label_down
    label.new(bar_index, level, text = '⦿', color = color(na), textcolor = trend == 1 ? colorUp : colorDown, style = label.style_label_center, size = dashSize)
    label.new(bar_index, level, text = str.tostring(close, format.mintick), color = color(na), textcolor = trend == 1 ? colorUp : colorDown, style = style, size = dashSize)

// Dashboard Logic
if showDash and barstate.islast
    var table dash = table.new(dashLoc, 3, 5, bgcolor = color.new(color.black, 40), border_width = 1, border_color = color.new(color.gray, 70))    
    // Header
    table.cell(dash, 0, 0, "TF", text_color = color.white, text_size = dashSize)
    table.cell(dash, 1, 0, "Trend", text_color = color.white, text_size = dashSize)
    table.cell(dash, 2, 0, "Pocket", text_color = color.white, text_size = dashSize)
    
    tfs = array.from(tf1, tf2, tf3, tf4)
    for i = 0 to 3
        curr_tf = array.get(tfs, i)
        [t, p] = request.security(syminfo.tickerid, curr_tf, [trend, inPocket])
        
        row = i + 1
        table.cell(dash, 0, row, format_tf(curr_tf), text_color = color.white, text_size = dashSize)
        table.cell(dash, 1, row, t == 1 ? "BULL" : "BEAR", bgcolor = t == 1 ? color.new(colorUp, 30) : color.new(colorDown, 30), text_color = color.white, text_size = dashSize)
        table.cell(dash, 2, row, p ? "INSIDE" : "OUT", bgcolor = p ? color.new(baseFill, 30) : color.new(color.gray, 80), text_color = color.white, text_size = dashSize)

// Real-time labels & Projections (Original code)
var line l100 = na, var line l50 = na, var line l618 = na, var line l786 = na
var label lb100 = na, var label lb50 = na, var label lb618 = na, var label lb786 = na
var linefill fGold = na

if barstate.islast and trend != 0
    line.delete(l100), line.delete(l50), line.delete(l618), line.delete(l786)
    label.delete(lb100), label.delete(lb50), label.delete(lb618), label.delete(lb786)
    linefill.delete(fGold)

    s100 = (level100 - level100[4]) / 4
    s50  = (fib50 - fib50[4]) / 4
    s618 = (fib618 - fib618[4]) / 4
    s786 = (fib786 - fib786[4]) / 4

    if showProj
        [ln100, lab100] = create_proj(level100, s100, trendCol, "1.0", true)
        [ln50, lab50]   = create_proj(fib50, s50, colorMid, "0.5")
        [ln618, lab618] = create_proj(fib618, s618, baseFill, "0.618")
        [ln786, lab786] = create_proj(fib786, s786, baseFill, "0.786")
        fGold := linefill.new(ln618, ln786, dynamicColor)
        l100 := ln100, l50 := ln50, l618 := ln618, l786 := ln786
        lb100 := lab100, lb50 := lab50, lb618 := lab618, lb786 := lab786
// }

Overview

ATR Fibonacci Trend Envelopes [BigBeluga] calculates Fibonacci retracement and expansion bands to identify trend direction and potential support or resistance zones. The script features forward projection lines to extend levels into future bars and includes a multi-timeframe dashboard table that tracks trend alignment across four customizable timeframes. Users can adjust the baseline moving average type, ATR multiplier, envelope periods, visual colors, and dashboard layout.

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
MA TypestringRMAmaType
MA Lengthint100maLength
ATR Lengthint100atrLength
ATR Multiplierfloat3.0atrMult
Show ProjectionsbooltrueshowProj
Projection Length (Bars)int50projLen
Uptrend Colorcolorcolor.rgb(36, 192, 212)colorUp
Downtrend Colorcolorcolor.rgb(235, 51, 51)colorDown
0.5 Fib Colorcolorcolor.graycolorMid
Pocket Base Colorcolorcolor.rgb(255, 123, 0)baseFill
Show MTF DashboardbooltrueshowDash
Locationstringposition.bottom_rightdashLoc
Show all 17 settings
SettingTypeDefaultVariable
Sizestringsize.smalldashSize
Timeframe 1timeframe5tf1
Timeframe 2timeframe15tf2
Timeframe 3timeframe60tf3
Timeframe 4timeframe240tf4
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 detects fast and slow Exponential Moving Average crossovers filtered by a long-term trend EMA. Upon a signal, it projects the entry line, dynamic stop loss based on recent swing extremes and an ATR distance multiplier, and up to three R-multiple

Indicator v6 Moving averagesTrend
Updated 3 weeks ago · MIT GitHub repository of EMA Crossover - 9/21 with 200 EMA Filter, Entry, Stop and Targets

Market Monitor - 1m

by chris-c-thomas
13 stars

Market Monitor - 1m is an overlay indicator designed for multi-chart monitoring and directional bias assessment. It plots a fast, mid, and slow EMA ribbon with a fill cloud, session VWAP with standard deviation bands, and previous day key levels. It evaluates

Indicator v6 TrendMoving averages Repaints
Updated 7 months ago · MIT GitHub repository of Market Monitor - 1m

5 EMAs

by hirawatt
11 stars

5 EMAs calculates and plots five Exponential Moving Averages derived from five configurable timeframes directly onto the main price chart. It also plots the high and low lines fetched from an additional custom timeframe, accompanied by a small on-screen table

Indicator v4 Moving averagesTrend Repaints
Updated 2 years ago · MIT GitHub repository of 5 EMAs

Snagprofit WMA MA

by dearvn
4 stars

Snagprofit WMA MA combines multi-timeframe Weighted Moving Averages (1M, 5M, 15M, and 1H) with a Simple Moving Average filter to assess trend momentum across different time horizons. It plots shape signals directly on the price chart when candle breakouts alig

Indicator v5 TrendMoving averages Repaints
Updated 4 years ago · None stated GitHub repository of Snagprofit WMA MA
257 stars

This indicator analyzes short-term price action on index futures and options charts by applying Rational Quadratic kernel smoothing to detect sideways consolidation ranges and potential breakouts. It processes pivot highs and lows over customizable loopback pe

Indicator v5 Support & resistanceTrend Repaints
Updated 2 months ago · None stated GitHub repository of SPX 30M - Trading Chart

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