Indicator · Pine Script v6 · On the chart

Fibonacci Auto Buy/Sell Signals

by Ahmed-GoCode· code credited to Ahmed - Quant-Edge Indicators

Fibonacci Auto Buy/Sell Signals calculates dynamic Fibonacci retracement levels (0.236, 0.382, 0.5, 0.618) and extension levels (1.618, 2.618) based on 50-period swing highs and lows.

View on GitHub

GitHub stars53on the repository
Pine versionv6current
Lines of code77
Settings0inputs
LicenceMPL-2.0
Last update2 months ago17 Aug 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

77 lines of Pine Script v6 from Quant-Edge-Indicators/Fibonacci & FVG/Fibonacci AutoSignals.pinescript, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

Fibonacci AutoSignals.pinescript
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Ahmed - Quant-Edge Indicators
//@version=6
indicator("Fibonacci Auto Buy/Sell Signals", overlay=true)

// Define Fibonacci retracement and extension levels
retracementLevel1 = 0.236
retracementLevel2 = 0.382
retracementLevel3 = 0.5
retracementLevel4 = 0.618
extensionLevel1 = 1.618
extensionLevel2 = 2.618

// Define lookback periods for swing high/low
lookbackPeriodHigh = 50
lookbackPeriodLow = 50

// Calculate swing high and swing low for Fibonacci
swingHigh = ta.highest(high, lookbackPeriodHigh)
swingLow = ta.lowest(low, lookbackPeriodLow)

// Calculate Fibonacci retracement levels
fibRetrace1 = swingHigh - (swingHigh - swingLow) * retracementLevel1
fibRetrace2 = swingHigh - (swingHigh - swingLow) * retracementLevel2
fibRetrace3 = swingHigh - (swingHigh - swingLow) * retracementLevel3
fibRetrace4 = swingHigh - (swingHigh - swingLow) * retracementLevel4

// Calculate Fibonacci extension levels
fibExtension1 = swingLow + (swingHigh - swingLow) * extensionLevel1
fibExtension2 = swingLow + (swingHigh - swingLow) * extensionLevel2

// Plot Fibonacci retracement levels dynamically
var line fibLine1 = na
var line fibLine2 = na
var line fibLine3 = na
var line fibLine4 = na
var line extLine1 = na
var line extLine2 = na

if bar_index > 1
    line.delete(fibLine1)
    line.delete(fibLine2)
    line.delete(fibLine3)
    line.delete(fibLine4)
    line.delete(extLine1)
    line.delete(extLine2)

    fibLine1 := line.new(x1=bar_index[1], y1=fibRetrace1, x2=bar_index, y2=fibRetrace1, color=color.green, width=1, style=line.style_dotted)
    fibLine2 := line.new(x1=bar_index[1], y1=fibRetrace2, x2=bar_index, y2=fibRetrace2, color=color.green, width=1, style=line.style_dotted)
    fibLine3 := line.new(x1=bar_index[1], y1=fibRetrace3, x2=bar_index, y2=fibRetrace3, color=color.green, width=1, style=line.style_dotted)
    fibLine4 := line.new(x1=bar_index[1], y1=fibRetrace4, x2=bar_index, y2=fibRetrace4, color=color.green, width=1, style=line.style_dotted)

    extLine1 := line.new(x1=bar_index[1], y1=fibExtension1, x2=bar_index, y2=fibExtension1, color=color.red, width=1, style=line.style_dotted)
    extLine2 := line.new(x1=bar_index[1], y1=fibExtension2, x2=bar_index, y2=fibExtension2, color=color.red, width=1, style=line.style_dotted)

// Define buy and sell signals
buySignal = ta.crossover(close, fibRetrace4)
sellSignal = ta.crossunder(close, fibRetrace1)

// Plot buy and sell signals on the chart
plotshape(series=buySignal, title="Buy Signal", location=location.belowbar, color=color.new(color.green, 0), style=shape.labelup, text="BUY")
plotshape(series=sellSignal, title="Sell Signal", location=location.abovebar, color=color.new(color.red, 0), style=shape.labeldown, text="SELL")

// Targets and stop-loss
entryLevel = close
target1 = fibExtension1
target2 = fibExtension2
stopLoss = fibRetrace3

// Display targets and stop-loss on chart
label.new(bar_index, target1, str.tostring(target1, "#.##"), style=label.style_label_down, color=color.new(color.green, 80))
label.new(bar_index, target2, str.tostring(target2, "#.##"), style=label.style_label_down, color=color.new(color.green, 80))
label.new(bar_index, stopLoss, "Stop Loss: " + str.tostring(stopLoss, "#.##"), style=label.style_label_up, color=color.new(color.red, 80))

// Alerts
alertcondition(buySignal, "Buy Alert", "Buy signal triggered!")
alertcondition(sellSignal, "Sell Alert", "Sell signal triggered!")

Overview

Fibonacci Auto Buy/Sell Signals plots dotted retracement and extension lines directly on the price chart. A buy signal triggers when the closing price crosses above the 0.618 retracement level, while a sell signal triggers when price crosses below the 0.236 level. The script also displays target and stop-loss price labels along with built-in alert conditions.

Details

Published by

Ahmed-GoCode on GitHub

Code credit

Ahmed - Quant-Edge Indicators, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Support & resistance

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

fair-value-gapfibonaccimarket-structurepine-scriptrsi-strategysmart-money-conceptstechnical-analysistradingviewalgorithmic-tradingcrypto-trading

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

948 stars

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 10 days ago · GPL-3.0 GitHub repository of Moving Average Channel

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker

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 4 years ago · None stated GitHub repository of Function - Linear Regression

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