Bezna\$ Automatic Fibonacci Plots

Bezna\$ Automatic Fibonacci Plots​

Simple but Powerful script that automatically plots Fibonacci retracements.

Code:
``````# Bezna\$ Automatic Fibonacci Plots
# https://tos.mx/VZVqul4
input ShowBubbles = Yes; def barnumber = BarNumber();
def rnd = if close < 1 then 3 else 2;
def a = HighestAll(high); def b = LowestAll(low);
def c = if high == a then barnumber else Double.NaN;
def d = if low == b then barnumber else Double.NaN;
rec highnumber = CompoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = CompoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);
def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;
def x = AbsValue(lownumberall - highnumberall );
def slope = (a - b) / x; def slopelow = (b - a) / x;
def day = GetDay(); def month = GetMonth(); def year = GetYear();
def lastDay = GetLastDay(); def lastmonth = GetLastMonth(); def lastyear = GetLastYear();
def isToday = If(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else Double.NaN);
def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall then linelow else Double.NaN;
def currentline = if barnumber <= highnumberall then line else Double.NaN;
def range = a - b;
def A0 = HighestAll(a - (range * 0)); def B0 = HighestAll((b + (range * 0 )));
def A1 = HighestAll(a - (range * .236)); def B1 = HighestAll((b + (range * .236 )));
def A2 = HighestAll(a - (range * .382)); def B2 = HighestAll((b + (range * .382 )));
def A3 = HighestAll(a - (range * .5)); def B3 = HighestAll((b + (range * .5 )));
def A4 = HighestAll(a - (range * .618)); def B4 = HighestAll((b + (range * .618 )));
def A5 = HighestAll(a - (range * .786)); def B5 = HighestAll((b + (range * .786 )));
def A6 = HighestAll(a - (range * 1)); def B6 = HighestAll((b + (range * 1 )));
def C4 = if upward then yes else no; #-- a
def C8 = if downward then yes else no; #----b
def C9 = downward and barnumber == highnumberall and ShowBubbles;
def C10 = upward and barnumber == lownumberall and ShowBubbles;
plot R0 = if C4 then A0 else if C8 then B0 else Double.NaN;
R0.AssignValueColor(Color.Red);
AddChartBubble(C9 or C10, R0, Concat( "\$", Round(R0, rnd )), Color.RED, yes);
plot R1 = if C4 then A1 else if C8 then B1 else Double.NaN;
R1.SetDefaultColor(getcolor(7));
AddChartBubble(C9 or C10, R1, Concat( "\$", Round(R1, rnd )), Color.Gray, yes);
plot R2 = if C4 then A2 else if C8 then B2 else Double.NaN;
R2.SetDefaultColor(getcolor(7));
AddChartBubble(C9 or C10, R2, Concat( "\$", Round(R2, rnd )), Color.Gray, yes);
plot R3 = if C4 then A3 else if C8 then B3 else Double.NaN;
R3.SetDefaultColor(getcolor(7));
AddChartBubble(C9 or C10, R3, Concat( "\$", Round(R3, rnd )), Color.Gray, yes);
plot R4 = if C4 then A4 else if C8 then B4 else Double.NaN;
R4.SetDefaultColor(getcolor(7));
AddChartBubble(C9 or C10, R4, Concat( "\$", Round(R4, rnd )), Color.Gray, yes);
plot R5 = if C4 then A5 else if C8 then B5 else Double.NaN;
R5.SetDefaultColor(getcolor(7));
AddChartBubble(C9 or C10, R5, Concat( "\$", Round(R5, rnd )), Color. Gray, yes);
plot R6 = if C4 then A6 else if C8 then B6 else Double.NaN;
R6.AssignValueColor(Color.GREEN);
AddChartBubble(C9 or C10, R6, Concat( "\$", Round(R6, rnd )), Color.GREEN, yes);``````

Last edited by a moderator:
Hi, could someone please help me edit the code to add the following levels (1.618, 2.618, 3.618, 4.236, 6.85)? I tried to add them but I'm not sure how to edit the plot section. OP hasn't been online since 2021. Thank you in advance!

Code:
``````def A0 = HighestAll(a - (range * 0)); def B0 = HighestAll((b + (range * 0 )));
def A1 = HighestAll(a - (range * .236)); def B1 = HighestAll((b + (range * .236 )));
def A2 = HighestAll(a - (range * .382)); def B2 = HighestAll((b + (range * .382 )));
def A3 = HighestAll(a - (range * .5)); def B3 = HighestAll((b + (range * .5 )));
def A4 = HighestAll(a - (range * .618)); def B4 = HighestAll((b + (range * .618 )));
def A5 = HighestAll(a - (range * .786)); def B5 = HighestAll((b + (range * .786 )));
def A6 = HighestAll(a - (range * 1)); def B6 = HighestAll((b + (range * 1 )));
def A7 = HighestAll(a - (range * 1.618)); def B6 = HighestAll((b + (range * 1.618 )));
def A8 = HighestAll(a - (range * 2.618)); def B6 = HighestAll((b + (range * 2.618 )));
def A9 = HighestAll(a - (range * 3.618)); def B6 = HighestAll((b + (range * 3.618 )));
def A10 = HighestAll(a - (range * 4.236)); def B6 = HighestAll((b + (range * 4.236 )));
def A7 = HighestAll(a - (range * 6.85)); def B6 = HighestAll((b + (range * 6.85 )));``````

Bezna\$ Automatic Fibonacci Plots

The indicator doesn't do Fib Extensions. It plots retracement levels from the highest point in a chart to the lowest point in a chart!

Not the exact question you're looking for?

87k+ Posts
409 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?