• Get $40 off VIP by signing up for a free account! Sign Up

vwap

neyland

New member
My goal is to have two separate plots VWAP on the same chart. Oh, and yes, I would like the plots to appear throughout the day.

Does anyone have a script I can use on TOS?

Help with VWAP for day trading. Daily one minute (or 2 Min) and previous day VWAP on same chart
 
Last edited by a moderator:
Solution
My goal is to have two separate plots VWAP on the same chart. Oh, and yes, I would like the plots to appear throughout the day.

Does anyone have a script I can use on TOS?

Help with VWAP for day trading. Daily one minute (or 2 Min) and previous day VWAP on same chart

Perhaps this will do what you want.

1. It places 2 versions of the following script on the chart.
2. One's input num_days_to_show, equals 2, the other equals 1;
3. The Vwap from the pervious day will continue to plot on the current day and use the current day's data there to compute the Vwap.

Screenshot 2024-05-16 102148.png
Code:
#Anchored_VWAP_Continuous_from_DaysBack_Start_Time

input num_days_to_show  = 2;
input start_time        = 0400;
input numdeviations1    = 1.0...
My goal is to have two separate plots VWAP on the same chart. Oh, and yes, I would like the plots to appear throughout the day.

Does anyone have a script I can use on TOS?

Help with VWAP for day trading. Daily one minute (or 2 Min) and previous day VWAP on same chart

Perhaps this will do what you want.

1. It places 2 versions of the following script on the chart.
2. One's input num_days_to_show, equals 2, the other equals 1;
3. The Vwap from the pervious day will continue to plot on the current day and use the current day's data there to compute the Vwap.

Screenshot 2024-05-16 102148.png
Code:
#Anchored_VWAP_Continuous_from_DaysBack_Start_Time

input num_days_to_show  = 2;
input start_time        = 0400;
input numdeviations1    = 1.0;
input numdeviations2    = 2.0;
input numdeviations3    = 3.0;
input show_deviations   = yes;
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 sec      = SecondsFromTime(start_time);
def time     = sec[1] <= 0 and sec >= 0 or
               sec < sec[1] and sec > 0;
def start = if thisDay <= num_days_to_show - 1 and time then 1 else start[1];
def isperiodrolled = thisDay <= num_days_to_show - 1 and start;


rec volumeSum;
rec volumeVwapSum;
rec volumeVwap2Sum;

if !(isperiodrolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);
} else {
    volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
    volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
    volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

rec v  = if IsNaN(reference VWAP()) then v[1] else price;

plot VWAP = if isperiodrolled then v else Double.NaN;
plot UpperBand1 = if show_deviations and isperiodrolled then price + numdeviations1 * deviation else Double.NaN;
plot LowerBand1 = if show_deviations and isperiodrolled then price - numdeviations1 * deviation else Double.NaN;

VWAP.SetDefaultColor(Color.CYAN);
VWAP.SetLineWeight(2);
UpperBand1.SetDefaultColor(Color.YELLOW);
LowerBand1.SetDefaultColor(Color.YELLOW);
UpperBand1.SetStyle(Curve.SHORT_DASH);
LowerBand1.SetStyle(Curve.SHORT_DASH);

plot UpperBand2 = if show_deviations and isperiodrolled then price + numdeviations2 * deviation else Double.NaN;
plot LowerBand2 = if show_deviations and isperiodrolled then price - numdeviations2 * deviation else Double.NaN;

UpperBand2.SetDefaultColor(Color.WHITE);
LowerBand2.SetDefaultColor(Color.WHITE);
UpperBand2.SetStyle(Curve.SHORT_DASH);
LowerBand2.SetStyle(Curve.SHORT_DASH);

plot UpperBand3 = if show_deviations and isperiodrolled then price + numdeviations3 * deviation else Double.NaN;
plot LowerBand3 = if show_deviations and isperiodrolled then price - numdeviations3 * deviation else Double.NaN;

UpperBand3.SetDefaultColor(Color.WHITE);
LowerBand3.SetDefaultColor(Color.WHITE);
UpperBand3.SetStyle(Curve.SHORT_DASH);
LowerBand3.SetStyle(Curve.SHORT_DASH);

input showvertical = yes;
AddVerticalLine(showvertical and isperiodrolled != isperiodrolled[1], "", Color.CYAN);

#
 
Solution

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

Thank you.
Help with VWAP script with 3 indicators:
YTD Low and YTD high and just YTD

On intraday charts make sure you have enough days displayed to have all 3 points plot
The image shows a 1h 360d chart with the Vwaps plot starting on the day when the condition occurred

Screenshot 2024-06-09 063515.png
Code:
#Anchored_VWAP_Continuous_from_YTD_Points

input select_start  = {default YTD, YTDHigh, YTDlow};
input showlabel     = no;
input showverticals = no;

def bn  = BarNumber();
def ymd = GetYYYYMMDD();
def yy  = if GetYear()[1] == GetYear() - 1 and GetYear() then 1  else yy[1] + 1;
def hh  = if yy == 1 then high else if yy > 1 and high > hh[1] then high else hh[1];
def ll  = if yy == 1 then low  else if yy > 1 and low < ll[1]  then low  else  ll[1];

def ytdhigh = HighestAll(if high == hh then ymd else Double.NaN);
def ytdlow  = HighestAll(if bn == 1 then Double.NaN else if low  == ll then ymd else Double.NaN);
def ytd     = HighestAll(if GetYear()[1] != GetLastYear() then ymd else Double.NaN);

AddLabel(showlabel, AsPrice(GetYear()) + " YTD High " + AsText(hh) + " @ " + AsPrice(ytdhigh) , Color.LIGHT_GREEN);
AddLabel(showlabel, AsPrice(GetYear()) + " YTD Low  " + AsText(ll) + " @ " + AsPrice(ytdlow), Color.LIGHT_RED);

AddVerticalLine(showverticals and ymd[1] != ytd and ymd == ytd, AsPrice(ytd) + "    START", Color.WHITE);
AddVerticalLine(showverticals and ymd[1] != ytdhigh and ymd == ytdhigh, AsPrice(ytdhigh) + "   HIGH", Color.WHITE);
AddVerticalLine(showverticals and ymd[1] != ytdlow and ymd == ytdlow,   AsPrice(ytdlow)  + "   LOW" , Color.WHITE);

def start;
input numDevDn  = -2.0;
input numDevUp  = 2.0;
switch (select_start) {
case YTD:
    start = ytd;
case YTDHigh:
    start = ytdhigh;
case YTDlow:
    start = ytdlow;
}

def   anchor    = GetYYYYMMDD() >= start;
def volumeSum   = if anchor then CompoundValue(1, volumeSum[1] + volume, volume) else 0;
def volumeVwapSum  = if anchor then CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap) else 0;
def volumeVwap2Sum = if anchor then CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap)) else 0;
def price     = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAP       = price;
input showbands = yes;
plot UpperBand  = if !showbands then Double.NaN else price + numDevUp * deviation;
plot LowerBand  = if !showbands then Double.NaN else price + numDevDn * deviation;

VWAP.SetDefaultColor(GetColor(0));
UpperBand.SetDefaultColor(GetColor(2));
LowerBand.SetDefaultColor(GetColor(4));

#
 
Last edited:
Thread starter Similar threads Forum Replies Date
T %VWAP Watchlist Column Questions 2
N Anchored VWAP Questions 1
B VWAP 9EMA Crossover Study Questions 0
M VWAP with a volume spike alert Questions 1
R EMA + VWAP + MACD Buy/Sell Signal Questions 3

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
370 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