script hl {
input daysback = 2;
input ORBegin = 1400;
input OREnd = 1500;
def na = Double.NaN;
input CloudOn = yes;
input ShowTodayOnly = yes;
# Create logic for OR definition:
def days = if GetYYYYMMDD() != GetYYYYMMDD()[1] then days[1] + 1 else days[1];
def daycount = HighestAll(days) - days;
def ORActive = if daycount == daysback and SecondsTillTime(OREnd) > 0 and SecondsFromTime(ORBegin) >= 0 then 1 else 0;
#High/Low starting at orbegin1 using Opening Range Script modified to use last hour
def h1500 = if SecondsFromTime(ORBegin)[1] < 0 and SecondsFromTime(ORBegin) >= 0 then high(period = AggregationPeriod.HOUR) else h1500[1];
def l1500 = if SecondsFromTime(ORBegin)[1] < 0 and SecondsFromTime(ORBegin) >= 0 then low(period = AggregationPeriod.HOUR) else l1500[1];
def cc1500 = if SecondsFromTime(ORBegin)[1] < 0 and SecondsFromTime(ORBegin) >= 0 then close(period = AggregationPeriod.HOUR) else cc1500[1];
def orhigh = if ORActive then h1500 else orhigh[1];
def orLow = if ORActive then l1500 else orLow[1];
def orClose = if ORActive then cc1500 else orClose[1];
# Define all the plots:
plot ORH = if ShowTodayOnly and GetDay() != GetLastDay() then na else orhigh;
plot ORL = if ShowTodayOnly and GetDay() != GetLastDay() then na else orLow;
plot ORC = if ShowTodayOnly and GetDay() != GetLastDay() then na else orClose;
# end Script
}
def bn = BarNumber();
DefineGlobalColor("H", Color.GREEN);
DefineGlobalColor("L", Color.RED);
DefineGlobalColor("C", Color.white);
DefineGlobalColor("Cloud", Color.GRAY);
input back1 = 1;
input back2 = 2;
input back3 = 3;
input orbegin = 1400;
input orend = 1500;
input cloudon = yes;
input showtodayonly = yes;
input showprice_in_bubble = yes;
plot rh1 = hl(back1, orbegin, orend, "cloud on" = cloudon, "show today only" = showtodayonly).ORH;
plot rl1 = hl(back1, orbegin, orend, "cloud on" = cloudon, "show today only" = showtodayonly).ORL;
plot rc1 = hl(back1, orbegin, orend, "cloud on" = cloudon, "show today only" = showtodayonly).ORC;
# Formatting:
rh1.SetDefaultColor(GlobalColor("H"));
rh1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rh1.SetLineWeight(1);
rl1.SetDefaultColor(GlobalColor("L"));
rl1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rl1.SetLineWeight(1);
rc1.SetDefaultColor(GlobalColor("C"));
rc1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rc1.SetLineWeight(1);
AddCloud(if cloudon then rh1 else Double.NaN, rl1, GlobalColor("Cloud"), GlobalColor("Cloud"));
AddChartBubble(bn == HighestAll(bn), rh1, if showprice_in_bubble then "H1 " + Round(rh1) else "H1", rh1.TakeValueColor());
AddChartBubble(bn == HighestAll(bn), rl1, if showprice_in_bubble then "L1 " + Round(rl1) else "L1", rl1.TakeValueColor(), no);
AddChartBubble(bn == HighestAll(bn), rc1, if showprice_in_bubble then "C1 " + Round(rc1) else "C1", rc1.TakeValueColor());
plot rh2 = hl(back2, orbegin, orend, "cloud on" = cloudon, "show today only" = showtodayonly).ORH;
plot rl2 = hl(back2, orbegin, orend, "cloud on" = cloudon, "show today only" = showtodayonly).ORL;
plot rc2 = hl(back2, orbegin, orend, "cloud on" = cloudon, "show today only" = showtodayonly).ORC;
# Formatting:
rh2.SetDefaultColor(GlobalColor("H"));
rh2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rh2.SetLineWeight(1);
rl2.SetDefaultColor(GlobalColor("L"));
rl2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rl2.SetLineWeight(1);
rc2.SetDefaultColor(GlobalColor("C"));
rc2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rc2.SetLineWeight(1);
AddCloud(if cloudon then rh2 else Double.NaN, rl2, GlobalColor("Cloud"), GlobalColor("Cloud"));
AddChartBubble(bn == HighestAll(bn), rh2, if showprice_in_bubble then "H2 " + Round(rh2) else "H2", rh2.TakeValueColor());
AddChartBubble(bn == HighestAll(bn), rl2, if showprice_in_bubble then "L2 " + Round(rl2) else "L2", rl2.TakeValueColor(), no);
AddChartBubble(bn == HighestAll(bn), rc2, if showprice_in_bubble then "C2 " + Round(rc2) else "C2", rc2.TakeValueColor());
plot rh3 = hl(back3, orbegin, orend, "cloud on" = cloudon, "show today only" = showtodayonly).ORH;
plot rl3 = hl(back3, orbegin, orend, "cloud on" = cloudon, "show today only" = showtodayonly).ORL;
plot rc3 = hl(back3, orbegin, orend, "cloud on" = cloudon, "show today only" = showtodayonly).ORC;
# Formatting:
rh3.SetDefaultColor(GlobalColor("H"));
rh3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rh3.SetLineWeight(1);
rl3.SetDefaultColor(GlobalColor("L"));
rl3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rl3.SetLineWeight(1);
rc3.SetDefaultColor(GlobalColor("C"));
rc3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rc3.SetLineWeight(1);
AddCloud(if cloudon then rh3 else Double.NaN, rl3, GlobalColor("Cloud"), GlobalColor("Cloud"));
AddChartBubble(bn == HighestAll(bn), rh3, if showprice_in_bubble then "H3 " + Round(rh3) else "H3" , rh3.TakeValueColor());
AddChartBubble(bn == HighestAll(bn), rl3, if showprice_in_bubble then "L3 " + Round(rl3) else "L3" , rl3.TakeValueColor(), no);
AddChartBubble(bn == HighestAll(bn), rc3, if showprice_in_bubble then "C3 " + Round(rc3) else "C3", rc3.TakeValueColor());
#