Anchored VWAP Premarket previous days

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);
 
Last edited:
Solution
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...
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);

This is narrowed to just Premarket High.
It uses the script function to be able to plot prior days anchored VWAP
There are 10 prior days included, but more code be added using the code's logic for the 10

Screenshot 2024-08-06 081735.png
Code:
#Anchored VWAP PremarketHigh
input colorvwap  = yes;
input lineweight = 2;

script phvwap {
    input lookup = 2;
    def bn    = BarNumber();
    def ymd   = GetYYYYMMDD();
    def count = if !IsNaN(close) and ymd != ymd[1] then count[1] + 1 else count[1];
    def cond  = HighestAll(count) - count + 1;
    def h     = if IsNaN(high) then h[1] else high;
   
    def premarketHigh    = if cond[1] == lookup + 1 and cond == lookup
                           then h
                           else if cond == lookup and SecondsFromTime(0930) < 0 and h > premarketHigh[1]
                           then h else premarketHigh[1];
    def premarketHighBar = if h == HighestAll(premarketHigh) then BarNumber() else Double.NaN;
   
    def anchor        = if cond == lookup and !isnan(premarketHighBar) 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;

    plot VWAP         = if cond == lookup then volumevwapsum / volumesum else Double.NaN;
}

plot ph1 = phvwap(1);
plot ph2 = phvwap(2);
plot ph3 = phvwap(3);
plot ph4 = phvwap(4);
plot ph5 = phvwap(5);
plot ph6 = phvwap(6);
plot ph7 = phvwap(7);
plot ph8 = phvwap(8);
plot ph9 = phvwap(9);
plot ph10 = phvwap(10);

ph1.AssignValueColor(if colorvwap and close[1] < ph1 then Color.RED else Color.CYAN);
ph2.AssignValueColor(if colorvwap and close[1] < ph2 then Color.RED else Color.CYAN);
ph3.AssignValueColor(if colorvwap and close[1] < ph3 then Color.RED else Color.CYAN);
ph4.AssignValueColor(if colorvwap and close[1] < ph4 then Color.RED else Color.CYAN);
ph5.AssignValueColor(if colorvwap and close[1] < ph5 then Color.RED else Color.CYAN);
ph6.AssignValueColor(if colorvwap and close[1] < ph6 then Color.RED else Color.CYAN);
ph7.AssignValueColor(if colorvwap and close[1] < ph7 then Color.RED else Color.CYAN);
ph8.AssignValueColor(if colorvwap and close[1] < ph8 then Color.RED else Color.CYAN);
ph9.AssignValueColor(if colorvwap and close[1] < ph9 then Color.RED else Color.CYAN);
ph10.AssignValueColor(if colorvwap and close[1] < ph10 then Color.RED else Color.CYAN);

ph1.SetLineWeight(lineweight);
ph2.SetLineWeight(lineweight);
ph3.SetLineWeight(lineweight);
ph4.SetLineWeight(lineweight);
ph5.SetLineWeight(lineweight);
ph6.SetLineWeight(lineweight);
ph7.SetLineWeight(lineweight);
ph8.SetLineWeight(lineweight);
ph9.SetLineWeight(lineweight);
ph10.SetLineWeight(lineweight);

#
 
Last edited:
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Thread starter Similar threads Forum Replies Date
N Anchored VWAP Questions 1
dsvitale Change this VWAP so it can be anchored Questions 1
S Repaints Combining ZigZag with Anchored VWAP Questions 5
S Anchored VWAP Questions 1
M Hiding Anchored Vwap Questions 2

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
190 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top