Indicator · Pine Script v5 · On the chart

Price Action as in Book: Fibonacci + Support/Resistant + Trendline

by theonetrade

This indicator automatically identifies pivot highs and pivot lows to construct support and resistance levels, trendlines, and Fibonacci retracements directly on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code187
Settings12inputs
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

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

fibonacci_support_resistant_trendline_price_action_HJqjyjGi.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @TrendCrypto2022

//@version=5
indicator("Price action as in book: Fibonacci + Support/Resistant + Trendline", overlay=true, max_lines_count = 500)

//Input
buyonly    =  input.bool   (title="Find entry  Long",     defval=true,   group="Set up Find entry")
sellonly   =  input.bool    (title="Find entry Short",   defval=false,   group="Set up Find entry")

leftbars    = input.int(10,     minval=1, title='Pivot Detection: Left Bars', group = "Set up Pivot High/Low")
rightbars   = input.int(5,      minval=1, title='Pivot Detection: Right Bars', group = "Set up Pivot High/Low")

width_fibo          = input.int(2,      minval=1, title='Width Fibonacci levels',   group = "Custom Selection",             inline = "1")
width_sup_res       = input.int(2,      minval=1, title='Width Sup/Res levels',     group = "Custom Selection",             inline = "2")
width_trendline     = input.int(2,      minval=1, title='Width Trendline',     group = "Custom Selection")

extend_fibo         = input.int(5,      minval=1, title='Extention',                group = "Custom Selection",             inline = "1")
color_fibo_label    = input.color(color.new(color.yellow, 0), title="Color Labels", group = "Custom Selection",             inline = "1")
extend_sup_res      = input.int(5,      minval=1, title='Extention',                group = "Custom Selection",             inline = "2")


// Pivots
ph = ta.pivothigh(high,     leftbars, rightbars)
pl = ta.pivotlow(low,       leftbars, rightbars)

//Caculate Support/Resistant levels based on Pivots
phvalue1    = ta.valuewhen(ph, high[rightbars], 0)
phbar1      = ta.valuewhen(ph, bar_index[rightbars], 0),        phv1low = ta.valuewhen(ph, close[rightbars]>open[rightbars] ? close[rightbars] : open[rightbars], 0)
phvalue2    = ta.valuewhen(ph, high[rightbars], 1)
phbar2      = ta.valuewhen(ph, bar_index[rightbars], 1),        phv2low = ta.valuewhen(ph, close[rightbars]>open[rightbars] ? close[rightbars] : open[rightbars], 1)
phbar3      = ta.valuewhen(ph, bar_index[rightbars], 2),
phvalue3    = ta.valuewhen(ph, high[rightbars], 2)

plvalue1    = ta.valuewhen(pl, low[rightbars], 0)
plbar1      = ta.valuewhen(pl, bar_index[rightbars], 0),        plv1low = ta.valuewhen(pl, close[rightbars]<open[rightbars] ? close[rightbars] : open[rightbars], 0)
plvalue2    = ta.valuewhen(pl, low[rightbars], 1)
plbar2      = ta.valuewhen(pl, bar_index[rightbars], 1)
plbar3      = ta.valuewhen(pl, bar_index[rightbars], 2),        plv2low = ta.valuewhen(pl, close[rightbars]<open[rightbars] ? close[rightbars] : open[rightbars], 1)
plvalue3    = ta.valuewhen(pl, low[rightbars], 2)

plotshape(ph, style=shape.diamond, location=location.abovebar, color=color.new(color.red, 0),    title='Pivot High',    offset=-rightbars)
plotshape(pl, style=shape.diamond, location=location.belowbar, color=color.new(color.green, 0),  title='Pivot Low',     offset=-rightbars)


//Calculate trendlines
_slope(x1, x2, y1, y2)  =>
    m = (y2 - y1) / (x2 - x1)
    m
get_y_oxy(m, x1, y1)    =>
    b = y1 - m * x1
    b
get_y(m, b, ts)         =>
    Y = m * ts + b
    Y
int         res_x1 = na
float       res_y1 = na
int         res_x2 = na
float       res_y2 = na
int         sup_x1 = na
float       sup_y1 = na
int         sup_x2 = na
float       sup_y2 = na
res_x1 := ph ? phbar2 : res_x1[1]
res_y1 := ph ? phvalue2 : res_y1[1]
res_x2 := ph ? phbar3 : res_x2[1]
res_y2 := ph ? phvalue3 : res_y2[1]
res_m = _slope(res_x1, res_x2, res_y1, res_y2)
res_b = get_y_oxy(res_m, res_x1, res_y1)
res_y = get_y(res_m, res_b, bar_index)

