Auto Fibonacci From Previous High & Low w/ Percentages & Alerts For ThinkOrSwim

CashMoney

Member
VIP
The author states: This is an auto fibonacci level generating indicator that uses the high and low from the previous day, week, month, quarter or year. It also has a table with real time updates of how far away the nearest fibonacci levels are above and below the current price, represented in percentages. It includes alerts for each level as well if you want to be notified of price crossing fibonacci levels without watching the chart.

HOW TO USE
Fibonacci levels are also known as the golden ratio and are popular levels for traders to use as support and resistance levels. Expect price to bounce off of these levels regularly.

The previous high and low are marked as white lines. These are very important levels so make sure to pay attention when price reaches these lines.

Make sure to check out the higher timeframes for major levels.

Each fibonacci line retracement and extension up to the 3.272 level in each direction is displayed as red or green depending on whether price is above or below that level.

The retracement levels used are: previous high, .117, .236, .382, .5, .618, .786, .883, previous low, 1.272, 1.618, 2, 2.272, 2.618, 3 and 3.272.

The extension levels used are: .272, .618, 1, 1.272, 1.618, 2, 2.272, 2.618, 3 and 3.272.

In the indicator settings input tab you can quickly change the timeframe used, turn lines on/off, upper line colors, lower line colors, previous high and low line colors, line width, turn percentage table on/off, change the color of the percentage table and move the percentage table to a different location on the chart.

The indicator includes alerts for each fibonacci level as well, just set your fibonacci timeframe on your favorite ticker and turn on tradingview alerts for alert() calls.

MARKETS
This indicator can be used as a signal on all markets, including stocks, crypto, futures and forex.

TIMEFRAMES
This auto fibonacci indicator can be used on all timeframes.

TIPS
Try using numerous indicators of ours on your chart so you can instantly see the bullish or bearish trend of multiple indicators in real time without having to analyze the data. Some of our favorites are our Buy & Sell Pressure Colored Candles, Directional Movement Index + Fisher Transform, Volume Profile W/ Buy & Sell Pressure Labels, Auto Support And Resistance and Money Flow Index in combination with this Auto Fibonacci. They all have real time Bullish and Bearish labels or percentage gap info as well so you can immediately understand each indicator's trend and how far away major levels are in percentages.

aziPAu2.png


Original indicator
https://www.tradingview.com/script/...-From-Previous-High-Low-w-Percentages-Alerts/
The ThinkOrSwim study can be found in the next post.
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hi,

please help convert this indicator! Thank you @samer800

https://www.tradingview.com/script/...-From-Previous-High-Low-w-Percentages-Alerts/

Code:
// © FriendOfTheTrend
//@version=5

indicator("Auto Fibonacci From Previous D/W/M/Q/Y High & Low With Percentages & Alerts", shorttitle="Auto Fibonacci by Trend Friend", overlay=true)

//Fib On/Off
fibOn = input.bool(true, title="Turn Fibonacci Levels On/Off")

//Get Timeframe And Previous High And Low
timeFrame = input.timeframe("1D", title="Timeframe", options=["1D", "1W", "1M", "3M", "12M"])
tickerHigh = request.security(syminfo.tickerid, timeFrame, high[1], barmerge.gaps_off, barmerge.lookahead_on)
tickerLow = request.security(syminfo.tickerid, timeFrame, low[1], barmerge.gaps_off, barmerge.lookahead_on)

//S&R Line Colors
supportColor = input.color(color.lime, title="Support/Lower Line Color", group="Line Style")
resistanceColor = input.color(color.red, title="Resistance/Higher Line Color", group="Line Style")

//High & Low Line Colors
highColor = input.color(color.white, title="Previous High Line Color", group="Line Style")
lowColor = input.color(color.white, title="Previous Low Line Color", group="Line Style")

//Linewidth
lw = input.int(1, title="Line Width", minval=1, maxval=4, group="Line Style")

//Table On/Off
dataTableOn = input.bool(true, title="Percentage Updates Table On/Off", group="Info Table")

//Table Colors
tableColor = input.color(color.blue, title="Percentage Table Color", group="Info Table")
previousLabelColor = input.color(color.purple, title="Previous Timeframe Being Used Label", group="Info Table")

//Table Positions
bright = position.bottom_right
bleft = position.bottom_left
bcenter = position.bottom_center
tright = position.top_right
tleft = position.top_left
tcenter = position.top_center
mright = position.middle_right
mleft = position.middle_left
mcenter = position.middle_center
tablePosition = input.string(bright, title="Table Position", options=[bright, bleft, bcenter, tright, tleft, tcenter, mright, mleft, mcenter], group="Info Table")

//Table Position Logic
tpos = position.bottom_right

if tablePosition == bleft
    tpos := bleft
if tablePosition == bright
    tpos := bright
if tablePosition == bcenter
    tpos := bcenter
if tablePosition == tleft
    tpos := tleft
if tablePosition == tright
    tpos := tright
if tablePosition == tcenter
    tpos := tcenter
if tablePosition == mleft
    tpos := mleft
if tablePosition == mright
    tpos := mright
if tablePosition == mcenter
    tpos := mcenter

//Calculate Fibonacci Levels
fib(level) =>
    fibGap = tickerHigh - tickerLow
    fibLevel = tickerHigh - (fibGap * level)

fibext(extlevel) =>
    fibExtGap = tickerLow - tickerHigh
    fibExtLevel = tickerHigh - (fibExtGap * extlevel)

//Fib Retacement Variables
fib1 = if fibOn
    fib(.0)
fib2 = if fibOn
    fib(.117)
fib3 = if fibOn
    fib(.236)
fib4 = if fibOn
    fib(.382)
fib5 = if fibOn
    fib(.5)
fib6 = if fibOn
    fib(.618)
fib7 = if fibOn
    fib(.786)
fib8 = if fibOn
    fib(.883)
fib9 = if fibOn
    fib(1)
fib10 = if fibOn
    fib(1.272)
fib11 = if fibOn
    fib(1.618)
fib12 = if fibOn
    fib(2)
fib13 = if fibOn
    fib(2.272)
fib14 = if fibOn
    fib(2.618)
fib15 = if fibOn
    fib(3)
fib16 = if fibOn
    fib(3.272)

//Fib Extension Variables
fibext1 = if fibOn
    fibext(.272)
fibext2 = if fibOn
    fibext(.618)
fibext3 = if fibOn
    fibext(1)
fibext4 = if fibOn
    fibext(1.272)
fibext5 = if fibOn
    fibext(1.618)
fibext6 = if fibOn
    fibext(2)
fibext7 = if fibOn
    fibext(2.272)
fibext8 = if fibOn
    fibext(2.618)
fibext9 = if fibOn
    fibext(3)
fibext10 = if fibOn
    fibext(3.272)

