def bn = BarNumber();
script tl {
def ymd = GetYYYYMMDD();
def candles = !IsNaN(close);
def capture = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) ;
def bn = BarNumber();
input days = 0;
def prehigh = CompoundValue(1, if thisDay == days and thisDay[1] == days + 1
then high
else if thisDay == days and GetTime() < RegularTradingStart(GetYYYYMMDD())
then Max(high, prehigh[1])
else prehigh[1], thisDay == days and high);
def prelow = CompoundValue(1, if thisDay == days and thisDay[1] == days + 1
then low
else if thisDay == days and GetTime() < RegularTradingStart(GetYYYYMMDD())
then Min(low, prelow[1])
else prelow[1], low);
def prehighbn = if thisDay == days and GetTime() < RegularTradingStart(GetYYYYMMDD()) and Round(high) == Round(HighestAll(prehigh))
then bn else prehighbn[1];
def prelowbn = if thisDay == days and GetTime() < RegularTradingStart(GetYYYYMMDD()) and low == prelow
then bn else prelowbn[1];
input method = {default Time, PremarketHigh, PremarketLow};
input pmHighPrice = low;
input pmLowPrice = high;
input time1 = 1045;
input time2 = 0930;
input ext = 20;
def begin;
def pricebegin;
def priceend;
def beginbn ;
def end;
def endbn;
switch (method) {
case Time:
begin = if thisDay == days and SecondsFromTime(time1) == 0 then 1 else 0;
pricebegin = high;
priceend = high;
beginbn = if thisDay == days and SecondsFromTime(time1) == 0 then bn else beginbn[1];
end = if thisDay == days and SecondsFromTime(time2) == 0 then 1 else 0;
endbn = if thisDay == days and SecondsFromTime(time2) == 0 then bn else endbn[1];
case PremarketHigh:
begin = if thisDay == days and BarNumber() == HighestAll(prehighbn) then 1 else 0;
pricebegin = prehigh;
priceend = if thisDay == days and GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then pmHighPrice else priceend[1];
beginbn = HighestAll(prehighbn);
end = if thisDay == days and GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then 1 else 0;
endbn = if thisDay == days and GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then bn else endbn[1];
case PremarketLow:
begin = if thisDay == days and BarNumber() == HighestAll(prelowbn)
then 1 else 0;
pricebegin = prelow;
priceend = if thisDay == days and GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then PmLowPrice else priceend[1];
beginbn = prelowbn;
end = if thisDay == days and GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then 1 else 0;
endbn = if thisDay == days and GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then bn else endbn[1];
}
def beginprice = if thisDay == days and begin then pricebegin else beginprice[1];
def endprice1 = if thisDay == days and end then priceend else endprice1[1];
plot line = if thisDay == days and begin
then beginprice
else if thisDay == days and end
then endprice1 else Double.NaN;
line.EnableApproximation();
#Line Extension-----------------------------------------------------------------
def y1 = if thisDay == days and bn == HighestAll(beginbn) then beginprice else y1[1];
def y2 = if thisDay == days and bn == HighestAll(endbn) then endprice1 else y2[1];
def slope = if thisDay == days and endbn > beginbn
then (( y2 - y1) / (endbn - beginbn))
else (( y1 - y2) / (beginbn - endbn));
rec lext = if thisDay == days and IsNaN(close[-1])
then lext[1] + (lext[1] - lext[2])
else if thisDay == days and endbn > beginbn
then y1 + ((bn - beginbn) * slope)
else y2 + ((bn - endbn) * slope);
plot lextplot = if thisDay == days and Between(bn, HighestAll(endbn) , HighestAll(endbn) + ext)
then lext
else Double.NaN;
lextplot.EnableApproximation();
lextplot.SetPaintingStrategy(PaintingStrategy.LINE);
lextplot.SetDefaultColor(Color.WHITE);
lextplot.SetLineWeight(2);
}
def today = HighestAll(if IsNaN(close[-1]) then GetYYYYMMDD() else 0);
input startlookback = {default Days, Date};
input lookbackdays = 0;
input lookbackdate = 20211126;
def lookback = if startlookback == startlookback.Days
then lookbackdays
else CountTradingDays(lookbackdate, today) - 1;
input method = {default Time, PremarketHigh, PremarketLow};
input pmhighPrice = low;
input pmlowprice = high;
input time1 = 1045;
input end = 1215;
input ext = 20;
input weight = 5;
plot tl0 = tl(AbsValue(lookback + 0), method, pmhighPrice, pmlowPrice, time1, end, ext);
plot tl1 = tl(AbsValue(lookback + 1), method, pmhighPrice, pmlowPrice, time1, end, ext);
plot tl2 = tl(AbsValue(lookback + 2), method, pmhighPrice, pmlowPrice, time1, end, ext);
plot tl3 = tl(AbsValue(lookback + 3), method, pmhighPrice, pmlowPrice, time1, end, ext);
plot tl4 = tl(AbsValue(lookback + 4), method, pmhighPrice, pmlowPrice, time1, end, ext);
plot tl5 = tl(AbsValue(lookback + 5), method, pmhighPrice, pmlowPrice, time1, end, ext);
plot tl6 = tl(AbsValue(lookback + 6), method, pmhighPrice, pmlowPrice, time1, end, ext);
plot tl7 = tl(AbsValue(lookback + 7), method, pmhighPrice, pmlowPrice, time1, end, ext);
plot tl8 = tl(AbsValue(lookback + 8), method, pmhighPrice, pmlowPrice, time1, end, ext);
plot tl9 = tl(AbsValue(lookback + 9), method, pmhighPrice, pmlowPrice, time1, end, ext);
DefineGlobalColor("TL", Color.YELLOW);
tl0.EnableApproximation();
tl0.SetLineWeight(weight);
tl0.SetDefaultColor(GlobalColor("TL"));
tl1.EnableApproximation();
tl1.SetLineWeight(weight);
tl1.SetDefaultColor(GlobalColor("TL"));
tl2.EnableApproximation();
tl2.SetLineWeight(weight);
tl2.SetDefaultColor(GlobalColor("TL"));
tl3.EnableApproximation();
tl3.SetLineWeight(weight);
tl3.SetDefaultColor(GlobalColor("TL"));
tl4.EnableApproximation();
tl4.SetLineWeight(weight);
tl4.SetDefaultColor(GlobalColor("TL"));
tl5.EnableApproximation();
tl5.SetLineWeight(weight);
tl5.SetDefaultColor(GlobalColor("TL"));
tl6.EnableApproximation();
tl6.SetLineWeight(weight);
tl6.SetDefaultColor(GlobalColor("TL"));
tl7.EnableApproximation();
tl7.SetLineWeight(weight);
tl7.SetDefaultColor(GlobalColor("TL"));
tl8.EnableApproximation();
tl8.SetLineWeight(weight);
tl8.SetDefaultColor(GlobalColor("TL"));
tl9.EnableApproximation();
tl9.SetLineWeight(weight);
tl9.SetDefaultColor(GlobalColor("TL"));
plot tlext0 = tl(AbsValue(lookback + 0), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
plot tlext1 = tl(AbsValue(lookback + 1), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
plot tlext2 = tl(AbsValue(lookback + 2), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
plot tlext3 = tl(AbsValue(lookback + 3), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
plot tlext4 = tl(AbsValue(lookback + 4), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
plot tlext5 = tl(AbsValue(lookback + 5), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
plot tlext6 = tl(AbsValue(lookback + 6), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
plot tlext7 = tl(AbsValue(lookback + 7), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
plot tlext8 = tl(AbsValue(lookback + 8), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
plot tlext9 = tl(AbsValue(lookback + 9), method, pmhighPrice, pmlowPrice, time1, end, ext).lextplot;
tlext0.EnableApproximation();
tlext0.SetLineWeight(weight);
tlext0.SetDefaultColor(GlobalColor("TL"));
tlext1.EnableApproximation();
tlext1.SetLineWeight(weight);
tlext1.SetDefaultColor(GlobalColor("TL"));
tlext2.EnableApproximation();
tlext2.SetLineWeight(weight);
tlext2.SetDefaultColor(GlobalColor("TL"));
tlext3.EnableApproximation();
tlext3.SetLineWeight(weight);
tlext3.SetDefaultColor(GlobalColor("TL"));
tlext4.EnableApproximation();
tlext4.SetLineWeight(weight);
tlext4.SetDefaultColor(GlobalColor("TL"));
tlext5.EnableApproximation();
tlext5.SetLineWeight(weight);
tlext5.SetDefaultColor(GlobalColor("TL"));
tlext6.EnableApproximation();
tlext6.SetLineWeight(weight);
tlext6.SetDefaultColor(GlobalColor("TL"));
tlext7.EnableApproximation();
tlext7.SetLineWeight(weight);
tlext7.SetDefaultColor(GlobalColor("TL"));
tlext8.EnableApproximation();
tlext8.SetLineWeight(weight);
tlext8.SetDefaultColor(GlobalColor("TL"));
tlext9.EnableApproximation();
tlext9.SetLineWeight(weight);
tlext9.SetDefaultColor(GlobalColor("TL"));