Anchored VWAP Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
Anchored VWAP indicator can useful for intraday trading. It can also be used on any timeframe including hourly, daily, and weekly. VWAP can be a great tool for analyzing the market, especially for day traders.

Here we have 2 different Anchored VWAP indicator for ThinkorSwim. Feel free to test both out and use any that fits your trading style.



Original - Anchored VWAP Stops

Rich (BB code):
#START STUDY
#Anchored_VWAP_STOPS
#linus, 2014-03-10, v0.1

#hint: VWAP stops anchored off FractalTrader pivots.

#hint n: Lookback period for finding swing highs, lows.
input n = 20;

#hint ticks: Offset VWAP lines by this number of ticks.
input ticks = 2.0;

def bnOK = barNumber() > n;

def isHigher = fold i = 1 to n + 1 with p = 1
               while p do high > GetValue(high, -i);

def HH = if bnOK and isHigher
         and high == Highest(high, n)
         then high else Double.NaN;

def isLower = fold j = 1 to n + 1 with q = 1
              while q do low < GetValue(low, -j);

def LL = if bnOK and isLower
         and low == Lowest(low, n)
         then low else Double.NaN;

def PivH = if HH > 0 then HH else Double.NaN;
def PivL = if LL > 0 then LL else Double.NaN;

rec dir = compoundValue(1, if !isNaN(PivL) then 1 else if !isNaN(PivH) then -1 else dir[1], 0);

plot Up = dir crosses above 0;
Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Up.SetLineWeight(3);
Up.SetDefaultColor(Color.WHITE);

plot Dn = dir crosses below 0;
Dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Dn.SetLineWeight(3);
Dn.SetDefaultColor(Color.ORANGE);

def LocH = (high + (tickSize() * ticks)) * volume;
def LocL = (low - (tickSize() * ticks)) * volume;
rec PH;
rec VH;
rec PL;
rec VL;

if Dn {
    PH = LocH;
    VH = volume;
} else {
    PH = compoundValue(1, LocH + PH[1], Double.NaN);
    VH = compoundValue(1, volume + VH[1], Double.NaN);
}
if Up  {
    PL = LocL;
    VL = volume;
} else {
    PL = compoundValue(1, LocL + PL[1], Double.NaN);
    VL = compoundValue(1, volume + VL[1], Double.NaN);
}

plot VwapH = if Dn then Double.NaN else PH / VH;
plot VwapL = if Up then Double.NaN else PL / VL;

VwapH.SetDefaultColor(Color.DARK_RED);
VwapL.SetDefaultColor(Color.DARK_GREEN);
#END STUDY
#Note: /ES 5m chart of the Anchored_VWAP_STOPS study.
Shareable Link: http://tos.mx/ICxmA7



VWAP Anchored_v02

Rich (BB code):
#START STUDY
#Anchored_VWAP2
#linus, 2014-03-10, v0.1

#10:24 linus: it carries over the previous pivot's lines for high, low and close. (it plots vwaps of the high, low and close that are reset each time a new pivot is found.)
#10:25 linus: i wrote it to experiment with vwap as stops. (the high and low vwaps that can be offset by the ticks input.)
#10:25 linus: but it should serve as an example of how to reset the vwaps based on a signal.
#10:35 linus: #hint: VWAP stops anchored off  fractalTrader pivots.
#10:37 linus: the code calculates the pivots as PivH and PivL, and then restarts the high, low and close vwaps when it finds a new pivot.  Otherwise it continues to calculate the high, low and close vwaps.
#10:37 linus: the dashed vwap plots are the saved from the previous pivot, and the solid vwap plots are since the last pivot.

#hint: VWAP stops anchored off  fractalTrader pivots.

#hint n: Lookback period for finding swing highs, lows.
input n = 20;

#hint ticks: Offset High/Low VWAP lines by this number of ticks.
input ticks = 2.0;

def bnOK = barNumber() > n;

def isHigher = fold i = 1 to n + 1 with p = 1
               while p do high > GetValue(high, -i);

def HH = if bnOK and isHigher
         and high == Highest(high, n)
         then high else Double.NaN;

def isLower = fold j = 1 to n + 1 with q = 1
              while q do low < GetValue(low, -j);

def LL = if bnOK and isLower
         and low == Lowest(low, n)
         then low else Double.NaN;

def PivH = if HH > 0 then HH else Double.NaN;
def PivL = if LL > 0 then LL else Double.NaN;

plot Up = !isNaN(PivL);
Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Up.SetLineWeight(3);
Up.SetDefaultColor(Color.WHITE);