sup_x1 := pl ? plbar2 : sup_x1[1]
sup_y1 := pl ? plvalue2 : sup_y1[1]
sup_x2 := pl ? plbar3 : sup_x2[1]
sup_y2 := pl ? plvalue3 : sup_y2[1]
sup_m = _slope(sup_x1, sup_x2, sup_y1, sup_y2)
sup_b = get_y_oxy(sup_m, sup_x1, sup_y1)
sup_y = get_y(sup_m, sup_b, bar_index)

// Setup Alert
alert_input         = input.string(title='Set alert Long Trade when price test',    defval='Fibo 0.5', options=['Fibo 0.382', 'Fibo 0.5', 'Fibo 0.618', 'Fibo 0.786', 'Support Zone', 'Trendline'], group='Set up Alert')
alertshort_input    = input.string(title='Set alert Short Trade when price test',   defval='Fibo 0.5', options=['Fibo 0.382', 'Fibo 0.5', 'Fibo 0.618', 'Fibo 0.786', 'Resistant Zone', 'Trendline'], group='Set up Alert')

distance_x = timenow + math.round(ta.change(time) * 1)



//Draw Fibonacci levels, Support levels and labels
if ph and phvalue1 > phvalue2 and buyonly == true
    line.new(plbar1, plvalue1,                              phbar1, phvalue1,                                                   style=line.style_arrow_right, color=color.lime, width = 2)
    line.new(plbar1, phvalue1,                              phbar1+ rightbars+extend_fibo, phvalue1,                               style=line.style_solid, color=color.new(color.silver, 60), width = width_fibo)
    line.new(plbar1, phvalue1-(phvalue1-plvalue1)*0.236,    phbar1+ rightbars+extend_fibo, phvalue1-(phvalue1-plvalue1)*0.236,     style=line.style_solid, color=color.new(color.red, 60), width = width_fibo)
    line.new(plbar1, phvalue1-(phvalue1-plvalue1)*0.382,    phbar1+ rightbars+extend_fibo, phvalue1-(phvalue1-plvalue1)*0.382,     style=line.style_solid, color=color.new(#81c784, 60), width = width_fibo)
    line.new(plbar1, phvalue1-(phvalue1-plvalue1)*0.500,    phbar1+ rightbars+extend_fibo, phvalue1-(phvalue1-plvalue1)*0.500,     style=line.style_solid, color=color.new(color.green, 60), width = width_fibo)
    line.new(plbar1, phvalue1-(phvalue1-plvalue1)*0.618,    phbar1+ rightbars+extend_fibo, phvalue1-(phvalue1-plvalue1)*0.618,     style=line.style_solid, color=color.new(#089981, 60), width = width_fibo)
    line.new(plbar1, phvalue1-(phvalue1-plvalue1)*0.786,    phbar1+ rightbars+extend_fibo, phvalue1-(phvalue1-plvalue1)*0.786,     style=line.style_solid, color=color.new(color.aqua, 60), width = width_fibo)
    line.new(plbar1, plvalue1,                              phbar1+ rightbars+extend_fibo, plvalue1,                               style=line.style_solid, color=color.new(color.silver, 60), width = width_fibo)
    p1=line.new(phbar2, phv2low,                               phbar1+ rightbars+extend_sup_res, phv2low,                                 style=line.style_solid, color=color.new(color.lime, 20), width = width_sup_res)
    p2=line.new(phbar2, phvalue2,                              phbar1+ rightbars+extend_sup_res, phvalue2,                                style=line.style_solid, color=color.new(color.lime, 20), width = width_sup_res)
    linefill.new(p1, p2, color = color.new(color.lime, transp =85))
    if phvalue2 < phvalue3
        line.new(phbar3, phvalue3, phbar2, phvalue2, style=line.style_dotted, color=color.red, width = width_trendline)
        line.new(phbar2, phvalue2, bar_index, res_y, style=line.style_dotted, color=color.red, width = width_trendline)
    if close<phvalue1-(phvalue1-plvalue1)*0.382 and alert_input == 'Fibo 0.382'
        alert(message = "Fibo 0.382", freq = alert.freq_once_per_bar)
    if close<phvalue1-(phvalue1-plvalue1)*0.500 and alert_input == 'Fibo 0.5'
        alert(message = "Fibo 0.5", freq = alert.freq_once_per_bar)
    if close<phvalue1-(phvalue1-plvalue1)*0.618 and alert_input == 'Fibo 0.618'
        alert(message = "Fibo 0.618", freq = alert.freq_once_per_bar)
    if close<phvalue1-(phvalue1-plvalue1)*0.786 and alert_input == 'Fibo 0.786'
        alert(message = "Fibo 0.786", freq = alert.freq_once_per_bar)
    if close<phvalue2                           and alert_input == 'Support Zone'
        alert(message = "Support Zone", freq = alert.freq_once_per_bar)
    if close<res_y + res_y*0.005                and alert_input == 'Trendline'
        alert(message = "Trendline",    freq = alert.freq_once_per_bar)
    var label labelfibo0 = na
    label.delete(labelfibo0)
    labelfibo0 := label.new(x=distance_x, y=phvalue1-(phvalue1-plvalue1)*0,        text='0', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo236 = na
    label.delete(labelfibo236)
    labelfibo236 := label.new(x=distance_x, y=phvalue1-(phvalue1-plvalue1)*0.236,  text='0.236', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo382 = na
    label.delete(labelfibo382)
    labelfibo382 := label.new(x=distance_x, y=phvalue1-(phvalue1-plvalue1)*0.382,  text='0.382', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo5 = na
    label.delete(labelfibo5)
    labelfibo5 := label.new(x=distance_x, y=phvalue1-(phvalue1-plvalue1)*0.5,      text='0.5', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo618 = na
    label.delete(labelfibo618)
    labelfibo618 := label.new(x=distance_x, y=phvalue1-(phvalue1-plvalue1)*0.618,  text='0.618', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo786 = na
    label.delete(labelfibo786)
    labelfibo786 := label.new(x=distance_x, y=phvalue1-(phvalue1-plvalue1)*0.786,  text='0.786', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo1 = na
    label.delete(labelfibo1)
    labelfibo1 := label.new(x=distance_x, y=phvalue1-(phvalue1-plvalue1)*1, text='1', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)


//Draw Fibonacci levels, Resistant levels and labels
if pl and plvalue1 < plvalue2 and sellonly == true
    line.new(phbar1, phvalue1,                              plbar1, plvalue1,                                                   style=line.style_arrow_right, color=color.red, width = 2)
    line.new(phbar1, plvalue1,                              plbar1+ rightbars+extend_fibo, plvalue1,                               style=line.style_solid, color=color.new(color.silver, 60), width = width_fibo)
    line.new(plbar1, plvalue1-(plvalue1-phvalue1)*0.236,    plbar1+ rightbars+extend_fibo, plvalue1-(plvalue1-phvalue1)*0.236,     style=line.style_solid, color=color.new(color.red, 60), width = width_fibo)
    line.new(plbar1, plvalue1-(plvalue1-phvalue1)*0.382,    plbar1+ rightbars+extend_fibo, plvalue1-(plvalue1-phvalue1)*0.382,     style=line.style_solid, color=color.new(#81c784, 60), width = width_fibo)
    line.new(plbar1, plvalue1-(plvalue1-phvalue1)*0.500,    plbar1+ rightbars+extend_fibo, plvalue1-(plvalue1-phvalue1)*0.500,     style=line.style_solid, color=color.new(color.green, 60), width = width_fibo)
    line.new(plbar1, plvalue1-(plvalue1-phvalue1)*0.618,    plbar1+ rightbars+extend_fibo, plvalue1-(plvalue1-phvalue1)*0.618,     style=line.style_solid, color=color.new(#089981, 60), width = width_fibo)
    line.new(plbar1, plvalue1-(plvalue1-phvalue1)*0.786,    plbar1+ rightbars+extend_fibo, plvalue1-(plvalue1-phvalue1)*0.786,     style=line.style_solid, color=color.new(color.aqua, 60), width = width_fibo)
    line.new(phbar1, phvalue1,                              plbar1+ rightbars+extend_fibo, phvalue1,                               style=line.style_solid, color=color.new(color.silver, 60), width = width_fibo)
    p1=line.new(plbar2, plv2low,                               plbar1+ rightbars+extend_sup_res, plv2low,                                 style=line.style_solid, color=color.new(color.red, 20), width = width_sup_res)
    p2=line.new(plbar2, plvalue2,                              plbar1+ rightbars+extend_sup_res, plvalue2,                                style=line.style_solid, color=color.new(color.red, 20), width = width_sup_res)
    linefill.new(p1, p2, color = color.new(color.red, transp =85))
    if plvalue2 > plvalue3
        line.new(plbar3, plvalue3, plbar2, plvalue2, style=line.style_dotted, color=color.lime, width = width_trendline)
        line.new(plbar2, plvalue2, bar_index, sup_y, style=line.style_dotted, color=color.lime, width = width_trendline)
    if close>plvalue1-(plvalue1-phvalue1)*0.382 and alertshort_input == 'Fibo 0.382'
        alert(message = "Fibo 0.382", freq = alert.freq_once_per_bar)
    if close>plvalue1-(plvalue1-phvalue1)*0.500 and alertshort_input == 'Fibo 0.5'
        alert(message = "Fibo 0.5", freq = alert.freq_once_per_bar)
    if close>plvalue1-(plvalue1-phvalue1)*0.618 and alertshort_input == 'Fibo 0.618'
        alert(message = "Fibo 0.618", freq = alert.freq_once_per_bar)
    if close>plvalue1-(plvalue1-phvalue1)*0.786 and alertshort_input == 'Fibo 0.786'
        alert(message = "Fibo 0.786", freq = alert.freq_once_per_bar)
    if close>plvalue2                           and alertshort_input == 'Resistant Zone'
        alert(message = "Resistant Zone",   freq = alert.freq_once_per_bar)
    if close>sup_y - sup_y*0.005                and alertshort_input == 'Trendline'
        alert(message = "Trendline",        freq = alert.freq_once_per_bar)
    var label labelfibo0 = na
    label.delete(labelfibo0)
    labelfibo0 := label.new(x=distance_x, y=plvalue1-(plvalue1-phvalue1)*0,        text='0', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo236 = na
    label.delete(labelfibo236)
    labelfibo236 := label.new(x=distance_x, y=plvalue1-(plvalue1-phvalue1)*0.236,  text='0.236', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo382 = na
    label.delete(labelfibo382)
    labelfibo382 := label.new(x=distance_x, y=plvalue1-(plvalue1-phvalue1)*0.382,  text='0.382', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo5 = na
    label.delete(labelfibo5)
    labelfibo5 := label.new(x=distance_x, y=plvalue1-(plvalue1-phvalue1)*0.5,      text='0.5', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo618 = na
    label.delete(labelfibo618)
    labelfibo618 := label.new(x=distance_x, y=plvalue1-(plvalue1-phvalue1)*0.618,  text='0.618', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo786 = na
    label.delete(labelfibo786)
    labelfibo786 := label.new(x=distance_x, y=plvalue1-(plvalue1-phvalue1)*0.786,  text='0.786', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
    var label labelfibo1 = na
    label.delete(labelfibo1)
    labelfibo1 := label.new(x=distance_x, y=plvalue1-(plvalue1-phvalue1)*1,        text='1', color=color.new(#000000, 100), textcolor = color_fibo_label, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)

Overview

Price Action as in Book: Fibonacci + Support/Resistant + Trendline calculates pivot points using customizable left and right bar counts and marks confirmed pivot structures with visual markers. The script projects trendlines and Fibonacci retracement levels into future bars to highlight potential support and resistance zones. Users can customize line extension lengths, visual styling, line widths, and alert thresholds.

Details

Published by

theonetrade on GitHub

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
Find entry Longbooltruebuyonly
Find entry Shortboolfalsesellonly
Pivot Detection: Left Barsint10leftbars
Pivot Detection: Right Barsint5rightbars
Width Fibonacci levelsint2width_fibo
Width Sup/Res levelsint2width_sup_res
Width Trendlineint2width_trendline
Extentionint5extend_fibo
Color Labelscolorcolor.new(color.yellow, 0)color_fibo_label
Extentionint5extend_sup_res
Set alert Long Trade when price teststringFibo 0.5alert_input
Set alert Short Trade when price teststringFibo 0.5alertshort_input
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 Support & resistance 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