masonbarnard
New member
Guys, this is driving me nuts.
I current have an anchored premarket high script, but it only works for the current day, and it does not show the previous days.
I want the chart to show all the prior days pre-market-high anchored-vwap as well. This way, I can scroll back on a chart and see how it responded during its gap up day to its premarket high anchor. (I DO NOT want to see the previous days premarket high anchored vwap carried through on the current day, i want it to restart itself everyday, from its premarket high. So each 24 hour period has its only "pre_high anchored vwap".
Here is the script i am currently using
def h = if IsNaN(high) then h[1] else high;
def l = if IsNaN(low) then l[1] else low;
# VWAP Anchored to Date/Time
input startdateselection = {default Daily, Custom};
input starttimeselection = {default HOD, LOD, RTH, PRE, PRE_HIGH, Custom};
input showtodayonly = no;
input colorvwap = yes;
input startdate = 20240103;
input starttime = 0930;
def premarketEnd = RegularTradingStart(GetYYYYMMDD());
def premarketHigh = if GetYYYYMMDD() != GetYYYYMMDD()[1] then h else if GetTime() < premarketEnd and h > premarketHigh[1] then h else premarketHigh[1];
def premarketHighBar = if h == premarketHigh then BarNumber() else Double.NaN;
def ymd = GetYYYYMMDD();
def bn = BarNumber();
def c = close;
def v = volume;
def vw = vwap;
def anchor = if startdateselection == startdateselection.Daily and ymd != ymd[1] or
startdateselection == startdateselection.Custom and GetYYYYMMDD() < startdate then 0
else if starttimeselection == starttimeselection.PRE_HIGH and BarNumber() == HighestAll(premarketHighBar) then 1
else if starttimeselection == starttimeselection.RTH and GetTime() crosses above RegularTradingStart(GetYYYYMMDD())
or starttimeselection == starttimeselection.PRE and GetTime() crosses below RegularTradingEnd(GetYYYYMMDD()[1])
or starttimeselection == starttimeselection.Custom and SecondsFromTime(starttime)[1] <= 0 and SecondsFromTime(starttime) >= 0 then 1
else anchor[1];
def volumesum = if anchor then volumesum[1] + volume else 0;
def volumevwapsum = if anchor then volumevwapsum[1] + volume * vwap else 0;
def price = volumevwapsum / volumesum;
plot VWAP = if showtodayonly and startdateselection == startdateselection.Daily and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else price;
VWAP.AssignValueColor(if colorvwap and close[1] < VWAP then Color.RED else Color.CYAN);
I current have an anchored premarket high script, but it only works for the current day, and it does not show the previous days.
I want the chart to show all the prior days pre-market-high anchored-vwap as well. This way, I can scroll back on a chart and see how it responded during its gap up day to its premarket high anchor. (I DO NOT want to see the previous days premarket high anchored vwap carried through on the current day, i want it to restart itself everyday, from its premarket high. So each 24 hour period has its only "pre_high anchored vwap".
Here is the script i am currently using
def h = if IsNaN(high) then h[1] else high;
def l = if IsNaN(low) then l[1] else low;
# VWAP Anchored to Date/Time
input startdateselection = {default Daily, Custom};
input starttimeselection = {default HOD, LOD, RTH, PRE, PRE_HIGH, Custom};
input showtodayonly = no;
input colorvwap = yes;
input startdate = 20240103;
input starttime = 0930;
def premarketEnd = RegularTradingStart(GetYYYYMMDD());
def premarketHigh = if GetYYYYMMDD() != GetYYYYMMDD()[1] then h else if GetTime() < premarketEnd and h > premarketHigh[1] then h else premarketHigh[1];
def premarketHighBar = if h == premarketHigh then BarNumber() else Double.NaN;
def ymd = GetYYYYMMDD();
def bn = BarNumber();
def c = close;
def v = volume;
def vw = vwap;
def anchor = if startdateselection == startdateselection.Daily and ymd != ymd[1] or
startdateselection == startdateselection.Custom and GetYYYYMMDD() < startdate then 0
else if starttimeselection == starttimeselection.PRE_HIGH and BarNumber() == HighestAll(premarketHighBar) then 1
else if starttimeselection == starttimeselection.RTH and GetTime() crosses above RegularTradingStart(GetYYYYMMDD())
or starttimeselection == starttimeselection.PRE and GetTime() crosses below RegularTradingEnd(GetYYYYMMDD()[1])
or starttimeselection == starttimeselection.Custom and SecondsFromTime(starttime)[1] <= 0 and SecondsFromTime(starttime) >= 0 then 1
else anchor[1];
def volumesum = if anchor then volumesum[1] + volume else 0;
def volumevwapsum = if anchor then volumevwapsum[1] + volume * vwap else 0;
def price = volumevwapsum / volumesum;
plot VWAP = if showtodayonly and startdateselection == startdateselection.Daily and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else price;
VWAP.AssignValueColor(if colorvwap and close[1] < VWAP then Color.RED else Color.CYAN);
Last edited: