#Auto_Fibs_TimeRange_Flip_0_100_time_chart_version
input start = 0400;
input end = 0929;
input showtodayonly = no;
input bubblemover = 0;
input showbubbles = yes;
input extendlines = yes;
input show_trendline = yes;
def sec1 = SecondsFromTime(start);
def sec2 = SecondsFromTime(end);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or
(sec1 < sec1[1] and sec1 > 0);
def isTime2 = (sec2 > 0 and sec2[1] <= 0) or
(sec2 < sec2[1] and sec2 > 0) ;
def aftermarket = CompoundValue(1,
if isTime1[1] == 0 and isTime1 == 1
then 1
else if isTime2
then 0
else aftermarket[1], 0);
def bars = 100000;
def bn = BarNumber();
def na = Double.NaN;
def period = bn - 1;
def count = CompoundValue(1,
if aftermarket and period != period[1]
then (count[1] + period - period[1]) % bars
else count[1], 0);
def cond = count < count[1] + period - period[1];
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = bars, "pricePerRow" = PricePerRow.TICKSIZE , "value area percent" = 0);
def hProfile = if aftermarket and IsNaN(vol.GetHighest())
then hProfile[1]
else if period != period[1]
then vol.GetHighest()
else hProfile[1];
def lProfile = if aftermarket and IsNaN(vol.GetLowest())
then lProfile[1]
else if period != period[1]
then vol.GetLowest()
else lProfile[1];
def ProfileHigh = if extendlines and !aftermarket then ProfileHigh[1] else if aftermarket then hProfile else na;
def ProfileLow = if extendlines and !aftermarket then ProfileLow[1] else if aftermarket then lProfile else na;
def hrange = ProfileHigh;
def lrange = ProfileLow;
input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);
input showtimerange_label = yes;
AddLabel(showtimerange_label, "HL Time Range: " + AsPrice(start) + " to " + AsPrice(end), Color.YELLOW);
input Fpos236 = .236;
input Fpos382 = .382;
input Fpos50 = .5;
input Fpos618 = .618;
input Fpos764 = .786;
input Fpos1618 = 1.618;
input Fneg618 = -0.618;
input Fpos1273 = 1.273;
input Fneg1273 = -0.273;
input Fpos1440 = 1.440;
input Fneg1440 = -0.440;
input Fpos2618 = 2.618;
input Fneg2618 = -1.618;
input Fpos4236 = 4.236;
input Fneg4236 = -3.236;
def range = AbsValue(hrange - lrange);
def F236 = hrange - (range * Fpos236);
def F382 = hrange - (range * Fpos382);
def F50 = hrange - (range * Fpos50);
def F618 = hrange - (range * Fpos618);
def F764 = hrange - (range * Fpos764);
def F1618 = hrange - (range * Fpos1618);
def F_618 = hrange - (range * Fneg618);
def F1273 = hrange - (range * Fpos1273);
def F_1273 = hrange - (range * Fneg1273);
def F1440 = hrange - (range * Fpos1440);
def F_1440 = hrange - (range * Fneg1440);
def F2618 = hrange - (range * Fpos2618);
def F_2618 = hrange - (range * Fneg2618);
def F4236 = hrange - (range * Fpos4236);
def F_4236 = hrange - (range * Fneg4236);
plot ORH;
plot ORL;
plot Fib50;
plot Fib236;
plot Fib382;
plot Fib618;
plot Fib764;
plot Fib1618;
plot Fib_618;
plot Fib1273;
plot Fib_1273;
plot Fib1440;
plot Fib_1440;
plot Fib2618;
plot Fib_2618;
plot Fib4236;
plot Fib_4236;
def dataCount = CompoundValue(1, if (aftermarket != aftermarket[1]) then dataCount[1] + 1 else dataCount[1], 0);
if showtodayonly and HighestAll(dataCount) - dataCount > 2
then {
ORH = Double.NaN;
ORL = Double.NaN;
Fib50 = Double.NaN;
Fib236 = Double.NaN;
Fib382 = Double.NaN;
Fib618 = Double.NaN;
Fib764 = Double.NaN;
Fib1618 = Double.NaN;
Fib_618 = Double.NaN;
Fib1273 = Double.NaN;
Fib_1273 = Double.NaN;
Fib1440 = Double.NaN;
Fib_1440 = Double.NaN;
Fib2618 = Double.NaN;
Fib_2618 = Double.NaN;
Fib4236 = Double.NaN;
Fib_4236 = Double.NaN;
} else {
ORH = hrange;
ORL = lrange;
Fib50 = F50;
Fib236 = F236;
Fib382 = F382;
Fib618 = F618;
Fib764 = F764;
Fib1618 = F1618;
Fib_618 = F_618;
Fib1273 = F1273;
Fib_1273 = F_1273;
Fib1440 = F1440;
Fib_1440 = F_1440;
Fib2618 = F2618;
Fib_2618 = F_2618;
Fib4236 = F4236;
Fib_4236 = F_4236;
}
ORH.SetDefaultColor(Color.WHITE);
ORH.SetPaintingStrategy(PaintingStrategy.DASHES);
ORH.SetLineWeight(2);
ORL.SetDefaultColor(Color.WHITE);
ORL.SetPaintingStrategy(PaintingStrategy.DASHES);
ORL.SetLineWeight(2);
Fib50.SetDefaultColor(Color.WHITE);
Fib50.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib50.SetLineWeight(1);
Fib236.SetDefaultColor(Color.CYAN);
Fib236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib236.SetLineWeight(1);
Fib382.SetDefaultColor(Color.YELLOW);
Fib382.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib382.SetLineWeight(1);
Fib618.SetDefaultColor(Color.YELLOW);
Fib618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib618.SetLineWeight(1);
Fib764.SetDefaultColor(Color.CYAN);
Fib764.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib764.SetLineWeight(2);
Fib1618.SetDefaultColor(Color.YELLOW);
Fib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1618.SetLineWeight(1);
Fib_618.SetDefaultColor(Color.YELLOW);
Fib_618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_618.SetLineWeight(1);
Fib1273.SetDefaultColor(Color.YELLOW);
Fib1273.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1273.SetLineWeight(1);
Fib_1273.SetDefaultColor(Color.YELLOW);
Fib_1273.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_1273.SetLineWeight(1);
Fib1440.SetDefaultColor(Color.YELLOW);
Fib1440.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1440.SetLineWeight(1);
Fib_1440.SetDefaultColor(Color.YELLOW);
Fib_1440.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_1440.SetLineWeight(1);
Fib2618.SetDefaultColor(Color.YELLOW);
Fib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib2618.SetLineWeight(1);
Fib_2618.SetDefaultColor(Color.YELLOW);
Fib_2618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_2618.SetLineWeight(1);
Fib4236.SetDefaultColor(Color.YELLOW);
Fib4236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib4236.SetLineWeight(1);
Fib_4236.SetDefaultColor(Color.YELLOW);
Fib_4236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_4236.SetLineWeight(1);
input manual_flip = no;
def mo = bubblemover;
def mo1 = mo + 1;
def lo1 = if low == lProfile then 1 else 0;
def hi1 = if high == hProfile then 1 else 0;
def hbar = if aftermarket and hi1 == 1 then bn else hbar[1];
def lbar = if aftermarket and lo1 == 1 then bn else lbar[1];
def last = IsNaN(close[mo + 1]) and !IsNaN(close[mo + 1]);
plot xhbar = if manual_flip then lbar else hbar;
plot xlbar = if manual_flip then hbar else lbar;
xhbar.SetHiding(yes);
xlbar.SetHiding(yes);
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
ORH[mo + 1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 0 else 100),
ORH.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
ORL[mo + 1], (if xhbar[mo + 1] > xlbar[mo + 1] then 100 else 0),
ORL.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib50[mo1 + 1],
"50",
Fib50.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 236 else 786),
Fib236.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib382[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 382 else 618),
Fib382.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 618 else 382),
Fib618.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib764[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 786 else 236),
Fib764.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1618 else -618),
Fib1618.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -618 else 1618),
Fib_618.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1273[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1273 else -273),
Fib1273.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_1273[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -273 else 1273),
Fib_1273.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1440[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1440 else -440),
Fib1440.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_1440[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -440 else 1440),
Fib_1440.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib2618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 2618 else -1618),
Fib2618.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_2618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -1618 else 2618),
Fib_2618.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib4236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 4236 else -3236),
Fib4236.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_4236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -3236 else 4236),
Fib_4236.TakeValueColor());
def hbar1 = if (aftermarket or aftermarket[1]) and hi1 == 1 then 1 else 0;
def lbar1 = if (aftermarket or aftermarket[1]) and lo1 == 1 then 1 else 0;
plot xhbar1 = hbar1;
plot xlbar1 = lbar1;
xhbar1.SetHiding(yes);
xlbar1.SetHiding(yes);
plot xline = if show_trendline then if aftermarket and !IsNaN(xhbar1) then hrange else if aftermarket and !IsNaN(xlbar1) then hrange else na else na;
xline.EnableApproximation();
;
input show_flip_mode = yes;
AddLabel(show_flip_mode, if manual_flip == yes then "Manual Flip Mode" else "Auto Flip Mode", Color.YELLOW);