D

D

@dolomick ThinkorSwim uses Eastern Time. So you would still have to use 9:30.

T

please let me know, if it works on tick charts?

Last edited by a moderator:

@Talochka You will know as soon as you add it to a Tick chart

J

I'm trying to create an anchored VWAP indicator that would work for futures extended hours. The idea is to specify an input anchor time using 24-hour clock notation in the EST timezone. The VWAP would start plotting each day at the anchor time, which may or may not be on the previous calendar day, and may be in either the extended or regular hours session. The VWAP would stop plotting each day at the time specified by the RegularTradingEnd method. This should work no matter the specific futures contract being plotted nor the trading hours of the contract.

For example, for the /ES contract I believe the extended hours of a trading day starts at 6:00 pm the previous calendar day and runs through 9:30 am, and the regular hours session runs from 9:30 am to 5:00 pm. So, an anchor time anywhere from 1800 (previous calendar day) to 1659 would plot until 5:00 pm (1700), and then the VWAP would start over the next day again anchored at the same anchor time for the next day.

The problem I'm having is identifying the correct bars on which to calculate the VWAP.

Does anyone have any tips on how this can be accomplished?

For example, for the /ES contract I believe the extended hours of a trading day starts at 6:00 pm the previous calendar day and runs through 9:30 am, and the regular hours session runs from 9:30 am to 5:00 pm. So, an anchor time anywhere from 1800 (previous calendar day) to 1659 would plot until 5:00 pm (1700), and then the VWAP would start over the next day again anchored at the same anchor time for the next day.

The problem I'm having is identifying the correct bars on which to calculate the VWAP.

Does anyone have any tips on how this can be accomplished?

Last edited:

J

Code:

```
declare hide_on_daily;
input numDevDn = -2.0;
input numDevUp = 2.0;
input shouldPlotDevDn = yes;
input shouldPlotDevUp = yes;
# The default is TOS' vwap, but could use CLOSE, OHLC4, or some other price.
input vwap_Type = vwap;
input anchorTimeEastern = 2100;
# This specifies whether the current time is after the anchor time in
# the current calendar day (not after the anchor time within
# the current trading day).
def afterAnchorTime = SecondsFromTime(anchorTimeEastern) >= 0;
# Counts the number of bars since the previous trading day.
# The first bar of the new day will equal 1.
# Iterates from the current bar backward up to 1600 bars (more
# than then number of minutes in a day) counting each bar until
# the current bar is a different trading day.
def barCountFromPreviousTradingDay =
fold relativeBarIndex = 0 to 1600
with barCount = 1
while GetValue(GetYYYYMMDD(), relativeBarIndex) == GetValue(GetYYYYMMDD(), relativeBarIndex + 1)
do barCount + 1;
# Counts the number of bars since the anchor time.
# The first bar whose start time is greater than or equal
# to the anchor time will equal zero.
def barCountFromAnchorTime =
fold relativeBarIndex_at = 0 to 1600
with barCount_fromAnchorTime
while GetValue(SecondsFromTime(anchorTimeEastern), relativeBarIndex_at) > 0
do barCount_fromAnchorTime + 1;
# Since afterAnchorTime only checks to see if the current bar is after the anchor
# time of the current calendar day, this variable is needed to track whether after
# the anchor time within the current trading day (which includes regular and
# extended hours). To be true, the bar has to be after the anchor time of the current
# calendar day and that anchor time cannot be in the previous trading day.
# To account for anchor times in the previous calendar day that are not in the
# previous trading day (i.e. valid to plot), the second line will continue plotting
# once started until the trading day changes.
def shouldPlot_VWAP =
(afterAnchorTime and (barCountFromPreviousTradingDay > barCountFromAnchorTime)) or
(shouldPlot_VWAP[1] and barCountFromPreviousTradingDay != 1);
# If previous bar didn't plot VWAP, but current bar should, then this is the
# first bar after a valid anchor time. The OR conditional is needed to handle
# the situation where the anchor time is the first bar of the trading day,
# because the previous bar would have been plotted as well in that scenario.
def isFirstBarAfterAnchorTime =
CompoundValue(
1,
(shouldPlot_VWAP != shouldPlot_VWAP[1]) or (shouldPlot_VWAP and barCountFromPreviousTradingDay == 1),
yes);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
# Basically TOS' VWAP study calculation below
if (isFirstBarAfterAnchorTime) {
volumeSum = volume;
volumeVwapSum = volume * vwap_Type;
volumeVwap2Sum = volume * Sqr(vwap_Type);
} else {
volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap_Type, volume * vwap_Type);
volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap_Type), volume * Sqr(vwap_Type));
}
plot VWAP = if shouldPlot_VWAP then (volumeVwapSum / volumeSum) else Double.NaN;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(VWAP), 0));
#plot VWAP = price;
plot UpperBand = if shouldPlotDevUp then VWAP + numDevUp * deviation else Double.NaN;
plot LowerBand = if shouldPlotDevDn then VWAP + numDevDn * deviation else Double.NaN;
VWAP.SetDefaultColor(Color.CYAN);
UpperBand.SetDefaultColor(Color.GRAY);
LowerBand.SetDefaultColor(Color.GRAY);
VWAP.SetLineWeight(3);
UpperBand.SetLineWeight(1);
LowerBand.SetLineWeight(1);
```

M

Hi I am looking for the code for TOS so that I can add a 1 hour vWAP line to my daily charts.

This site also has loads of day traders so you're in the right place. Look at the bottom of the page for matches.

As you are new here, this is what we suggest: Look at the bottom of the page for matches.

Go to the Tutorials section here > https://usethinkscript.com/forums/tutorials.4/

Also type VWAP in our great SEARCH engine above. There are many available between these three sources. Best wishes!

Y

G

ive had repainting and delay issues. pretty much not usable for intra day trading.

G

@BenTen My apologies, Yes i meant the Signals.

Y

Can any1 help with a scanner for stocks touching previous days vwap

Last=previousVWAP

thanks

Last=previousVWAP

thanks

T

Can any1 help with a scanner for stocks touching previous days vwap

Last=previousVWAP

thanks

Here is a scan for stocks that crosses ABOVE the previous day's VWAP. Place this code in the scanner and run this on a daily aggregation. I just ran this on the S&P 100 (Daily) and obtained 46 results

Code:

```
# Scan for crosses above previous day's VWAP
# tomsk
# 1.21.2020
# Run on a daily aggregation
def cap = getAggregationPeriod();
def yyyyMmDd = getYyyyMmDd();
def periodIndx = yyyyMmDd;
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
def 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 VWAP = price;
plot scan = close crosses above VWAP[1];
# End Scan for crosses above previous day's VWAP
```

Y

@tomsk I have tried to scan it on daily doesnt show any results is there any other parameters to add

T

https://usethinkscript.com/threads/how-to-use-the-tos-scanner.284/

M

Does this one work out of the box on the 5 minute or is there something someone can suggest to find something or tweak this one to best suit my needs.

If this script paints the arrows where they currently appear on my charts for the 5 min, then this is awesome! I try to keep it simple and this just might be it. Going to test it tomorrow.

B

Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|

L | Anchored VWAP | Questions | 6 | |

J | Very Intriguing VWAP Indicator | Questions | 0 | |

T | Custom Scan - VWAP + Momentum Oscillator | Questions | 3 | |

Triple VWAP Indicator for ThinkorSwim | Custom | 0 | ||

Create VWAP deviation band price label | Questions | 2 |