Fibonacci Extension study version 1.1
Made some modifications to BLT's Fib Choices code to suit my needs, sectionalized the code for easier future code maintenance, marked the High/Low from which calculations were made, and color coded upper/lower extensions for easier visualization. Kudos for some really great ideas there @BLT Anyone that uses this code, just remember that this is designed for an intraday chart
Made some modifications to BLT's Fib Choices code to suit my needs, sectionalized the code for easier future code maintenance, marked the High/Low from which calculations were made, and color coded upper/lower extensions for easier visualization. Kudos for some really great ideas there @BLT Anyone that uses this code, just remember that this is designed for an intraday chart
Code:
# Fib Choices V1.1
# BLT, with modifications by tomsk
# 12.25.2019
# V1.0 - 12.24.2019 - BLT - Initial release of Fib Choices
# V1.1 - 12.25.2019 - tomsk - Marked High/Low, color coded Fib upper/lower extensions
declare hide_on_daily;
input aggregation = AggregationPeriod.DAY;
input display_upper_extended_fibs = yes;
input display_lower_extended_fibs = yes;
input fib1 = .236;
input fib2 = .382;
input fib3 = .500;
input fib4 = .618;
input fib5 = .764;
def hh = high(period = aggregation);
def ll = low(period = aggregation);
def range = hh - ll;
def f1 = ll + range * fib1;
def f2 = ll + range * fib2;
def f3 = ll + range * fib3;
def f4 = ll + range * fib4;
def f5 = ll + range * fib5;
def hh1 = if !IsNaN(close(period = aggregation)) then hh else hh1[1];
def ff1 = if !IsNaN(close(period = aggregation)) then f1 else ff1[1];
def ff2 = if !IsNaN(close(period = aggregation)) then f2 else ff2[1];
def ff3 = if !IsNaN(close(period = aggregation)) then f3 else ff3[1];
def ff4 = if !IsNaN(close(period = aggregation)) then f4 else ff4[1];
def ff5 = if !IsNaN(close(period = aggregation)) then f5 else ff5[1];
def ll1 = if !IsNaN(close(period = aggregation)) then ll else ll1[1];
# REGULAR FIBONACCI RETRACEMENT LEVELS
plot hhp = if !IsNaN(close) then Double.NaN else hh1;
hhp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhp.SetDefaultColor(Color.GREEN);
hhp.SetLineWeight(4);
plot f1p = if !IsNaN(close) then Double.NaN else ff1;
f1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f1p.SetDefaultColor(Color.YELLOW);
f1p.SetLineWeight(1);
plot f2p = if !IsNaN(close) then Double.NaN else ff2;
f2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f2p.SetDefaultColor(Color.YELLOW);
f2p.SetLineWeight(1);
plot f3p = if !IsNaN(close) then Double.NaN else ff3;
f3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f3p.SetDefaultColor(Color.WHITE);
f3p.SetLineWeight(1);
plot f4p = if !IsNaN(close) then Double.NaN else ff4;
f4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f4p.SetDefaultColor(Color.YELLOW);
f4p.SetLineWeight(1);
plot f5p = if !IsNaN(close) then Double.NaN else ff5;
f5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f5p.SetDefaultColor(Color.YELLOW);
f5p.SetLineWeight(1);
plot llp = if !IsNaN(close) then Double.NaN else ll1;
llp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llp.SetDefaultColor(Color.RED);
llp.SetLineWeight(4);
# UPPER FIBONACCI EXTENSION LEVELS
plot uhhp = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + hh1;
uhhp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uhhp.SetDefaultColor(Color.GREEN);
uhhp.SetLineWeight(1);
plot uf1p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff1;
uf1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf1p.SetDefaultColor(Color.YELLOW);
uf1p.SetLineWeight(1);
plot uf2p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff2;
uf2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf2p.SetDefaultColor(Color.YELLOW);
uf2p.SetLineWeight(1);
plot uf3p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff3;
uf3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf3p.SetDefaultColor(Color.WHITE);
uf3p.SetLineWeight(1);
plot uf4p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff4;
uf4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf4p.SetDefaultColor(Color.YELLOW);
uf4p.SetLineWeight(1);
plot uf5p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff5;
uf5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf5p.SetDefaultColor(Color.YELLOW);
uf5p.SetLineWeight(1);
# LOWER FIBONACCI EXTENSION LEVELS
plot Lllp = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range;
Lllp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lllp.SetDefaultColor(Color.RED);
Lllp.SetLineWeight(1);
plot Lf1p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib1;
Lf1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf1p.SetDefaultColor(Color.YELLOW);
Lf1p.SetLineWeight(1);
plot Lf2p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib2;
Lf2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf2p.SetDefaultColor(Color.YELLOW);
Lf2p.SetLineWeight(1);
plot Lf3p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib3;
Lf3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf3p.SetDefaultColor(Color.WHITE);
Lf3p.SetLineWeight(1);
plot Lf4p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib4;
Lf4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf4p.SetDefaultColor(Color.YELLOW);
Lf4p.SetLineWeight(1);
plot Lf5p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib5;
Lf5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf5p.SetDefaultColor(Color.YELLOW);
Lf5p.SetLineWeight(1);
# CHART BUBBLES
input showchart_bubbles = yes;
input bubblemover = 5; #used to move the bubble left and right
def n = bubblemover;
def n1 = n + 1;
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), hhp[n], 1 + " = High", Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff1[n], fib1 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff2[n], fib2 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff3[n], fib3 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff4[n], fib4 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff5[n], fib5 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), llp[n], 0 + " = Low", Color.YELLOW, yes);
# EXTENSION ABOVE
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf1p[n], 1+fib1, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf2p[n], 1+fib2, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf3p[n], 1+fib3, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf4p[n], 1+fib4, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf5p[n], 1+fib5, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uhhp[n], 2 , Color.WHITE, yes);
# EXTENSION BELOW
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf1p[n], -fib1, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf2p[n], -fib2, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf3p[n], -fib3, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf4p[n], -fib4, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf5p[n], -fib5, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lllp[n], -1 , Color.PINK, yes);
# HIDE BUBBLE FLAG
hhp.HideBubble();
llp.HideBubble();
uhhp.HideBubble();
Lllp.HideBubble();
f1p.HideBubble();
f2p.HideBubble();
f3p.HideBubble();
f4p.HideBubble();
f5p.HideBubble();
Lf1p.HideBubble();
Lf2p.HideBubble();
Lf3p.HideBubble();
Lf4p.HideBubble();
Lf5p.HideBubble();
uf1p.HideBubble();
uf2p.HideBubble();
uf3p.HideBubble();
uf4p.HideBubble();
uf5p.HideBubble();
# End Fib Choices V1.1
Last edited by a moderator: