#Auto_Fibs_TimeProfile_Flip_0_100_time_chart_version
input timePerProfile = { CHART, MINUTE, HOUR, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input showtodayonly = no;
input bubblemover = 0;
input showbubbles = yes;
input extendlines = yes;
input show_trendline = yes;
input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 70;
input opacity = 50;
def bn = barnumber();
def na = double.nan;
def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
period = 0;
case MINUTE:
period = Floor(seconds / 60 + day_number * 24 * 60);
case HOUR:
period = Floor(seconds / 3600 + day_number * 24);
case DAY:
period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
period = Floor(day_number / 7);
case MONTH:
period = Floor(month - First(month));
case "OPT EXP":
period = exp_opt - First(exp_opt);
case BAR:
period = BarNumber() - 1;
}
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % multiplier else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}
profile vol = volumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = compoundValue(1, onExpansion, no);
def hProfile = if IsNaN(vol.getHighest()) and con then hProfile[1] else vol.getHighest();
def lProfile = if IsNaN(vol.getLowest()) and con then lProfile[1] else vol.getLowest();
def plotsDomain = IsNaN(close) == onExpansion;
plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
plot ProfileLow = if plotsDomain then lProfile else Double.NaN;
def hrange = ProfileHigh;
def lrange = ProfileLow;
input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);
input Fpos236 = .214;
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
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 hi1 == 1 then bn else hbar[1];
def lbar = if 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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 214 else 786),
Fib236.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 214),
Fib764.TakeValueColor());
AddChartBubble(
if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 and !isnan(close[-1])
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 hi1 == 1 then 1 else 0;
def lbar1 = if 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 !IsNaN(xhbar1) then hrange else if !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", if manual_flip == no then Color.YELLOW else Color.CYAN);
#