//Fibonacci Retracements
plot(fib1, title="Previous High", color=highColor, linewidth=lw, style=plot.style_line)
plot(fib2, title=".117 Fib Ret", color=close > fib2 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib3, title=".236 Fib Ret", color=close > fib3 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib4, title=".382 Fib Ret", color=close > fib4 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib5, title=".50 Fib Ret", color=close > fib5 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib6, title=".618 Fib Ret", color=close > fib6 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib7, title=".786 Fib Ret", color=close > fib7 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib8, title=".883 Fib Ret", color=close > fib8 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib9, title="Previous Low", color=lowColor, linewidth=lw, style=plot.style_line)
plot(fib10, title="1.272 Fib Ret", color=close > fib10 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib11, title="1.618 Fib Ret", color=close > fib11 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib12, title="2 Fib Ret", color=close > fib12 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib13, title="2.272 Fib Ret", color=close > fib13 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib14, title="2.618 Fib Ret", color=close > fib14 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib15, title="3 Fib Ret", color=close > fib15 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fib16, title="3.272 Fib Ret", color=close > fib16 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)

//Fibonacci Extensions
plot(fibext1, title=".272 Fib Ext", color=close > fibext1 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fibext2, title=".618 Fib Ext", color=close > fibext2 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fibext3, title="1 Fib Ext", color=close > fibext3 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fibext4, title="1.272 Fib Ext", color=close > fibext4 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fibext5, title="1.618 Fib Ext", color=close > fibext5 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fibext6, title="2 Fib Ext", color=close > fibext6 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fibext7, title="2.272 Fib Ext", color=close > fibext7 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fibext8, title="2.618 Fib Ext", color=close > fibext8 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fibext9, title="3 Fib Ext", color=close > fibext9 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)
plot(fibext10, title="3.272 Fib Ext", color=close > fibext10 ? supportColor : resistanceColor, linewidth=lw, style=plot.style_line)

//Price Diiference Fib Variables
float priceDiffFibDown = 0
float priceDiffFibUp = 0
fibUpText = ""
fibDownText = ""

//Price difference Fib Extensions
if close > fib1 and close < fibext1
    priceDiffFibDown := (close - fib1) / close * 100
    priceDiffFibUp := (fibext1 - close) / fibext1 * 100
    fibUpText := " from .272 Fib Ext"
    fibDownText := " from Previous High"
else if close > fibext1 and close < fibext2
    priceDiffFibDown := (close - fibext1) / close * 100
    priceDiffFibUp := (fibext2 - close) / fibext2 * 100
    fibUpText := " from .618 Fib Ext"
    fibDownText := " from .272 Fib Ext"
else if close > fibext2 and close < fibext3
    priceDiffFibDown := (close - fibext2) / close * 100
    priceDiffFibUp := (fibext3 - close) / fibext3 * 100
    fibUpText := " from 1 Fib Ext"
    fibDownText := " from .618 Fib Ext"
else if close > fibext3 and close < fibext4
    priceDiffFibDown := (close - fibext3) / close * 100
    priceDiffFibUp := (fibext4 - close) / fibext4 * 100
    fibUpText := " from 1.272 Fib Ext"
    fibDownText := " from 1 Fib Ext"
else if close > fibext4 and close < fibext5
    priceDiffFibDown := (close - fibext4) / close * 100
    priceDiffFibUp := (fibext5 - close) / fibext5 * 100
    fibUpText := " from 1.618 Fib Ext"
    fibDownText := " from 1.272 Fib Ext"
else if close > fibext5 and close < fibext6
    priceDiffFibDown := (close - fibext5) / close * 100
    priceDiffFibUp := (fibext6 - close) / fibext6 * 100
    fibUpText := " from 2 Fib Ext"
    fibDownText := " from 1.618 Fib Ext"
else if close > fibext6 and close < fibext7
    priceDiffFibDown := (close - fibext6) / close * 100
    priceDiffFibUp := (fibext7 - close) / fibext7 * 100
    fibUpText := " from 2.272 Fib Ext"
    fibDownText := " from 2 Fib Ext"
else if close > fibext7 and close < fibext8
    priceDiffFibDown := (close - fibext7) / close * 100
    priceDiffFibUp := (fibext8 - close) / fibext8 * 100
    fibUpText := " from 2.618 Fib Ext"
    fibDownText := " from 2.272 Fib Ext"
else if close > fibext8 and close < fibext9
    priceDiffFibDown := (close - fibext8) / close * 100
    priceDiffFibUp := (fibext9 - close) / fibext9 * 100
    fibUpText := " from 3 Fib Ext"
    fibDownText := " from 2.618 Fib Ext"
else if close > fibext9 and close < fibext10
    priceDiffFibDown := (close - fibext9) / close * 100
    priceDiffFibUp := (fibext10 - close) / fibext10 * 100
    fibUpText := " from 3.272 Fib Ext"
    fibDownText := " from 3 Fib Ext"
else if close > fibext10
    fibUpText := "Price Above Fib Levels"
    fibDownText := "Price Above Fib Levels"

//Price difference Fib Retracements
else if close < fib1 and close > fib2
    priceDiffFibUp := (close - fib1) / close * -100
    priceDiffFibDown := (fib2 - close) / fib2 * -100
    fibUpText := " from Previous High"
    fibDownText := " from .117 Fib Ret"
else if close < fib2 and close > fib3
    priceDiffFibUp := (close - fib2) / close * -100
    priceDiffFibDown := (fib3 - close) / fib3 * -100
    fibUpText := " from .117 Fib Ret"
    fibDownText := " from .236 Fib Ret"
else if close < fib3 and close > fib4
    priceDiffFibUp := (close - fib3) / close * -100
    priceDiffFibDown := (fib4 - close) / fib4 * -100
    fibUpText := " from .236 Fib Ret"
    fibDownText := " from .382 Fib Ret"
else if close < fib4 and close > fib5
    priceDiffFibUp := (close - fib4) / close * -100
    priceDiffFibDown := (fib5 - close) / fib5 * -100
    fibUpText := " from .382 Fib Ret"
    fibDownText := " from .5 Fib Ret"
else if close < fib5 and close > fib6
    priceDiffFibUp := (close - fib5) / close * -100
    priceDiffFibDown := (fib6 - close) / fib6 * -100
    fibUpText := " from .5 Fib Ret"
    fibDownText := " from .618 Fib Ret"
else if close < fib6 and close > fib7
    priceDiffFibUp := (close - fib6) / close * -100
    priceDiffFibDown := (fib7 - close) / fib7 * -100
    fibUpText := " from .618 Fib Ret"
    fibDownText := " from .786 Fib Ret"
else if close < fib7 and close > fib8
    priceDiffFibUp := (close - fib7) / close * -100
    priceDiffFibDown := (fib8 - close) / fib8 * -100
    fibUpText := " from .786 Fib Ret"
    fibDownText := " from .883 Fib Ret"
else if close < fib8 and close > fib9
    priceDiffFibUp := (close - fib8) / close * -100
    priceDiffFibDown := (fib9 - close) / fib9 * -100
    fibUpText := " from .883 Fib Ret"
    fibDownText := " from Previous Low"
else if close < fib9 and close > fib10
    priceDiffFibUp := (close - fib9) / close * -100
    priceDiffFibDown := (fib10 - close) / fib10 * -100
    fibUpText := " from Previous Low"
    fibDownText := " from 1.272 Fib Ret"
else if close < fib10 and close > fib11
    priceDiffFibUp := (close - fib10) / close * -100
    priceDiffFibDown := (fib11 - close) / fib11 * -100
    fibUpText := " from 1.272 Fib Ret"
    fibDownText := " from 1.618 Fib Ret"
