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.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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