def na = Double.NaN;
input onexpansion = yes;
input displace = 0;
input Fpos236 = .236;
input Fpos382 = .382;
input Fpos50 = .5;
input Fpos618 = .618;
input Fpos764 = .764;
def rhi = if isnan(close) then rhi[1] else high[1];
def rlo = if isnan(close) then rlo[1] else low[1];
def range = rHi - rLo;
def F236 = rHi - (range * Fpos236);
def F382 = rHi - (range * Fpos382);
def F50 = rHi - (range * Fpos50);
def F618 = rHi - (range * Fpos618);
def F764 = rHi - (range * Fpos764);
plot ORH;
plot ORL;
plot Fib50;
plot Fib236;
plot Fib382;
plot Fib618;
plot Fib764;
ORH = if onexpansion and !isnan(close) then double.nan else rhi;
ORL = if onexpansion and !isnan(close) then double.nan else rlo;
Fib50 = if onexpansion and !isnan(close) then double.nan else F50;
Fib236 = if onexpansion and !isnan(close) then double.nan else F236;
Fib382 = if onexpansion and !isnan(close) then double.nan else F382;
Fib618 = if onexpansion and !isnan(close) then double.nan else F618;
Fib764 = if onexpansion and !isnan(close) then double.nan else F764;
ORH.SetDefaultColor(Color.GREEN);
ORH.setpaintingStrategy(paintingStrategy.HORIZONTAL);
ORH.SetLineWeight(2);
ORL.SetDefaultColor(Color.RED);
ORL.setpaintingStrategy(paintingStrategy.HORIZONTAL);
ORL.SetLineWeight(2);
Fib50.SetDefaultColor(Color.WHITE);
Fib50.setpaintingStrategy(paintingStrategy.HORIZONTAL);
Fib50.SetLineWeight(1);
Fib236.SetDefaultColor(Color.CYAN);
Fib236.setpaintingStrategy(paintingStrategy.HORIZONTAL);
Fib236.SetLineWeight(1);
Fib382.SetDefaultColor(Color.MAGENTA);
Fib382.setpaintingStrategy(paintingStrategy.HORIZONTAL);
Fib382.SetLineWeight(1);
Fib618.SetDefaultColor(Color.YELLOW);
Fib618.setpaintingStrategy(paintingStrategy.HORIZONTAL);
Fib618.SetLineWeight(1);
Fib764.SetDefaultColor(Color.DARK_RED);
Fib764.setpaintingStrategy(paintingStrategy.HORIZONTAL);
Fib764.SetLineWeight(2);
input showfib_bubbles = yes;
input n = 5;
def n1 = n +1;
AddChartBubble(showfib_bubbles and !IsNaN(close[n1 + if onexpansion then 1 else 0]) and IsNaN(close[n]), orh[n1], orh[n1], Color.green, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1 + if onexpansion then 1 else 0]) and IsNaN(close[n]), orl[n1], orl[n1], Color.red, no);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1 + if onexpansion then 1 else 0]) and IsNaN(close[n]), fib618[n1], aspercent(fpos618), Color.cyan, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1 + if onexpansion then 1 else 0]) and IsNaN(close[n]), fib236[n1], aspercent(fpos236), Color.yellow, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1 + if onexpansion then 1 else 0]) and IsNaN(close[n]), fib50[n1], aspercent(fpos50), Color.yellow, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1 + if onexpansion then 1 else 0]) and IsNaN(close[n]), fib382[n1], aspercent(fpos382), Color.white, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1 + if onexpansion then 1 else 0]) and IsNaN(close[n]), fib764[n1], aspercent(fpos764), Color.yellow, yes);