#LABELS
#
#Current Price
AddLabel (1, "P: " + Round(close, 2), Color.CYAN);
#Percent Change from yesterday close
def AP = AggregationPeriod.DAY;
def Priorclose = close(period = AP)[1];
def PctChange = (close - Priorclose) / Priorclose;
def PC1 = Round(PctChange, 3);
AddLabel(1, "Ch: " + AsPercent(PC1), if PctChange > 0 then CreateColor(238, 210, 238) else CreateColor(255, 153, 153));
#Check if time is premarket
def pmopen = if SecondsFromTime(0400) >= 0 and SecondsTillTime(0930) >= 0 then 1 else 0;
def pmclosed = if SecondsFromTime(0400) >= 0 and SecondsTillTime(0930) >= 0 then 0 else 1;
def pastten = if SecondsFromTime(0400) >= 0 and SecondsTillTime(1000) >= 0 then 1 else 0;
#Prior Close
AddLabel (1, "Y: " + Round(Priorclose, 2), Color.LIGHT_GREEN);
#Open price
def open1 = open(period = AP);
AddLabel (pmclosed, "O: " + Round(open1, 2), CreateColor(254, 216, 177));
#High of Day
def high1 = Highest(high(period = AP), 1);
AddLabel (pmclosed, "H: " + Round(high1, 2), Color.CYAN);
#Low of Day
def low1 = Lowest(low(period = AP), 1);
AddLabel (pmclosed, "L: " + Round(low1, 2), CreateColor(178, 255, 102));
#Volume Today
def today = volume(period = AP);
def L1 = RoundDown(Lg(today), 0);
def M1 = if L1 > 5 and L1 < 8 then 1 else 0;
AddLabel (L1 < 5, "V: " + today, CreateColor(144, 171, 255));
AddLabel (L1 between 4.5 and 5.5, "V: " + Round((today / 1000), 0) + "K", CreateColor(144, 171, 255));
AddLabel (M1, "V: " + Round((today / 1000000), 1) + "M", CreateColor(206, 177, 128));
AddLabel (L1 > 7, "V: " + Round((today / 1000000), 0) + "M", CreateColor(206, 177, 128));
#Change From Open
def CFO = Round(100*((close/open1)-1),1);
AddLabel(pmclosed, "C: " + CFO + "%", if CFO > 0 then CreateColor(0, 255, 128) else CreateColor(255, 153, 153));
#Relative Volume
def AV = AggregationPeriod.DAY;
def x1 = Average(volume(period = AV)[1], 60);
def v1 = volume(period = AV);
def z1 = v1 / x1;
def z2 = if Lg(z1) >= 2 then 0 else 1;
AddLabel(pmclosed, "R: " + Round(z1, z2), CreateColor(208, 209, 238));
#Addlabel(1,x1,color.PINK);
def h = high;
def v = volume;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
#Premarket Volume
def vol = if GlobeX and !GlobeX[1] then v else if GlobeX then vol[1] + v else Double.NaN;
def L2 = RoundDown(Lg(vol), 0);
def C1 = if L2 > 4.5 and L2 < 5.5 then 1 else 0;
AddLabel (pmopen and L2 < 5, "PV: " + vol, CreateColor(196, 212, 207));
AddLabel (pmopen and C1, "PV: " + Round((vol / 1000), 0) + "K", CreateColor(196, 212, 207));
AddLabel (pmopen and L2 > 5, "PV: " + Round((vol / 1000000), 1) + "M", CreateColor(196, 212, 207));
#Premarket Open
def newDay = GetDay() <> GetDay()[1];
def start = newDay or SecondsTillTime(400) == 0;
rec premarketOpen = if start then open else premarketOpen[1];
def x = premarketOpen;
AddLabel(pmopen, "PO: " + Round(x, 2), CreateColor(110, 160, 208));
#Premarket High
def ONhigh = if GlobeX and !GlobeX[1] then h else if GlobeX and h > ONhigh[1] then h else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh then bar else Double.NaN;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar) then ONhigh else OverNightHigh[1];
AddLabel(pastten, "PH: " + Round(OverNightHigh, 2), Color.CYAN);
#Pct difference between price and premarket open
def z = Round(100 * ((close / x) - 1), 1);
AddLabel(pmopen, "PG: " + z + "%", if z < 0 then CreateColor(255, 153, 153) else CreateColor(197, 239, 161));
#Premarket Relative Volume
def z3 = vol / x1;
AddLabel(pmopen, "PR: " + Round(z3, 2), CreateColor(254, 216, 177));