else if close < fib11 and close > fib12
    priceDiffFibUp := (close - fib11) / close * -100
    priceDiffFibDown := (fib12 - close) / fib12 * -100
    fibUpText := " from 1.618 Fib Ret"
    fibDownText := " from 2 Fib Ret"
else if close < fib12 and close > fib13
    priceDiffFibUp := (close - fib12) / close * -100
    priceDiffFibDown := (fib13 - close) / fib13 * -100
    fibUpText := " from 2 Fib Ret"
    fibDownText := " from 2.272 Fib Ret"
else if close < fib13 and close > fib14
    priceDiffFibUp := (close - fib13) / close * -100
    priceDiffFibDown := (fib14 - close) / fib14 * -100
    fibUpText := " from 2.272 Fib Ret"
    fibDownText := " from 2.618 Fib Ret"
else if close < fib14 and close > fib15
    priceDiffFibUp := (close - fib14) / close * -100
    priceDiffFibDown := (fib15 - close) / fib15 * -100
    fibUpText := " from 2.618 Fib Ret"
    fibDownText := " from 3 Fib Ret"
else if close < fib15 and close > fib16
    priceDiffFibUp := (close - fib15) / close * -100
    priceDiffFibDown := (fib16 - close) / fib16 * -100
    fibUpText := " from 3 Fib Ret"
    fibDownText := " from 3.272 Fib Ret"
else if close < fib16
    fibUpText := "Price Below Fib Levels"
    fibDownText := "Price Below Fib Levels"

//Alert Fib Retracements
if ta.cross(close, fib1)
    alert("Price Crossing Previous High")
  
if ta.cross(close, fib2)
    alert("Price Crossing Fibonacci .117 Level")
  
if ta.cross(close, fib3)
    alert("Price Crossing Fibonacci .236 Level")
  
if ta.cross(close, fib4)
    alert("Price Crossing Fibonacci .382 Level")
  
if ta.cross(close, fib5)
    alert("Price Crossing Fibonacci .5 Level")
  
if ta.cross(close, fib6)
    alert("Price Crossing Fibonacci .618 Level")
  
if ta.cross(close, fib7)
    alert("Price Crossing Fibonacci .786 Level")
  
if ta.cross(close, fib8)
    alert("Price Crossing Fibonacci .883 Level")
  
if ta.cross(close, fib9)
    alert("Price Crossing Previous Low")
  
if ta.cross(close, fib10)
    alert("Price Crossing Fibonacci 1.272 Retracement")
  
if ta.cross(close, fib11)
    alert("Price Crossing Fibonacci 1.618 Retracement")
  
if ta.cross(close, fib12)
    alert("Price Crossing Fibonacci 2 Retracement")
  
if ta.cross(close, fib13)
    alert("Price Crossing Fibonacci 2.272 Retracement")
  
if ta.cross(close, fib14)
    alert("Price Crossing Fibonacci 2.618 Retracement")
  
if ta.cross(close, fib15)
    alert("Price Crossing Fibonacci 3 Retracement")
  
if ta.cross(close, fib16)
    alert("Price Crossing Fibonacci 3.272 Retracement")

//Alert Fib Extensions
if ta.cross(close, fibext1)
    alert("Price Crossing Fibonacci .272 Extension")
  
if ta.cross(close, fibext2)
    alert("Price Crossing Fibonacci .618 Extension")
  
if ta.cross(close, fibext3)
    alert("Price Crossing Fibonacci 1 Extension")
  
if ta.cross(close, fibext4)
    alert("Price Crossing Fibonacci 1.272 Extension")
  
if ta.cross(close, fibext5)
    alert("Price Crossing Fibonacci 1.618 Extension")
  
if ta.cross(close, fibext6)
    alert("Price Crossing Fibonacci 2 Extension")
  
if ta.cross(close, fibext7)
    alert("Price Crossing Fibonacci 2.272 Extension")
  
if ta.cross(close, fibext8)
    alert("Price Crossing Fibonacci 2.618 Extension")
  
if ta.cross(close, fibext9)
    alert("Price Crossing Fibonacci 3 Extension")
  
if ta.cross(close, fibext10)
    alert("Price Crossing Fibonacci 3.272 Extension")

//Timframe Label
timeframeLabel = ""
if timeFrame == "1D"
    timeframeLabel := "Using Previous Day"
if timeFrame == "1W"
    timeframeLabel := "Using Previous Week"
if timeFrame == "1M"
    timeframeLabel := "Using Previous Month"
if timeFrame == "3M"
    timeframeLabel := "Using Previous Quarter"
if timeFrame == "12M"
    timeframeLabel := "Using Previous Year"

//Create price difference table data
percentFromFibUp = str.tostring(priceDiffFibUp, format.percent) + str.tostring(fibUpText)
percentFromFibDown = str.tostring(priceDiffFibDown, format.percent) + str.tostring(fibDownText)

//Plot Price Difference Table
dataTable = table.new(tpos, columns=1, rows=3, bgcolor=tableColor)
if dataTableOn and  barstate.islast
    table.cell(table_id=dataTable, column=0, row=0, text=timeframeLabel, height=0, text_color=color.white, text_halign=text.align_center, text_valign= text.align_top, bgcolor=previousLabelColor)
    table.cell(table_id=dataTable, column=0, row=1, text=percentFromFibUp, height=0, text_color=color.white, text_halign=text.align_left, text_valign= text.align_top)
    table.cell(table_id=dataTable, column=0, row=2, text=percentFromFibDown, height=0, text_color=color.white, text_halign=text.align_left, text_valign= text.align_top)
check the below:

CSS:
#// Indicator for TOS
#// © FriendOfTheTrend
#indicator("Auto Fibonacci From Previous D/W/M/Q/Y High & Low With Percentages & Alerts", shorttit
# converted by Sam4Cok@Samer800    - 08/2024, Request from www.UseThinkScript.com member

input extednLines = no;
input enableRetracementsLines = yes; #(true, title="Turn Fibonacci Levels On/Off")
input enableExtensionsLines = yes;
input timeFrame = AggregationPeriod.DAY;
input showLabel = yes; #(true, title="Percentage Updates Table On/Off", group="Info Table")


def na = Double.NaN;
def last = IsNaN(close);
def extend = if extednLines then yes else !last;
def current = GetAggregationPeriod();
def tf = Max(current, timeFrame);
def tickerHigh = if last then tickerHigh[1] else high(Period = tf)[1];
def tickerLow = if last then tickerLow[1] else low(Period = tf)[1];

#/Calculate Fibonacci Levels
script fib {
    input level = 0;
    input tickerHigh = high;
    input tickerLow = low;
    def fibGap = tickerHigh - tickerLow;
    def fibLevel = tickerHigh - (fibGap * level);
    plot out = fibLevel;
}
script fibext {
    input extlevel = 0;
    input tickerHigh = high;
    input tickerLow = low;
    def fibExtGap = tickerLow - tickerHigh;
    def fibExtLevel = tickerHigh - (fibExtGap * extlevel);
    plot out = fibExtLevel;
}

def fib01;
def fib02;
def fib03;
def fib04;
def fib05;
def fib06;
def fib07;
def fib08;
def fib09;
def fib10;
def fib11;
def fib12;
def fib13;
def fib14;
def fib15;
def fib16;
if enableRetracementsLines {
    fib01 = fib(0, tickerHigh, tickerLow);
    fib02 = fib(.117, tickerHigh, tickerLow);
    fib03 = fib(.236, tickerHigh, tickerLow);
    fib04 = fib(.382, tickerHigh, tickerLow);
    fib05 = fib(.5, tickerHigh, tickerLow);
    fib06 = fib(.618, tickerHigh, tickerLow);
    fib07 = fib(.786, tickerHigh, tickerLow);
    fib08 = fib(.883, tickerHigh, tickerLow);
    fib09 = fib(1, tickerHigh, tickerLow);
    fib10 = fib(1.272, tickerHigh, tickerLow);
    fib11 = fib(1.618, tickerHigh, tickerLow);
    fib12 = fib(2, tickerHigh, tickerLow);
    fib13 = fib(2.272, tickerHigh, tickerLow);
    fib14 = fib(2.618, tickerHigh, tickerLow);
    fib15 = fib(3, tickerHigh, tickerLow);
    fib16 = fib(3.272, tickerHigh, tickerLow);
} else {
    fib01 = na;
    fib02 = na;
    fib03 = na;
    fib04 = na;
    fib05 = na;
    fib06 = na;
    fib07 = na;
    fib08 = na;
    fib09 = na;
    fib10 = na;
    fib11 = na;
    fib12 = na;
    fib13 = na;
    fib14 = na;
    fib15 = na;
    fib16 = na;
}
#//Fib Extension Variables
def fibext01;
def fibext02;
def fibext03;
def fibext04;
def fibext05;
def fibext06;
def fibext07;
def fibext08;
def fibext09;
def fibext10;
if enableExtensionsLines {
    fibext01 = fibext(.272, tickerHigh, tickerLow);
    fibext02 = fibext(.618, tickerHigh, tickerLow);
    fibext03 = fibext(1, tickerHigh, tickerLow);
    fibext04 = fibext(1.272, tickerHigh, tickerLow);
    fibext05 = fibext(1.618, tickerHigh, tickerLow);
    fibext06 = fibext(2, tickerHigh, tickerLow);
    fibext07 = fibext(2.272, tickerHigh, tickerLow);
    fibext08 = fibext(2.618, tickerHigh, tickerLow);
    fibext09 = fibext(3, tickerHigh, tickerLow);
    fibext10 = fibext(3.272, tickerHigh, tickerLow);
} else {
    fibext01 = na;
    fibext02 = na;
    fibext03 = na;
    fibext04 = na;
    fibext05 = na;
    fibext06 = na;
    fibext07 = na;
    fibext08 = na;
    fibext09 = na;
    fibext10 = na;
}

#//Fibonacci Retracements

plot fibLine01 = if extend and fib01 then fib01 else na;
plot fibLine02 = if extend and fib02 then fib02 else na;
plot fibLine03 = if extend and fib03 then fib03 else na;
plot fibLine04 = if extend and fib04 then fib04 else na;
plot fibLine05 = if extend and fib05 then fib05 else na;
plot fibLine06 = if extend and fib06 then fib06 else na;
plot fibLine07 = if extend and fib07 then fib07 else na;
plot fibLine08 = if extend and fib08 then fib08 else na;
plot fibLine09 = if extend and fib09 then fib09 else na;
plot fibLine10 = if extend and fib10 then fib10 else na;
plot fibLine11 = if extend and fib11 then fib11 else na;
plot fibLine12 = if extend and fib12 then fib12 else na;
plot fibLine13 = if extend and fib13 then fib13 else na;
plot fibLine14 = if extend and fib14 then fib14 else na;
plot fibLine15 = if extend and fib15 then fib15 else na;
plot fibLine16 = if extend and fib16 then fib16 else na;
#//Fibonacci Extensions
plot fibextLine01 = if extend and fibext01 then fibext01 else na;
plot fibextLine02 = if extend and fibext02 then fibext02 else na;
plot fibextLine03 = if extend and fibext03 then fibext03 else na;
plot fibextLine04 = if extend and fibext04 then fibext04 else na;
plot fibextLine05 = if extend and fibext05 then fibext05 else na;
plot fibextLine06 = if extend and fibext06 then fibext06 else na;
plot fibextLine07 = if extend and fibext07 then fibext07 else na;
plot fibextLine08 = if extend and fibext08 then fibext08 else na;
plot fibextLine09 = if extend and fibext09 then fibext09 else na;
plot fibextLine10 = if extend and fibext10 then fibext10 else na;

fibLine01.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine02.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine03.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine04.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine05.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine06.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine07.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine08.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine09.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine13.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine14.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine15.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine16.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine01.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine02.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine03.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine04.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine05.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine06.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine07.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine08.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine09.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


fibLine02.SetDefaultColor(Color.GRAY);
fibLine03.SetDefaultColor(Color.GRAY);
fibLine04.SetDefaultColor(Color.GRAY);
fibLine05.SetDefaultColor(Color.GRAY);
fibLine06.SetDefaultColor(Color.GRAY);
fibLine07.SetDefaultColor(Color.GRAY);
fibLine08.SetDefaultColor(Color.GRAY);
fibLine10.SetDefaultColor(Color.GRAY);
fibLine11.SetDefaultColor(Color.GRAY);
fibLine12.SetDefaultColor(Color.GRAY);
fibLine13.SetDefaultColor(Color.GRAY);
fibLine14.SetDefaultColor(Color.GRAY);
fibLine15.SetDefaultColor(Color.GRAY);
fibLine16.SetDefaultColor(Color.GRAY);
fibextLine01.SetDefaultColor(Color.GRAY);
fibextLine02.SetDefaultColor(Color.GRAY);
fibextLine03.SetDefaultColor(Color.GRAY);
fibextLine04.SetDefaultColor(Color.GRAY);
fibextLine05.SetDefaultColor(Color.GRAY);
fibextLine06.SetDefaultColor(Color.GRAY);
fibextLine07.SetDefaultColor(Color.GRAY);
fibextLine08.SetDefaultColor(Color.GRAY);
fibextLine09.SetDefaultColor(Color.GRAY);
fibextLine10.SetDefaultColor(Color.GRAY);
fibLine01.SetDefaultColor(Color.WHITE);
fibLine02.AssignValueColor(if close > fib02 then Color.CYAN else Color.MAGENTA);
fibLine03.AssignValueColor(if close > fib03 then Color.CYAN else Color.MAGENTA);
fibLine04.AssignValueColor(if close > fib04 then Color.CYAN else Color.MAGENTA);
fibLine05.AssignValueColor(if close > fib05 then Color.CYAN else Color.MAGENTA);
fibLine06.AssignValueColor(if close > fib06 then Color.CYAN else Color.MAGENTA);
fibLine07.AssignValueColor(if close > fib07 then Color.CYAN else Color.MAGENTA);
fibLine08.AssignValueColor(if close > fib08 then Color.CYAN else Color.MAGENTA);
fibLine09.SetDefaultColor(Color.WHITE);
fibLine10.AssignValueColor(if close > fib10 then Color.CYAN else Color.MAGENTA);
fibLine11.AssignValueColor(if close > fib11 then Color.CYAN else Color.MAGENTA);
fibLine12.AssignValueColor(if close > fib12 then Color.CYAN else Color.MAGENTA);
fibLine13.AssignValueColor(if close > fib13 then Color.CYAN else Color.MAGENTA);
fibLine14.AssignValueColor(if close > fib14 then Color.CYAN else Color.MAGENTA);
fibLine15.AssignValueColor(if close > fib15 then Color.CYAN else Color.MAGENTA);
fibLine16.AssignValueColor(if close > fib16 then Color.CYAN else Color.MAGENTA);
fibextLine01.AssignValueColor(if close > fibext01 then Color.CYAN else Color.MAGENTA);
fibextLine02.AssignValueColor(if close > fibext02 then Color.CYAN else Color.MAGENTA);
fibextLine03.AssignValueColor(if close > fibext03 then Color.CYAN else Color.MAGENTA);
fibextLine04.AssignValueColor(if close > fibext04 then Color.CYAN else Color.MAGENTA);
fibextLine05.AssignValueColor(if close > fibext05 then Color.CYAN else Color.MAGENTA);
fibextLine06.AssignValueColor(if close > fibext06 then Color.CYAN else Color.MAGENTA);
fibextLine07.AssignValueColor(if close > fibext07 then Color.CYAN else Color.MAGENTA);
fibextLine08.AssignValueColor(if close > fibext08 then Color.CYAN else Color.MAGENTA);
fibextLine09.AssignValueColor(if close > fibext09 then Color.CYAN else Color.MAGENTA);
fibextLine10.AssignValueColor(if close > fibext10 then Color.CYAN else Color.MAGENTA);

#//Price Diiference Fib Variables
def priceDiffFibDown;
def priceDiffFibUp;
def fibUpText;
def fibDownText;
#//Price difference Fib Extensions
if close > fib01 and close < fibext01 {
    priceDiffFibDown = (close - fib01) / close;
    priceDiffFibUp = (fibext01 - close) / fibext01;
    fibUpText = 0.272;
    fibDownText = 100;
} else if close > fibext01 and close < fibext02 {
    priceDiffFibDown = (close - fibext01) / close;
    priceDiffFibUp = (fibext02 - close) / fibext02;
    fibUpText = 0.618;
    fibDownText = 0.272;
} else if close > fibext02 and close < fibext03 {
    priceDiffFibDown = (close - fibext02) / close;
    priceDiffFibUp = (fibext03 - close) / fibext03;
    fibUpText = 1.000;
    fibDownText = 0.618;
} else if close > fibext03 and close < fibext04 {
    priceDiffFibDown = (close - fibext03) / close;
    priceDiffFibUp = (fibext04 - close) / fibext04;
    fibUpText = 1.272;
    fibDownText = 1.000;
} else if close > fibext04 and close < fibext05 {
    priceDiffFibDown = (close - fibext04) / close;
    priceDiffFibUp = (fibext05 - close) / fibext05;
    fibUpText = 1.618;
    fibDownText = 1.272;
} else if close > fibext05 and close < fibext06 {
    priceDiffFibDown = (close - fibext05) / close;
    priceDiffFibUp = (fibext06 - close) / fibext06;
    fibUpText = 2.000;
    fibDownText = 1.618;
} else if close > fibext06 and close < fibext07 {
    priceDiffFibDown = (close - fibext06) / close;
    priceDiffFibUp = (fibext07 - close) / fibext07;
    fibUpText = 2.272;
    fibDownText = 2.000;
} else if close > fibext07 and close < fibext08 {
    priceDiffFibDown = (close - fibext07) / close;
    priceDiffFibUp = (fibext08 - close) / fibext08;
    fibUpText = 2.618;
    fibDownText = 2.272;
} else if close > fibext08 and close < fibext09 {
    priceDiffFibDown = (close - fibext08) / close;
    priceDiffFibUp = (fibext09 - close) / fibext09;
    fibUpText = 3.000;
    fibDownText = 2.618;
} else if close > fibext09 and close < fibext10 {
    priceDiffFibDown = (close - fibext09) / close;
    priceDiffFibUp = (fibext10 - close) / fibext10;
    fibUpText = 3.272;
    fibDownText = 3.000;
} else if close > fibext10 {
    priceDiffFibDown = 0;
    priceDiffFibUp = 0;
    fibUpText = 50;
    fibDownText = 50;
#//Price difference Fib Retracements
} else if close < fib01 and close > fib02 {
    priceDiffFibUp = (close - fib01) / close * -1;
    priceDiffFibDown = (fib02 - close) / fib02 * -1;
    fibUpText = 100;
    fibDownText = 0.117;
} else if close < fib02 and close > fib03 {
    priceDiffFibUp = (close - fib02) / close * -1;
    priceDiffFibDown = (fib03 - close) / fib03 * -1;
    fibUpText = 0.117;
    fibDownText = 0.236;
} else if close < fib03 and close > fib04 {
    priceDiffFibUp = (close - fib03) / close * -1;
    priceDiffFibDown = (fib04 - close) / fib04 * -1;
    fibUpText = 0.236;
    fibDownText = 0.382;
} else if close < fib04 and close > fib05 {
    priceDiffFibUp = (close - fib04) / close * -1;
    priceDiffFibDown = (fib05 - close) / fib05 * -1;
    fibUpText = 0.382;
    fibDownText = 0.500;
} else if close < fib05 and close > fib06 {
    priceDiffFibUp = (close - fib05) / close * -1;
    priceDiffFibDown = (fib06 - close) / fib06 * -1;
    fibUpText = 0.500;
    fibDownText = 0.618;
} else if close < fib06 and close > fib07 {
    priceDiffFibUp = (close - fib06) / close * -1;
    priceDiffFibDown = (fib07 - close) / fib07 * -1;
    fibUpText = 0.618;
    fibDownText = 0.786;
} else if close < fib07 and close > fib08 {
    priceDiffFibUp = (close - fib07) / close * -1;
    priceDiffFibDown = (fib08 - close) / fib08 * -1;
    fibUpText = 0.786;
    fibDownText = 0.883;
} else if close < fib08 and close > fib09 {
    priceDiffFibUp = (close - fib08) / close * -1;
    priceDiffFibDown = (fib09 - close) / fib09 * -1;
    fibUpText = 0.883;
    fibDownText = -100;
} else if close < fib09 and close > fib10 {
    priceDiffFibUp = (close - fib09) / close * -1;
    priceDiffFibDown = (fib10 - close) / fib10 * -1;
    fibUpText = -100;
    fibDownText = 1.272;
} else if close < fib10 and close > fib11 {
    priceDiffFibUp = (close - fib10) / close * -1;
    priceDiffFibDown = (fib11 - close) / fib11 * -1;
    fibUpText = 1.272;
    fibDownText = 1.618;
} else if close < fib11 and close > fib12 {
    priceDiffFibUp = (close - fib11) / close * -1;
    priceDiffFibDown = (fib12 - close) / fib12 * -1;
    fibUpText = 1.618;
    fibDownText = 2.000;
} else if close < fib12 and close > fib13 {
    priceDiffFibUp = (close - fib12) / close * -1;
    priceDiffFibDown = (fib13 - close) / fib13 * -1;
    fibUpText = 2.000;
    fibDownText = 2.272;
} else if close < fib13 and close > fib14 {
    priceDiffFibUp = (close - fib13) / close * -1;
    priceDiffFibDown = (fib14 - close) / fib14 * -1;
    fibUpText = 2.272;
    fibDownText = 2.618;
} else if close < fib14 and close > fib15 {
    priceDiffFibUp = (close - fib14) / close * -1;
    priceDiffFibDown = (fib15 - close) / fib15 * -1;
    fibUpText = 2.618;
    fibDownText = 3.000;
} else if close < fib15 and close > fib16 {
    priceDiffFibUp = (close - fib15) / close * -1;
    priceDiffFibDown = (fib16 - close) / fib16 * -1;
    fibUpText = 3.000;
    fibDownText = 3.272;
} else if close < fib16 {
    priceDiffFibUp = 0;
    priceDiffFibDown = 0;
    fibUpText = -50;
    fibDownText = -50;
} else {
    priceDiffFibUp = 0;
    priceDiffFibDown = 0;
    fibUpText = na;
    fibDownText = na;
}

