Moving Averages + Premarket High/Low + Yesterday High/Low V2
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © convicted
//@version=5

indicator(title='MovingAvg', shorttitle='MovingAvg', overlay=true)

//Yesterday high and low
bool preHours = (hour == 4 or hour >= 4) and (hour < 9 and minute <= 30)
bool marketHours = (hour >= 9 and minute >= 30) and hour < 16
bool afterHours = hour >= 16 and (hour <= 20 or hour == 20)

//Current High And Low
currentdayhigh = request.security(syminfo.tickerid, 'D', high[0])
currentdaylow = request.security(syminfo.tickerid, 'D', low[0])

//Yesterday high and low
previousdayhigh = request.security(syminfo.tickerid, 'D', high[1])
previousdaylow = request.security(syminfo.tickerid, 'D', low[1])

if marketHours
    previousdayhigh := previousdayhigh
    previousdaylow := previousdaylow

if preHours
    previousdayhigh := currentdayhigh
    previousdaylow := currentdaylow

if afterHours
    previousdayhigh := currentdayhigh
    previousdaylow := currentdaylow  
   
//Premarket high and low
t = time('1440', '0400-0930:23456')  // 1440 is the number of minutes in a whole day.
is_first = na(t[1]) and not na(t) or t[1] < t
ending_hour = 9
ending_minute = 30

pm_high = float(na)
pm_low = float(na)
k = int(na)

if is_first and barstate.isnew and (hour < ending_hour or hour >= 0400 or hour == ending_hour and minute < ending_minute)
    pm_high := high
    pm_low := low
    pm_low
else
    pm_high := pm_high[1]
    pm_low := pm_low[1]
    pm_low
if high > pm_high and (hour < ending_hour or hour >= 0400 or hour == ending_hour and minute < ending_minute)
    pm_high := high
    pm_high
if low < pm_low and (hour < ending_hour or hour >= 0400 or hour == ending_hour and minute < ending_minute)
    pm_low := low
    pm_low
LastOnly = true

if LastOnly == true
    k := -9999
    k
else
    k := 0
    k

//Just a variable here for the label coordinates
td = time - time[100]

//Previous day high and low lines
plot(previousdayhigh, style=plot.style_line, title='Yesterday High', color=color.new(#e8f287, 0), linewidth=1, trackprice=true, offset=k)
plot(previousdaylow, style=plot.style_line, title='Yesterday Low', color=color.new(#e8f287, 0), linewidth=1, trackprice=true, offset=k)

//Premarket high and low lines
plot(pm_high, style=plot.style_line, title='Premarket High', trackprice=true, color=color.new(#64ffda, 0), linewidth=1, offset=k)
pmh = label.new(x=time + td, y=pm_high, xloc=xloc.bar_time, style=label.style_none, textcolor=#64ffda, size=size.small, textalign=text.align_right)
label.delete(pmh[1])

plot(pm_low, style=plot.style_line, title='Premarket Low', trackprice=true, color=color.new(#64ffda, 0), linewidth=1, offset=k)
pml = label.new(x=time + td, y=pm_low, xloc=xloc.bar_time, style=label.style_none, textcolor=#64ffda, size=size.small, textalign=text.align_right)
label.delete(pml[1])

//PLOT EMAs AND VWAP
ema9 = ta.ema(close, 9)
expo9 = if (timeframe.in_seconds() <= timeframe.in_seconds("65"))
    ema9
else
    na
plot(series=expo9, title="EMA 9", color= #e8f287, linewidth=1)

ema21 = ta.ema(close, 21)
expo21 = if (timeframe.in_seconds() <= timeframe.in_seconds("65"))
    ema21
else
    na
plot(series=expo21, title="EMA 21", color= #e2affc, linewidth=1)

ema50 = ta.ema(close, 50)
expo50 = if (timeframe.in_seconds() <= timeframe.in_seconds("65"))
    ema50
else
    na
//plot(series=expo50, title="EMA 50", color= #ffec68, linewidth=1)  

ema100 = ta.ema(close, 100)
expo100 = if (timeframe.in_seconds() <= timeframe.in_seconds("65"))
    ema100
else
    na
//plot(series=expo100, title="EMA 100", color= #22ab94, linewidth=1)  

ema200 = ta.ema(close, 200)
expo200 = if (timeframe.in_seconds() <= timeframe.in_seconds("65"))
    ema200
else
    na
plot(series=expo200, title="EMA 200", color= #2d6a84 , linewidth=1)

vwap = ta.vwap(close)
VWAP = if (timeframe.in_seconds() <= timeframe.in_seconds("65"))
    vwap
else
    na
//plot(series=VWAP, title="VWAP", color= #ffec68, linewidth=1)

//EXPO MOVING AVERAGES (DAILY+)
sma21 = ta.sma(close, 21)
simple21 = if (timeframe.in_seconds() >= timeframe.in_seconds("120"))
    sma21
else
    na
plot(series=simple21, title="SMA 21", color= #e8f287, linewidth=1)

sma50 = ta.sma(close, 50)
simple50 = if (timeframe.in_seconds() >= timeframe.in_seconds("120"))
    sma50
else
    na
plot(series=simple50, title="SMA 50", color= #e2affc, linewidth=1)  

sma100 = ta.sma(close, 100)
simple100 = if (timeframe.in_seconds() >= timeframe.in_seconds("120"))
    sma100
else
    na
plot(series=simple100, title="SMA 100", color= #a6e4fc, linewidth=1)  

sma200 = ta.sma(close, 200)
simple200 = if (timeframe.in_seconds() >= timeframe.in_seconds("120"))
    sma200
else
    na
plot(series=simple200, title="SMA 200", color= #2d6a84, linewidth=1)