Hello,
Would it be possible to write a VWAP indicator that is starting from the prior day's open?
Code:#Anchored_VWAP_Continuous_from_DaysBacck_Start_Time input num_days_to_show = 2; input start_time = 0930; input numdeviations1 = 2.0; input numdeviations2 = 1.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 start = if thisday==num_days_to_show - 1 and...
Hello,
Would it be possible to write a VWAP indicator that is starting from the prior day's open?
Code:#Anchored_VWAP_Continuous_from_DaysBacck_Start_Time input num_days_to_show = 2; input start_time = 0930; input numdeviations1 = 2.0; input numdeviations2 = 1.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 start = if thisday==num_days_to_show - 1 and secondsFromTime(start_time)==0 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); input showvertical = yes; AddVerticalLine(showvertical and isperiodrolled != isperiodrolled[1], "", Color.CYAN);
What is different in this calculation vs. the calculation that is done by TOS? Would it be possible to adjust the calculation to match TOS? I think the calculation is starting from the opening price the average price in that candle?Just input the number of days back and the start time for a continuous VWAP from that point.
Hi There,Just input the number of days back and the start time for a continuous VWAP from that point.
Hi There,
How do we display the previous day VWAP for SPX like shown (in green) in the attached image?
I played with the above code and couldn't get it to look like the one shown in the image. Interestingly, it doesn't show the vwap for SPX.
Thank You!
Code:#Anchored_VWAP_Continuous_from_DaysBacck_Start_Time_Futures input num_days_to_show = 2; input start_time = 1800; input numdeviations1 = 2.0; input numdeviations2 = 1.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 start = if thisDay == num_days_to_show - 1 and SecondsFromTime(start_time + GetAggregationPeriod() / 60000) == 0 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); input showvertical = yes; AddVerticalLine(showvertical and isperiodrolled != isperiodrolled[1], "", Color.CYAN); #
Awesome. Thanks for coding the script. Would you be able to add labels to the previous day vwap (call it 'PD VWAP') and the current day vvwap (call it 'VWAP') so that we can distinguish between them?1. SPX dioes not have any volume in TOS. Therefore, the VWAP will not plot.
2. The script is coded to start each day selected at a time input. The previous version was set to begin at 0930, the start of regular trading hours.
3. Since you are using futures, I have modified the script to start at the beginning of the trading day (1800) for the /ES.
4. The image shows the TOS VWAP native study, which starts plotting at the start of each day and then restarts anew at the beginning of the next day.
5. The image also shows 2 versions of the script. One is set to 1 and other 2. Each maps the same day's VWAP as the native study. The one set at 2 continues plotting into the following day(s) from the start without restarting like the TOS native version.
6. Your image shows another broker chart than TOS. So I do not know how that compares to TOS.
Awesome. Thanks for coding the script. Would you be able to add labels to the previous day vwap (call it 'PD VWAP') and the current day vvwap (call it 'VWAP') so that we can distinguish between them?
Thanks Again!
Code:#Anchored_VWAP_Continuous_from_DaysBacck_Start_Time_Futures input num_days_to_show = 2; input start_time = 1800; input numdeviations1 = 2.0; input numdeviations2 = 1.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 start = if thisDay == num_days_to_show - 1 and SecondsFromTime(start_time + GetAggregationPeriod() / 60000) == 0 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)); def 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); input showvertical = yes; AddVerticalLine(showvertical and isperiodrolled != isperiodrolled[1], "", Color.CYAN); input showbubbles = yes; input bubblemover = 10; def mover = IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]) and showbubbles; AddChartBubble(mover, VWAP[bubblemover + 1], "V-" + num_days_to_show, VWAP.TakeValueColor()); AddChartBubble(mover, UpperBand1[bubblemover + 1], "U1-" + num_days_to_show, UpperBand1.TakeValueColor()); AddChartBubble(mover, LowerBand1[bubblemover + 1], "L1-" + num_days_to_show, LowerBand1.TakeValueColor()); AddChartBubble(mover, UpperBand2[bubblemover + 1], "U2-" + num_days_to_show, UpperBand2.TakeValueColor()); AddChartBubble(mover, LowerBand2[bubblemover + 1], "L2-" + num_days_to_show, LowerBand2.TakeValueColor()); #
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.