# showonly1day_01
# https://usethinkscript.com/threads/can-i-hide-the-chart-but-keep-the-lower-indicators.4170/
# show just candles for 1 day , 4am to 8pm
# start with 4am on left. dont scroll candles off screen
# at 4am, the screen resets, blanks, and starts over with 1 candle on the left
# hidebars01 , turn off main price candles
input HidePrice = YES;
HidePricePlot(HidePrice);
input new_bars_as_blue = yes;
def na = double.nan;
def bn = barnumber();
# ---------------------------------
def istoday = if GetLastDay() == GetDay() then 1 else 0;
def dow = GetDayofWeek(GetYYYYMMDD());
# 4am to 8pm
input start1 = 0400;
input end1 = 2000;
def daytime = if secondsfromTime(start1) >= 0 and secondstillTime(end1) > 0 then 1 else 0;
def periodchg = (daytime <> daytime[-1]);
def daychg = (dow <> dow[-1]);
# ---------------------------------
# first bar , of first day on chart
def firstbn =
if (bn == 1 and secondsfromTime(start1) == 0) then bn
else if bn == 1 then 0
else if firstbn[1] > 0 then firstbn[1]
else if secondsfromTime(start1) >= 0 then bn
else firstbn[1];
def newfirstbn = highestall(firstbn);
def firstdaynum =
if bn == 1 then 0
else if firstdaynum[1] > 0 then firstdaynum[1]
else if firstbn > 0 then dow
else firstdaynum[1];
def lastbn = if bn == 1 then 0
else if lastbn[1] > 0 then lastbn[1]
else if (bn > firstbn) and (periodchg or daychg) then bn
else lastbn[1];
def newlastbn = highestall(lastbn);
def day1bars = (bn >= newfirstbn and bn <= newlastbn);
#addchartbubble(1, low*0.995, bn + "\n" + periodchg + "\n" + lastbn + "\n" + dow + "\n" + firstdaynum, color.cyan, no);
#addchartbubble(1, low*0.995, bn + "\nF " + firstbn + "\nL " + lastbn + "\nP " + periodchg + "\nD " + dow + "\n" + firstdaynum, color.cyan, no);
#addchartbubble(1, low*0.995, bn + "\n" + periodchg + "\n" + lastbn + "\n" + dow + "\n" + firstdaynum, color.cyan, no);
#addchartbubble(day1bars, high, "x" , color.cyan, yes);
# --------------------------------------
def newday_enable = ( bn >= newfirstbn and bn <= newlastbn);
# first bar , of current day
def currdayfirstbn = if bn == 1 then 0 else if (istoday and secondsfromTime(start1) == 0) then bn else currdayfirstbn[1];
def oldfirstbn = highestall(currdayfirstbn);
def off1 = if newday_enable then (oldfirstbn - newfirstbn) else na;
# addchartbubble(1,low, bn + "\n" + newfirstbn + "\n" + newlastbn, color.cyan, no);
# calculate the offset
def lastBar = HighestAll(if !isNaN(close) then BarNumber() else 0);
#def offset = lastBar - firstbn;
#def offset = if (daytime and istoday) then bn else na;
def offset = off1;
def o = GetValue(open, -offset);
def c = GetValue(close, -offset);
# ----------- green
def h1;
def l1;
if (!new_bars_as_blue and c > o) then {
h1 = GetValue(high, -offset);
l1 = GetValue(low, -offset);
} else {
h1 = na;
l1 = na;
};
AddChart(high = h1, low = l1, open = o, close = c, type = ChartType.CANDLE, growcolor = color.light_green);
# --------- red
def h2;
def l2;
if (!new_bars_as_blue and c < o) then {
h2 = GetValue(high, -offset);
l2 = GetValue(low, -offset);
} else {
h2 = na;
l2 = na;
};
AddChart(high = h2, low = l2, open = o, close = c, type = ChartType.CANDLE, growcolor = color.light_red);
# --------- cyan
def h3;
def l3;
if new_bars_as_blue then {
h3 = GetValue(high, -offset);
l3 = GetValue(low, -offset);
} else {
h3 = na;
l3 = na;
};
AddChart(high = h3, low = l3, open = o, close = c, type = ChartType.CANDLE, growcolor = color.cyan);
#