AddLabel(showLabel and !last and (isNaN(fib01) or isNaN(fibext01)), "No Data", Color.WHITE);


AddLabel(showLabel and !last and close < fib01 and !isNaN(fib01) and !isNaN(fibext01), AsPercent(priceDiffFibUp) +
        if fibUpText== 100 then " from Previous High" else
        if fibUpText==-100 then " from Previous Low" else
        if fibUpText== -50 then "Price Below Fib Levels" else
        " from " + fibUpText + " Fib Ret", Color.CYAN);
AddLabel(showLabel and !last and close < fib01 and !isNaN(fib01) and !isNaN(fibext01), AsPercent(priceDiffFibDown) +
        if fibDownText== 100 then " from Previous High" else
        if fibDownText==-100 then " from Previous Low" else
        if fibDownText== -50 then "Price Below Fib Levels" else
        " from " + fibDownText + " Fib Ret", Color.MAGENTA);

AddLabel(showLabel and !last and close > fib01 and !isNaN(fib01) and !isNaN(fibext01), AsPercent(priceDiffFibUp) +
        if fibUpText== 100 then " from Previous High" else
        if fibUpText==-100 then " from Previous Low" else
        if fibUpText== -50 then "Price Above Fib Levels" else
        " from " + fibUpText + " Fib Ext", Color.CYAN);
AddLabel(showLabel and !last and close > fib01 and !isNaN(fib01) and !isNaN(fibext01), AsPercent(priceDiffFibDown) +
        if fibDownText== 100 then " from Previous High" else
        if fibDownText==-100 then " from Previous Low" else
        if fibDownText== -50 then "Price Above Fib Levels" else
        " from " + fibDownText + " Fib Ext", Color.MAGENTA);


#-- ENd of CODE
 
check the below:

CSS:
#// Indicator for TOS
#// © FriendOfTheTrend
#indicator("Auto Fibonacci From Previous D/W/M/Q/Y High & Low With Percentages & Alerts", shorttit
# converted by Sam4Cok@Samer800    - 08/2024, Request from www.UseThinkScript.com member

input extednLines = no;
input enableRetracementsLines = yes; #(true, title="Turn Fibonacci Levels On/Off")
input enableExtensionsLines = yes;
input timeFrame = AggregationPeriod.DAY;
input showLabel = yes; #(true, title="Percentage Updates Table On/Off", group="Info Table")


def na = Double.NaN;
def last = IsNaN(close);
def extend = if extednLines then yes else !last;
def current = GetAggregationPeriod();
def tf = Max(current, timeFrame);
def tickerHigh = if last then tickerHigh[1] else high(Period = tf)[1];
def tickerLow = if last then tickerLow[1] else low(Period = tf)[1];

#/Calculate Fibonacci Levels
script fib {
    input level = 0;
    input tickerHigh = high;
    input tickerLow = low;
    def fibGap = tickerHigh - tickerLow;
    def fibLevel = tickerHigh - (fibGap * level);
    plot out = fibLevel;
}
script fibext {
    input extlevel = 0;
    input tickerHigh = high;
    input tickerLow = low;
    def fibExtGap = tickerLow - tickerHigh;
    def fibExtLevel = tickerHigh - (fibExtGap * extlevel);
    plot out = fibExtLevel;
}

def fib01;
def fib02;
def fib03;
def fib04;
def fib05;
def fib06;
def fib07;
def fib08;
def fib09;
def fib10;
def fib11;
def fib12;
def fib13;
def fib14;
def fib15;
def fib16;
if enableRetracementsLines {
    fib01 = fib(0, tickerHigh, tickerLow);
    fib02 = fib(.117, tickerHigh, tickerLow);
    fib03 = fib(.236, tickerHigh, tickerLow);
    fib04 = fib(.382, tickerHigh, tickerLow);
    fib05 = fib(.5, tickerHigh, tickerLow);
    fib06 = fib(.618, tickerHigh, tickerLow);
    fib07 = fib(.786, tickerHigh, tickerLow);
    fib08 = fib(.883, tickerHigh, tickerLow);
    fib09 = fib(1, tickerHigh, tickerLow);
    fib10 = fib(1.272, tickerHigh, tickerLow);
    fib11 = fib(1.618, tickerHigh, tickerLow);
    fib12 = fib(2, tickerHigh, tickerLow);
    fib13 = fib(2.272, tickerHigh, tickerLow);
    fib14 = fib(2.618, tickerHigh, tickerLow);
    fib15 = fib(3, tickerHigh, tickerLow);
    fib16 = fib(3.272, tickerHigh, tickerLow);
} else {
    fib01 = na;
    fib02 = na;
    fib03 = na;
    fib04 = na;
    fib05 = na;
    fib06 = na;
    fib07 = na;
    fib08 = na;
    fib09 = na;
    fib10 = na;
    fib11 = na;
    fib12 = na;
    fib13 = na;
    fib14 = na;
    fib15 = na;
    fib16 = na;
}
#//Fib Extension Variables
def fibext01;
def fibext02;
def fibext03;
def fibext04;
def fibext05;
def fibext06;
def fibext07;
def fibext08;
def fibext09;
def fibext10;
if enableExtensionsLines {
    fibext01 = fibext(.272, tickerHigh, tickerLow);
    fibext02 = fibext(.618, tickerHigh, tickerLow);
    fibext03 = fibext(1, tickerHigh, tickerLow);
    fibext04 = fibext(1.272, tickerHigh, tickerLow);
    fibext05 = fibext(1.618, tickerHigh, tickerLow);
    fibext06 = fibext(2, tickerHigh, tickerLow);
    fibext07 = fibext(2.272, tickerHigh, tickerLow);
    fibext08 = fibext(2.618, tickerHigh, tickerLow);
    fibext09 = fibext(3, tickerHigh, tickerLow);
    fibext10 = fibext(3.272, tickerHigh, tickerLow);
} else {
    fibext01 = na;
    fibext02 = na;
    fibext03 = na;
    fibext04 = na;
    fibext05 = na;
    fibext06 = na;
    fibext07 = na;
    fibext08 = na;
    fibext09 = na;
    fibext10 = na;
}

#//Fibonacci Retracements