plot Dn = !isNaN(PivH);
Dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Dn.SetLineWeight(3);
Dn.SetDefaultColor(Color.ORANGE);

def LocH = (high + (tickSize() * ticks)) * volume;
def LocL = (low - (tickSize() * ticks)) * volume;
def LocC = close * volume;

rec PC;
rec VC;
rec PC2;
rec VC2;
rec PH;
rec VH;
rec PL;
rec VL;
rec PH2;
rec VH2;
rec PL2;
rec VL2;

if Dn or Up {
    PC = LocC;
    VC = volume;
    PC2 = PC[1];
    VC2 = VC[1];
} else {
    PC = compoundValue(1, LocC + PC[1], Double.NaN);
    VC = compoundValue(1, volume + VC[1], Double.NaN);
    PC2 = compoundValue(1, LocC + PC2[1], Double.NaN);
    VC2 = compoundValue(1, volume + VC2[1], Double.NaN);
}

if Dn {
    PH = LocH;
    VH = volume;
    PH2 = PH[1];
    VH2 = VH[1];
} else {
    PH = compoundValue(1, LocH + PH[1], Double.NaN);
    VH = compoundValue(1, volume + VH[1], Double.NaN);
    PH2 = compoundValue(1, LocH + PH2[1], Double.NaN);
    VH2 = compoundValue(1, volume + VH2[1], Double.NaN);
}
if Up  {
    PL = LocL;
    VL = volume;
    PL2 = PL[1];
    VL2 = VL[1];
} else {
    PL = compoundValue(1, LocL + PL[1], Double.NaN);
    VL = compoundValue(1, volume + VL[1], Double.NaN);
    PL2 = compoundValue(1, LocL + PL2[1], Double.NaN);
    VL2 = compoundValue(1, volume + VL2[1], Double.NaN);
}

plot VwapC = if Dn or Up then Double.NaN else PC / VC;
plot VwapC2 = if Dn or Up then Double.NaN else PC2 / VC2;
plot VwapH = if Dn then Double.NaN else PH / VH;
plot VwapL = if Up then Double.NaN else PL / VL;
plot VwapH2 = if Dn then Double.NaN else PH2 / VH2;
plot VwapL2 = if Up then Double.NaN else PL2 / VL2;

VwapC.SetDefaultColor(Color.YELLOW);
VwapC.SetLineWeight(2);
VwapC.HideBubble();

VwapC2.SetDefaultColor(Color.YELLOW);
VwapC2.SetLineWeight(2);
VwapC2.SetStyle(Curve.SHORT_DASH);
VwapC2.HideBubble();

VwapH.SetDefaultColor(Color.DARK_RED);
VwapH.HideBubble();

VwapL.SetDefaultColor(Color.DARK_GREEN);
VwapL.HideBubble();

VwapH2.SetDefaultColor(Color.DARK_RED);
VwapH2.SetStyle(Curve.SHORT_DASH);
VwapH2.HideBubble();

VwapL2.SetDefaultColor(Color.DARK_GREEN);
VwapL2.SetStyle(Curve.SHORT_DASH);
VwapL2.HideBubble();
#END STUDY
Shareable Link: http://tos.mx/s17BmB

Intraday Anchored VWAP

link for my intraday anchored VWAP script (shared by yakbrodev)
Code:
#yakBro intraday anchoredVWAP excluding extended hours volume 2019

declare hide_on_daily;

def anchorTime = 0930;
def anchorEnd = 1600;

input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;
def endAchorTime = if SecondsTillTime(anchorEnd) >= 0 then 1 else 0;

#plot anchorVWAP for intraday
def  volumeSum = compoundValue(1, if postAnchorTime and endAchorTime then volumeSum[1] + volume else 0, volume);
def  volumeVwapSum = compoundValue(1, if postAnchorTime and endAchorTime then volumeVwapSum[1] + volume * vwap else 0, volume * vwap);
 
plot anchorVWAP = if ShowTodayOnly and !Today then Double.NaN else if anchorTime then volumeVwapSum / volumeSum else Double.NaN;
anchorVWAP.setStyle(Curve.Firm);
anchorVWAP.setDefaultColor(Color.light_ORANGE);
anchorVWAP.setlineWeight(2);

Video Tutorial

 
Last edited:
markos

markos

Well-known member
VIP
Warehouse
I use Linus' 1st VWAP above when I look at short term charts. It is excellent, thanks, @BenTen
 
Last edited:
C

chillc15

