# Twitter: @Eddie_HigherLow
#
# I created this script to save me time when charting.
# Includes:
# Previous Day High, Low, and Close
# Premarket High and Low
# Opening Price
#
#Show PreMarket
input Show_Bubbles = no;
input Show_PreMarket = yes;
input periodstart = 0400;
input periodend = 0930;
input sPeriod = {default DAY};
def offset = 1;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def varopen = open(period = sPeriod)[offset];
def varclose = close(period = sPeriod)[offset];
def activeperiod = if SecondsFromTime(periodstart) >= 0 and SecondsTillTime(periodend) > 0 then yes else Double.NaN;
def acriveperiodstartbar = if SecondsFromTime(periodstart) == 0 then BarNumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i = 0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod, -i)) do GetValue(BarNumber(), -i);
def activeperiodlength = 1 + (activeperiodendbar - acriveperiodstartbar);
def activeperiodhigh;
if SecondsFromTime(periodstart) == 0 {
activeperiodhigh = high;
} else if !IsNaN(activeperiod) and high >= activeperiodhigh[1] {
activeperiodhigh = high;
} else {
activeperiodhigh = activeperiodhigh[1];
}
def activeperiodlow;
if SecondsFromTime(periodstart) == 0 {
activeperiodlow = low;
} else if !IsNaN(activeperiod) and low <= activeperiodlow[1] {
activeperiodlow = low;
} else {
activeperiodlow = activeperiodlow[1];
}
def activephigh = fold iah = 0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh, -iah);
def activeplow = fold ial = 0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow, -ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;
plot PreHigh = if !IsNaN(activeperiod) and activephigh > 0 then activephigh else Double.NaN;
PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PreHigh.SetStyle(Curve.LONG_DASH);
PreHigh.SetLineWeight(2);
PreHigh.SetDefaultColor(Color.GREEN);
PreHigh.SetHiding(!Show_PreMarket);
plot PreLow = if !IsNaN(activeperiod) and activeplow > 0 then activeplow else Double.NaN;
PreLow.SetPaintingStrategy(PaintingStrategy.LINE);
PreLow.SetStyle(Curve.LONG_DASH);
PreLow.SetLineWeight(2);
PreLow.SetDefaultColor(Color.RED);
PreLow.SetHiding(!Show_PreMarket);
plot PMHigh = if IsNaN(activeperiod) and aph > 0 then aph else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PMHigh.SetStyle(Curve.LONG_DASH);
PMHigh.SetLineWeight(2);
PMHigh.SetDefaultColor(Color.GREEN);
PMHigh.SetHiding(!Show_PreMarket);
plot PMLow = if IsNaN(activeperiod) and apl > 0 then apl else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.LINE);
PMLow.SetStyle(Curve.LONG_DASH);
PMLow.SetLineWeight(2);
PMLow.SetDefaultColor(Color.RED);
PMLow.SetHiding(!Show_PreMarket);
AddChartBubble(Show_Bubbles and IsNaN(PreHigh[1]) and !IsNaN(PreHigh) and Show_PreMarket, PreHigh, "PMH", Color.WHITE, yes);
AddChartBubble(Show_Bubbles and IsNaN(PreLow[1]) and !IsNaN(PreLow) and Show_PreMarket, PreLow, "PML", Color.WHITE, no);
#
#
#Show Previous Day High and Low
input RTHbegin = 0930;
input RTHend = 1559;
input Show_PreviousDay_High_and_Low = yes;
def pastOpen = If((SecondsTillTime(RTHbegin) > 0), 0, 1);
def pastClose = If((SecondsTillTime(RTHend) > 0), 0, 1);
def marketOpen = If(pastOpen and !pastClose, 1, 0);
def date = GetYYYYMMDD();
def c = close;
def h = high;
def l = low;
def o = open;
#Highest High during RTH from Previous Day Determined
def begin = CompoundValue(1, if GetDay() == GetDay()[1]
then if SecondsFromTime(RTHbegin) == 0
then h
else if h > begin[1] and marketOpen
then h
else begin[1]
else 0, begin[1]);
def beginbn = if GetDay() == GetLastDay()
then 0
else if GetDay() == GetDay()[1]
then if h == begin and marketOpen
then BarNumber()
else beginbn[1]
else 0;
def beginprice = if GetDay() == GetDay()[1]
then if BarNumber() == HighestAll(beginbn)
then h
else beginprice[1]
else beginprice[1];
#Lowest Low During RTH from Previous Day Determined
def begin1 = CompoundValue(1, if GetDay() == GetDay()[1]
then if SecondsFromTime(RTHbegin) == 0
then l
else if l < begin1[1] and marketOpen
then l
else begin1[1]
else 0, l);
def beginbn1 = if GetDay() == GetLastDay()
then 0
else if l == begin1
then BarNumber()
else beginbn1[1];
def beginprice1 = if date == date[1]
then if BarNumber() == HighestAll(beginbn1)
then l
else beginprice1[1]
else beginprice1[1];
plot PDH = if GetDay() != GetLastDay() then Double.NaN else beginprice;
PDH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PDH.SetLineWeight(2);
PDH.SetDefaultColor(Color.GREEN);
PDH.SetHiding(!Show_PreviousDay_High_and_Low);
plot PDL = if GetDay() != GetLastDay() then Double.NaN else beginprice1;
PDL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PDL.SetLineWeight(2);
PDL.SetDefaultColor(Color.RED);
PDL.SetHiding(!Show_PreviousDay_High_and_Low);
AddChartBubble(Show_Bubbles and IsNaN(PDH[1]) and !IsNaN(PDH) and Show_PreviousDay_High_and_Low, PDH, "PDH", Color.WHITE, yes);
AddChartBubble(Show_Bubbles and IsNaN(PDL[1]) and !IsNaN(PDL) and Show_PreviousDay_High_and_Low, PDL, "PDL", Color.WHITE, yes);
#
#
#Previous Close
input Show_Previous_Day_Close=yes;
def lastclose = CompoundValue(1,
if SecondsTillTime(rthend)[1] > 0 and
SecondsTillTime(rthend) <= 0 or
(SecondsTillTime(rthend)[1] < SecondsTillTime(rthend) and
SecondsTillTime(rthend)[1] > 0)
then close
else lastclose[1], close);
def showlastcloseonly=no;
def bn = barnumber();
def lastclosebn = CompoundValue(1,
if SecondsTillTime(rthend)[1] > 0 and
SecondsTillTime(rthend) <= 0 or
(SecondsTillTime(rthend)[1] < SecondsTillTime(rthend) and
SecondsTillTime(rthend)[1] > 0)
then bn
else double.nan, bn);
plot PreviousDayClose = if showlastcloseonly and
bn < highestall(lastclosebn)
then double.nan
else lastclose;
PreviousDayClose.SetPaintingStrategy(PaintingStrategy.line);
PreviousDayClose.SetStyle(Curve.SHORT_DASH);
PreviousDayClose.SetDefaultColor(Color.lIGHT_GRAY);
PreviousDayClose.SetLineWeight(2);
PreviousDayClose.SetHiding(!Show_Previous_Day_Close);
AddChartBubble(Show_Bubbles and IsNaN(PreviousDayClose[1]) and !IsNaN(PreviousDayClose) and Show_Previous_Day_Close, PreviousDayClose, "PDC", Color.WHITE, yes);
#
#
#Opening Price
input Show_Opening_Price = yes;
def MarketOpenPrice = if SecondsFromTime (0930) == 0 && SecondsTillTime(0930) == 0 then open else MarketOpenPrice[1];
plot Opening_Price = if SecondsFromTime (0930) >= 0 and SecondsFromTime(1559) <= 0 then MarketOpenPrice else Double.NaN;
Opening_Price.SetPaintingStrategy(PaintingStrategy.LINE);
Opening_Price.SetDefaultColor(ColOr.MAGENTA);
Opening_Price.SetStyle(Curve.MEDIUM_DASH);
Opening_Price.SetLineWeight(1);
Opening_Price.SetHiding(!Show_Opening_Price);
AddChartBubble(Show_Bubbles and IsNaN(Opening_Price[1]) and !IsNaN(Opening_Price) and Show_Opening_Price, Opening_Price, "Open", Color.WHITE, yes);