plot fibLine01 = if extend and fib01 then fib01 else na;
plot fibLine02 = if extend and fib02 then fib02 else na;
plot fibLine03 = if extend and fib03 then fib03 else na;
plot fibLine04 = if extend and fib04 then fib04 else na;
plot fibLine05 = if extend and fib05 then fib05 else na;
plot fibLine06 = if extend and fib06 then fib06 else na;
plot fibLine07 = if extend and fib07 then fib07 else na;
plot fibLine08 = if extend and fib08 then fib08 else na;
plot fibLine09 = if extend and fib09 then fib09 else na;
plot fibLine10 = if extend and fib10 then fib10 else na;
plot fibLine11 = if extend and fib11 then fib11 else na;
plot fibLine12 = if extend and fib12 then fib12 else na;
plot fibLine13 = if extend and fib13 then fib13 else na;
plot fibLine14 = if extend and fib14 then fib14 else na;
plot fibLine15 = if extend and fib15 then fib15 else na;
plot fibLine16 = if extend and fib16 then fib16 else na;
#//Fibonacci Extensions
plot fibextLine01 = if extend and fibext01 then fibext01 else na;
plot fibextLine02 = if extend and fibext02 then fibext02 else na;
plot fibextLine03 = if extend and fibext03 then fibext03 else na;
plot fibextLine04 = if extend and fibext04 then fibext04 else na;
plot fibextLine05 = if extend and fibext05 then fibext05 else na;
plot fibextLine06 = if extend and fibext06 then fibext06 else na;
plot fibextLine07 = if extend and fibext07 then fibext07 else na;
plot fibextLine08 = if extend and fibext08 then fibext08 else na;
plot fibextLine09 = if extend and fibext09 then fibext09 else na;
plot fibextLine10 = if extend and fibext10 then fibext10 else na;

fibLine01.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine02.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine03.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine04.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine05.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine06.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine07.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine08.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine09.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine13.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine14.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine15.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibLine16.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine01.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine02.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine03.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine04.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine05.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine06.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine07.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine08.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine09.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibextLine10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


fibLine02.SetDefaultColor(Color.GRAY);
fibLine03.SetDefaultColor(Color.GRAY);
fibLine04.SetDefaultColor(Color.GRAY);
fibLine05.SetDefaultColor(Color.GRAY);
fibLine06.SetDefaultColor(Color.GRAY);
fibLine07.SetDefaultColor(Color.GRAY);
fibLine08.SetDefaultColor(Color.GRAY);
fibLine10.SetDefaultColor(Color.GRAY);
fibLine11.SetDefaultColor(Color.GRAY);
fibLine12.SetDefaultColor(Color.GRAY);
fibLine13.SetDefaultColor(Color.GRAY);
fibLine14.SetDefaultColor(Color.GRAY);
fibLine15.SetDefaultColor(Color.GRAY);
fibLine16.SetDefaultColor(Color.GRAY);
fibextLine01.SetDefaultColor(Color.GRAY);
fibextLine02.SetDefaultColor(Color.GRAY);
fibextLine03.SetDefaultColor(Color.GRAY);
fibextLine04.SetDefaultColor(Color.GRAY);
fibextLine05.SetDefaultColor(Color.GRAY);
fibextLine06.SetDefaultColor(Color.GRAY);
fibextLine07.SetDefaultColor(Color.GRAY);
fibextLine08.SetDefaultColor(Color.GRAY);
fibextLine09.SetDefaultColor(Color.GRAY);
fibextLine10.SetDefaultColor(Color.GRAY);
fibLine01.SetDefaultColor(Color.WHITE);
fibLine02.AssignValueColor(if close > fib02 then Color.CYAN else Color.MAGENTA);
fibLine03.AssignValueColor(if close > fib03 then Color.CYAN else Color.MAGENTA);
fibLine04.AssignValueColor(if close > fib04 then Color.CYAN else Color.MAGENTA);
fibLine05.AssignValueColor(if close > fib05 then Color.CYAN else Color.MAGENTA);
fibLine06.AssignValueColor(if close > fib06 then Color.CYAN else Color.MAGENTA);
fibLine07.AssignValueColor(if close > fib07 then Color.CYAN else Color.MAGENTA);
fibLine08.AssignValueColor(if close > fib08 then Color.CYAN else Color.MAGENTA);
fibLine09.SetDefaultColor(Color.WHITE);
fibLine10.AssignValueColor(if close > fib10 then Color.CYAN else Color.MAGENTA);
fibLine11.AssignValueColor(if close > fib11 then Color.CYAN else Color.MAGENTA);
fibLine12.AssignValueColor(if close > fib12 then Color.CYAN else Color.MAGENTA);
fibLine13.AssignValueColor(if close > fib13 then Color.CYAN else Color.MAGENTA);
fibLine14.AssignValueColor(if close > fib14 then Color.CYAN else Color.MAGENTA);
fibLine15.AssignValueColor(if close > fib15 then Color.CYAN else Color.MAGENTA);
fibLine16.AssignValueColor(if close > fib16 then Color.CYAN else Color.MAGENTA);
fibextLine01.AssignValueColor(if close > fibext01 then Color.CYAN else Color.MAGENTA);
fibextLine02.AssignValueColor(if close > fibext02 then Color.CYAN else Color.MAGENTA);
fibextLine03.AssignValueColor(if close > fibext03 then Color.CYAN else Color.MAGENTA);
fibextLine04.AssignValueColor(if close > fibext04 then Color.CYAN else Color.MAGENTA);
fibextLine05.AssignValueColor(if close > fibext05 then Color.CYAN else Color.MAGENTA);
fibextLine06.AssignValueColor(if close > fibext06 then Color.CYAN else Color.MAGENTA);
fibextLine07.AssignValueColor(if close > fibext07 then Color.CYAN else Color.MAGENTA);
fibextLine08.AssignValueColor(if close > fibext08 then Color.CYAN else Color.MAGENTA);
fibextLine09.AssignValueColor(if close > fibext09 then Color.CYAN else Color.MAGENTA);
fibextLine10.AssignValueColor(if close > fibext10 then Color.CYAN else Color.MAGENTA);

