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: