Indicator · Pine Script v6 · On the chart

Fibonacci Trend [ChartPrime]

by theonetrade· code credited to ChartPrime

Fibonacci Trend [ChartPrime] is an overlay indicator that identifies market trends using Supertrend calculations and dynamically plots Fibonacci retracement levels.

View on GitHub

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

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

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


//@version=6
indicator("Fibonacci Trend [ChartPrime]", overlay = true, max_lines_count = 500)

// --------------------------------------------------------------------------------------------------------------------}
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{

bool  trend_on = input.bool(true, "", inline = "trend", group = "Trend")
float trend_   = input.float(4, "Trend", step = 0.01, inline = "trend", group = "Trend")
color col1     = input.color(#26905d, "", inline = "trend", group = "Trend")
color col2     = input.color(#74286d, "",inline = "trend", group = "Trend")

int   extend   = input.int(15, "Extend", group = "Fibonacci", inline = "1"), fill_col = input.color(#2689901c, "", group = "Fibonacci", inline = "1")

float v_236 = input.float(0.236, "1")*100
float v_382 = input.float(0.382, "2")*100
float v_618 = input.float(0.618, "3")*100
float v_786 = input.float(0.786, "4")*100

// UDT
type data 
    line fib05  = na    
    line fib0   = na
    line fib236 = na
    line fib382 = na
    line fib618 = na
    line fib786 = na
    line fib_   = na
    line fib_di   = na

    label H = na
    label L = na

    label L0   = na
    label L236 = na
    label L382 = na
    label L618 = na
    label L786 = na
    label L_   = na


var fib_d =  data.new()




// --------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{

[supertrend, direction] = ta.supertrend(trend_, 25)

draw_fibb(trend)=>

    var h = float(na)
    var l = float(na)
    var hi = int(na)
    var li = int(na)

    var val_0 = float(na)
    var val_ = float(na)

    atr = ta.atr(200)
    // delete previous fibb 
    if trend != trend[1]
        line.delete(fib_d.fib_)
        line.delete(fib_d.fib0)
        line.delete(fib_d.fib05)
        line.delete(fib_d.fib_di)
        line.delete(fib_d.fib236)
        line.delete(fib_d.fib382)
        line.delete(fib_d.fib618)
        line.delete(fib_d.fib786)
        label.delete(fib_d.H)
        label.delete(fib_d.L)
        label.delete(fib_d.L0)
        label.delete(fib_d.L_)        
        label.delete(fib_d.L236)
        label.delete(fib_d.L382)
        label.delete(fib_d.L618)
        label.delete(fib_d.L786)


    // Creat Fib Lines at the bottom and the top
    if trend != trend[1] and trend == -1
    
        fib_d.fib_ := line.new(bar_index, low, bar_index, low, color = chart.fg_color, width = 2)
        fib_d.fib0 := line.new(bar_index, high+atr*3, bar_index, high+atr*3, color = chart.fg_color, width = 2)


    if trend != trend[1] and trend == 1
    
        fib_d.fib_ := line.new(bar_index, high, bar_index, high, color = chart.fg_color, width = 2)
        fib_d.fib0 := line.new(bar_index, low-atr*3, bar_index, low-atr*3, color = chart.fg_color, width = 2)

        fib_d.fib_di := line.new(li, l, hi, h, style = line.style_dashed, color = chart.fg_color)
        

    // Extend fibb lines during a trend
    if trend == trend[1]
        // Update High and low of Fibb
        
        if low < fib_d.fib_.get_y1()
            fib_d.fib_.set_y1(low)
            fib_d.fib_.set_y2(low)


        if high > fib_d.fib0.get_y1()
            fib_d.fib0.set_y1(high)
            fib_d.fib0.set_y2(high)


        // High and low labels
        if high == fib_d.fib0.get_y1()
            h := high
            hi := bar_index
            label.delete((fib_d[1]).H)
            fib_d.H := label.new(hi, h, str.tostring(h, "#,###.####"), color = #15373b)
   
        if low == fib_d.fib_.get_y1()
            l := low
            li := bar_index
            label.delete((fib_d[1]).L)
            fib_d.L := label.new(li, l, str.tostring(l, "#,###.####"), style = label.style_label_up, color = #15373b)
   


        fib_d.fib_.set_x2(bar_index+extend)
        fib_d.fib0.set_x2(bar_index+extend)

        line.delete((fib_d[1]).fib_di)
        fib_d.fib_di := line.new(li, l, hi, h, style = line.style_dashed, color = chart.fg_color)

        if fib_d.fib_di.get_x1() < fib_d.fib0.get_x1() or fib_d.fib_di.get_x2() < fib_d.fib0.get_x1()
            line.delete(fib_d.fib_di)

        size_step = (fib_d.fib0.get_y1() - fib_d.fib_.get_y1()) / 100

        line.delete((fib_d[1]).fib05)
        line.delete((fib_d[1]).fib382)
        line.delete((fib_d[1]).fib236)
        line.delete((fib_d[1]).fib618)
        line.delete((fib_d[1]).fib786)

        if trend == -1

            val_0   := fib_d.fib0.get_y1()
            val_    := fib_d.fib_.get_y1()

        if trend == 1 

            val_0   := fib_d.fib_.get_y1()
            val_    := fib_d.fib0.get_y1()

        fib_d.fib236 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_236 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_236 * trend*-1, color = chart.fg_color)
        fib_d.fib382 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_382 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_382 * trend*-1, color = chart.fg_color)

        fib_d.fib05  := line.new(fib_d.fib0.get_x1(), val_0 - size_step * 50 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * 50 * trend*-1, color = color.new(chart.fg_color, 50), style = line.style_dotted)

        fib_d.fib618 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_618 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_618 * trend*-1, color = chart.fg_color)
        fib_d.fib786 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_786 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_786 * trend*-1, color = chart.fg_color)

        label.delete((fib_d[1]).L0)
        label.delete((fib_d[1]).L_)                
        label.delete((fib_d[1]).L236)
        label.delete((fib_d[1]).L382)
        label.delete((fib_d[1]).L618)
        label.delete((fib_d[1]).L786)

        fib_d.L0 := label.new(bar_index+extend, val_0,  text = "0 " + str.tostring(val_0, "(#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
        fib_d.L_ := label.new(bar_index+extend, val_,   text = "1 " + str.tostring(val_, "(#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)      

        fib_d.L236 := label.new(bar_index+extend, fib_d.fib236.get_y1(), text = str.tostring(v_236/100) + str.tostring(fib_d.fib236.get_y1(), " (#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
        fib_d.L382 := label.new(bar_index+extend, fib_d.fib382.get_y1(), text = str.tostring(v_382/100) + str.tostring(fib_d.fib382.get_y1(), " (#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
        fib_d.L618 := label.new(bar_index+extend, fib_d.fib618.get_y1(), text = str.tostring(v_618/100) + str.tostring(fib_d.fib618.get_y1(), " (#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
        fib_d.L786 := label.new(bar_index+extend, fib_d.fib786.get_y1(), text = str.tostring(v_786/100) + str.tostring(fib_d.fib786.get_y1(), " (#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)

        linefill.new(fib_d.fib618, fib_d.fib786, fill_col)
        linefill.new(fib_d.fib05, fib_d.fib786, fill_col)


// --------------------------------------------------------------------------------------------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{

draw_fibb(direction)

color = trend_on ? (direction == 1 ? col2 : col1) : na
p1 = plot(supertrend, "Trend", color = direction != direction[1] ? na : color, style = plot.style_linebr)
p2 = plot(hl2, display = display.none)

fill(p1, p2, hl2, supertrend, na, direction != direction[1] ? na : color.new(color, 90))
// --------------------------------------------------------------------------------------------------------------------}

Overview

When a trend shift occurs, the script anchors high and low boundaries based on price action and ATR offsets, continuously updating key Fibonacci ratios like 0.236, 0.382, 0.618, and 0.786. Users can adjust the trend factor, Fibonacci extension lengths, and ratio levels. All lines and labels are drawn directly on the price chart.

Details

Published by

theonetrade on GitHub

Code credit

ChartPrime, 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
trend_onbooltruetrend_on
Trendfloat4trend_
col1color#26905dcol1
col2color#74286dcol2
Extendint15extend
fill_colcolor#2689901cfill_col
1float0.236v_236
2float0.382v_382
3float0.618v_618
4float0.786v_786
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

575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener

Swing labels

by tradoor-terminal
320 stars

Calculates swing highs and swing lows on the price chart using pivot high and pivot low detection over a specified length. It places labels above pivot highs and below pivot lows to highlight key structural swing points. The indicator measures and displays the

Indicator v6 Support & resistanceTrend
Updated 3 days ago · AGPL-3.0 GitHub repository of Swing labels

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 5 years ago · None stated GitHub repository of Function - Linear Regression

AI Trend

by dearvn
257 stars

AI Trend is an indicator that plots pivot points, trend lines, and support and resistance levels directly on the price chart. It marks high and low pivots based on user-defined length, draws trend lines that check for violations at specified points, and identi

Indicator v5 TrendSupport & resistance
Updated 2 months ago · None stated GitHub repository of AI Trend

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

Ichimoku Cloud

by harryguiacorn
220 stars

This indicator plots Ichimoku Cloud elements on the price chart, including Tenkan-sen, Kijun-sen, Senkou Span A and B lines with optional Chikou Span. It signals trend changes via Tenkan-sen and Kijun-sen crosses and places arrows at Kijun-sen direction shifts

Indicator v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ichimoku Cloud

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