#//Price Diiference Fib Variables
def priceDiffFibDown;
def priceDiffFibUp;
def fibUpText;
def fibDownText;
#//Price difference Fib Extensions
if close > fib01 and close < fibext01 {
    priceDiffFibDown = (close - fib01) / close;
    priceDiffFibUp = (fibext01 - close) / fibext01;
    fibUpText = 0.272;
    fibDownText = 100;
} else if close > fibext01 and close < fibext02 {
    priceDiffFibDown = (close - fibext01) / close;
    priceDiffFibUp = (fibext02 - close) / fibext02;
    fibUpText = 0.618;
    fibDownText = 0.272;
} else if close > fibext02 and close < fibext03 {
    priceDiffFibDown = (close - fibext02) / close;
    priceDiffFibUp = (fibext03 - close) / fibext03;
    fibUpText = 1.000;
    fibDownText = 0.618;
} else if close > fibext03 and close < fibext04 {
    priceDiffFibDown = (close - fibext03) / close;
    priceDiffFibUp = (fibext04 - close) / fibext04;
    fibUpText = 1.272;
    fibDownText = 1.000;
} else if close > fibext04 and close < fibext05 {
    priceDiffFibDown = (close - fibext04) / close;
    priceDiffFibUp = (fibext05 - close) / fibext05;
    fibUpText = 1.618;
    fibDownText = 1.272;
} else if close > fibext05 and close < fibext06 {
    priceDiffFibDown = (close - fibext05) / close;
    priceDiffFibUp = (fibext06 - close) / fibext06;
    fibUpText = 2.000;
    fibDownText = 1.618;
} else if close > fibext06 and close < fibext07 {
    priceDiffFibDown = (close - fibext06) / close;
    priceDiffFibUp = (fibext07 - close) / fibext07;
    fibUpText = 2.272;
    fibDownText = 2.000;
} else if close > fibext07 and close < fibext08 {
    priceDiffFibDown = (close - fibext07) / close;
    priceDiffFibUp = (fibext08 - close) / fibext08;
    fibUpText = 2.618;
    fibDownText = 2.272;
} else if close > fibext08 and close < fibext09 {
    priceDiffFibDown = (close - fibext08) / close;
    priceDiffFibUp = (fibext09 - close) / fibext09;
    fibUpText = 3.000;
    fibDownText = 2.618;
} else if close > fibext09 and close < fibext10 {
    priceDiffFibDown = (close - fibext09) / close;
    priceDiffFibUp = (fibext10 - close) / fibext10;
    fibUpText = 3.272;
    fibDownText = 3.000;
} else if close > fibext10 {
    priceDiffFibDown = 0;
    priceDiffFibUp = 0;
    fibUpText = 50;
    fibDownText = 50;
#//Price difference Fib Retracements
} else if close < fib01 and close > fib02 {
    priceDiffFibUp = (close - fib01) / close * -1;
    priceDiffFibDown = (fib02 - close) / fib02 * -1;
    fibUpText = 100;
    fibDownText = 0.117;
} else if close < fib02 and close > fib03 {
    priceDiffFibUp = (close - fib02) / close * -1;
    priceDiffFibDown = (fib03 - close) / fib03 * -1;
    fibUpText = 0.117;
    fibDownText = 0.236;
} else if close < fib03 and close > fib04 {
    priceDiffFibUp = (close - fib03) / close * -1;
    priceDiffFibDown = (fib04 - close) / fib04 * -1;
    fibUpText = 0.236;
    fibDownText = 0.382;
} else if close < fib04 and close > fib05 {
    priceDiffFibUp = (close - fib04) / close * -1;
    priceDiffFibDown = (fib05 - close) / fib05 * -1;
    fibUpText = 0.382;
    fibDownText = 0.500;
} else if close < fib05 and close > fib06 {
    priceDiffFibUp = (close - fib05) / close * -1;
    priceDiffFibDown = (fib06 - close) / fib06 * -1;
    fibUpText = 0.500;
    fibDownText = 0.618;
} else if close < fib06 and close > fib07 {
    priceDiffFibUp = (close - fib06) / close * -1;
    priceDiffFibDown = (fib07 - close) / fib07 * -1;
    fibUpText = 0.618;
    fibDownText = 0.786;
} else if close < fib07 and close > fib08 {
    priceDiffFibUp = (close - fib07) / close * -1;
    priceDiffFibDown = (fib08 - close) / fib08 * -1;
    fibUpText = 0.786;
    fibDownText = 0.883;
} else if close < fib08 and close > fib09 {
    priceDiffFibUp = (close - fib08) / close * -1;
    priceDiffFibDown = (fib09 - close) / fib09 * -1;
    fibUpText = 0.883;
    fibDownText = -100;
} else if close < fib09 and close > fib10 {
    priceDiffFibUp = (close - fib09) / close * -1;
    priceDiffFibDown = (fib10 - close) / fib10 * -1;
    fibUpText = -100;
    fibDownText = 1.272;
} else if close < fib10 and close > fib11 {
    priceDiffFibUp = (close - fib10) / close * -1;
    priceDiffFibDown = (fib11 - close) / fib11 * -1;
    fibUpText = 1.272;
    fibDownText = 1.618;
} else if close < fib11 and close > fib12 {
    priceDiffFibUp = (close - fib11) / close * -1;
    priceDiffFibDown = (fib12 - close) / fib12 * -1;
    fibUpText = 1.618;
    fibDownText = 2.000;
} else if close < fib12 and close > fib13 {
    priceDiffFibUp = (close - fib12) / close * -1;
    priceDiffFibDown = (fib13 - close) / fib13 * -1;
    fibUpText = 2.000;
    fibDownText = 2.272;
} else if close < fib13 and close > fib14 {
    priceDiffFibUp = (close - fib13) / close * -1;
    priceDiffFibDown = (fib14 - close) / fib14 * -1;
    fibUpText = 2.272;
    fibDownText = 2.618;
} else if close < fib14 and close > fib15 {
    priceDiffFibUp = (close - fib14) / close * -1;
    priceDiffFibDown = (fib15 - close) / fib15 * -1;
    fibUpText = 2.618;
    fibDownText = 3.000;
} else if close < fib15 and close > fib16 {
    priceDiffFibUp = (close - fib15) / close * -1;
    priceDiffFibDown = (fib16 - close) / fib16 * -1;
    fibUpText = 3.000;
    fibDownText = 3.272;
} else if close < fib16 {
    priceDiffFibUp = 0;
    priceDiffFibDown = 0;
    fibUpText = -50;
    fibDownText = -50;
} else {
    priceDiffFibUp = 0;
    priceDiffFibDown = 0;
    fibUpText = na;
    fibDownText = na;
}

AddLabel(showLabel and !last and (isNaN(fib01) or isNaN(fibext01)), "No Data", Color.WHITE);


AddLabel(showLabel and !last and close < fib01 and !isNaN(fib01) and !isNaN(fibext01), AsPercent(priceDiffFibUp) +
        if fibUpText== 100 then " from Previous High" else
        if fibUpText==-100 then " from Previous Low" else
        if fibUpText== -50 then "Price Below Fib Levels" else
        " from " + fibUpText + " Fib Ret", Color.CYAN);
AddLabel(showLabel and !last and close < fib01 and !isNaN(fib01) and !isNaN(fibext01), AsPercent(priceDiffFibDown) +
        if fibDownText== 100 then " from Previous High" else
        if fibDownText==-100 then " from Previous Low" else
        if fibDownText== -50 then "Price Below Fib Levels" else
        " from " + fibDownText + " Fib Ret", Color.MAGENTA);

AddLabel(showLabel and !last and close > fib01 and !isNaN(fib01) and !isNaN(fibext01), AsPercent(priceDiffFibUp) +
        if fibUpText== 100 then " from Previous High" else
        if fibUpText==-100 then " from Previous Low" else
        if fibUpText== -50 then "Price Above Fib Levels" else
        " from " + fibUpText + " Fib Ext", Color.CYAN);
AddLabel(showLabel and !last and close > fib01 and !isNaN(fib01) and !isNaN(fibext01), AsPercent(priceDiffFibDown) +
        if fibDownText== 100 then " from Previous High" else
        if fibDownText==-100 then " from Previous Low" else
        if fibDownText== -50 then "Price Above Fib Levels" else
        " from " + fibDownText + " Fib Ext", Color.MAGENTA);


#-- ENd of CODE
Thank you!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
266 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top