New member
I use Linus' 1st VWAP above when I look at short term charts. It is excellent, thanks, @BenTen
Interesting indicator but I reviewed /CL on a one minute time frame this morning and what was interesting was that the buy and sell signals were delayed. Meaning that after a period of time I changed the time frame on the chart to like a 5 minute, went back to a one minute and there were new signals that previously were not there on the one minute chart. Just interested in how you use this on a shorter time period. Thanks
 
T

thinky

Member
Tried 1st indicator and have the same issue as with the Trend Exhaustion indicator, works with 1D:1m and 1D:3m, but not with 1D:5m and up, until I use 5D:5m, then it works, but only for the first 4 days, not the last.

Wish I could make Anchored VWAP #1 and Trend Reversal indicators work on the 5 minute chart (Today or 1D).
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@thinky Most likely because these indicators require more than just a single day of data.
 
T

thinky

Member
I have both on a 1D:3m chart and seem to be working (need to test on the Today:3m time frame).



Anchored VWAP starts working in the 1D:5m if the lookback period is changed from 20 to 17.

Trend Reversal doesn't have a similar parameter to test it in a 1D:5m chart.
 
markos

markos

Well-known member
VIP
Warehouse
Interesting indicator but I reviewed /CL on a one minute time frame this morning and what was interesting was that the buy and sell signals were delayed. Meaning that after a period of time I changed the time frame on the chart to like a 5 minute, went back to a one minute and there were new signals that previously were not there on the one minute chart. Just interested in how you use this on a shorter time period. Thanks
@chillc15 & @thinky the only way a one minute chart would stay the same after you left it to look at a five minute or five year chart would be for the price to stay the same as it was when you first left it, and then it still would not be right. Looking at the code, it is taking 20 bars and looking for a pivot. Wherever you have the time starting when you click on a one minute or whatever chart, it starts over, looking for a pivot hi/low in 20 bars. I hope this makes sense because it is pretty much the best I can explain it. Anyone else?

Also, curious to know, why are you looking at anything at such a short timeframe? I know it all depends on where a person learned, and maybe it's just me, but trading at the speed of a hummingbird's wings seems a little excessive, meaning price is so very random. (I will be the first to admit I know little about trading /CL)

There are two ways to adjust a chart like this: Change the input for number of bars. Turn off after hours so that only RTH is showing.
 
T

thinky

Member
Must say it is not logical for an indicator to work at 1 min and 3 min, but not 5 min for only the last day of trading, without changing the input (whether the info is reliable/useful).

It just seems arbitrary (surely missing something) if the indicator has no problem with 5m charts, but only if it is not the last day of trading after market close and only showing RTH, so the data the code is working on doesn't change.

* The question would be why is the last day any different from the previous day(s)?
 
Last edited:
markos

markos

Well-known member
VIP
Warehouse
@thinky Your questions are good ones. Unless someone else can help answer that question, I am out of answers.
Please call the Advanced Trading Support line. Their phone # is listed in the Tutorial Section 800-672-2098.
They can log into your computer and see what you are seeing. They are both traders and coders at that number.
Please let us know what answer you get.
 
T

thinky

Member
No worries, not using them with time frames below 5 min, which can give more false signals (why new signals), and can always add 2D(and up):5m time frame to see the last reversal in case of a 2-day bullish move (why no signals on last day), for example. Becoming familiar with indicators, ToS, and market activity.
 
markos

markos

Well-known member
VIP
Warehouse
@thinky Please papertrade w new indicators. No need to loose money if not familiar with new indicators and ToS. Good Trading to you!
 
C

corello

New member
VIP
Does this indicator give the signals in real time? Or is it delayed?
 
markos

markos

Well-known member
VIP
Warehouse
I found out where a hangup was on android. When using the intraday VWAP on android, you must have "use extended hours" turned ON.
see if that helps.
 
C

corello

New member
VIP
Going to test this on Sunday/Monday with /ES futures. Curious to see how long the delay is. The signals it gives for entry are very accurate.
 
C

Craighaber71

Member
VIP
Warehouse
Can we add an alert for above or below the high and low
 
C

Craighaber71

Member
VIP
Warehouse
How are your guys trading with this .....Breaking the hi/lo?
 
C

corello

New member
VIP
Trying to figure out how delayed these signals are. On the 5 minute, even if it was 10 min delayed, it would still give a great entry.
 
C

Craighaber71

Member
VIP
Warehouse
Are your entries above and below the lines
 
Thread starter Similar threads Forum Replies Date
J Questions 17
H Indicators 4
S Questions 5
P Questions 0
L Questions 6

Top