#Auto_Fib_Levels_Using_High_and_Low_of_#_of_Input_Days_Excluding_Todays
input showtodayonly = yes;#Hint showtodayonly: Set to NO to test HH/LL Basis
input daysago = 10;
def ymd = GetYYYYMMDD();
def candles = !IsNaN(close);
def capture = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) ;
def hi = if thisDay == daysago and thisDay != thisDay[1]
then high
else if thisDay != 0
then Max(high, hi[1])
else hi[1];
plot hh = if showtodayonly and thisDay == 0
then hi
else if !showtodayonly and thisDay <= daysago
then hi
else Double.NaN;
def lo = if thisDay == daysago and thisDay != thisDay[1]
then low
else if thisDay != 0
then Min(low, lo[1])
else lo[1];
plot ll = if showtodayonly and thisDay == 0
then lo
else if !showtodayonly and thisDay <= daysago
then lo
else Double.NaN;
AddVerticalLine(thisDay == daysago and thisDay != thisDay[1], "", Color.WHITE);
input showbubbles = yes;
input bubblemover = 4; #Hint n: Number of Bars to shift bubble to the right
input F1 = -1.00;
input F2 = -0.62;
input F3 = -0.27;
input F4 = 0.236;
input F5 = 0.382;
input F6 = 0.500;
input F7 = 0.618;
input F8 = 0.764;
input F10 = 1.27;
input F11 = 1.618;
input F12 = 2.00;
def rHi = hh;
def rLo = ll;
def range = rHi - rLo;
plot FF1 = rLo + (range * F1);
plot FF2 = rLo + (range * F2);
plot FF3 = rLo + (range * F3);
plot FF4 = rLo + (range * F4);
plot FF5 = rLo + (range * F5);
plot FF6 = rLo + (range * F6);
plot FF7 = rLo + (range * F7);
plot FF8 = rLo + (range * F8);
plot FF10 = rLo + (range * F10);
plot FF11 = rLo + (range * F11);
plot FF12 = rLo + (range * F12);
FF1.SetDefaultColor(Color.GREEN);
FF1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF1.SetLineWeight(1);
FF2.SetDefaultColor(Color.GREEN);
FF2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF2.SetLineWeight(1);
FF3.SetDefaultColor(Color.GREEN);
FF3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF3.SetLineWeight(1);
FF4.SetDefaultColor(Color.RED);
FF4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF4.SetLineWeight(1);
FF5.SetDefaultColor(Color.RED);
FF5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF5.SetLineWeight(1);
FF6.SetDefaultColor(Color.YELLOW);
FF6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF6.SetLineWeight(1);
FF7.SetDefaultColor(Color.CYAN);
FF7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF7.SetLineWeight(1);
FF8.SetDefaultColor(Color.CYAN);
FF8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF8.SetLineWeight(1);
FF10.SetDefaultColor(Color.GREEN);
FF10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF10.SetLineWeight(1);
FF11.SetDefaultColor(Color.GREEN);
FF11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF11.SetLineWeight(1);
FF12.SetDefaultColor(Color.GREEN);
FF12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF12.SetLineWeight(1);
def b = bubblemover;
def b1 = b + 1;
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF1[b], F1, FF1.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF2[b], F2, FF2.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF3[b], F3, FF3.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF4[b], F4, FF4.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF5[b], F5, FF5.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF6[b], F6, FF6.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF7[b], F7, FF7.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF8[b], F8, FF8.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF10[b], F10, FF10.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF11[b], F11, FF11.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF12[b], F12, FF12.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), hh[b], 1, hh.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), ll[b], 0, ll.TakeValueColor());