Anchored VWAP Indicator for ThinkorSwim

F

FibDude

New member
I have an anchored VWAP code with standard deviations and I was wondering if anyone could modify it to automatically anchor to the day of the last earnings report. code is below thanks

Code:
# input is bar 126 bc that is the last bar on the 6M 1D Timeframe I use
input Number_Of_Bar1 = 126;
#I set it to 14 days back as that seems to be norm with other indicators like RSI
def Number_Of_Bar = Number_of_Bar1 - 14;
def Data = BarNumber();
input price = ohlc4;
def bar =  Data >= Number_Of_Bar;
def pv = if bar then pv[1] + price * volume else 0;
def cumvolume = if bar then cumvolume[1] + volume else 0;
plot vw = pv / cumvolume;
def bars = data - number_Of_Bar;
def sample = if bar then sample[1] + sqr(price - vw) else 0;
def var = sample/bars;
def dev = sqrt(var);
plot dev1 =  vw + dev;
plot dev2 = vw + (dev * 2);
plot dev3 = vw + (dev * 3);
plot devN1 =  vw - dev;
plot devN2 = vw - (dev * 2);
plot devN3 = vw - (dev * 3);
 
R

ReyHak

New member
Hi,
This custom anchoredVWAP indicator does not work on some hourly charts (1,4 hour etc...) For example it does not work for GDX 4H chart but it does work for GLD 4H chart, what am I doing wrong?

Code:
input anchorDate = 20200805;
input anchorTime = 2030;


def tradeStartEST = 0930;
def tradeEndEST = 1600;
def inPeriod = if SecondsTillTime(tradeStartEST) <= 0 and SecondsTillTime(tradeEndEST) > 0 then 1 else 0;

def revisedDate = if SecondsTillTime(anchorTime)<=0 and !inPeriod then anchorDate+1 else if SecondsTillTime(anchorTime)<=0 and inPeriod then anchorDate else anchorDate;

def postAnchorDate = if GetYYYYMMDD() >= revisedDate then 1 else 0;
def postAnchorTime = if SecondsTillTime(anchorTime) <= 0 then 1 else 0;

plot anchoredVWAP = TotalSum(if postAnchorDate and postAnchorTime then ((high+low+close)/3)*(volume) else 0)/TotalSum(if postAnchorDate and postAnchorTime then volume else 0);

anchoredVWAP.setStyle(Curve.Firm);
anchoredVWAP.SetLineWeight(3);
anchoredVWAP.SetDefaultColor(Color.Cyan);

#AddChartBubble(yes,close, revisedDate, color.yellow);
 
R

Richenough

New member
Can someone help me auto anchor a vwap from the high / low from a chart instead of inputting it myself from this script

Code:
input anchorDate = 20200917;
input anchorTime = 1130;

def postAnchorDate = if GetYYYYMMDD()  >= anchorDate then 1 else 0;
def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;
plot anchoredVWAP = TotalSum(if postAnchorDate and postAnchorTime then ((high+low+close)/3)*(volume) else 0)/TotalSum(if postAnchorDate and postAnchorTime then volume else 0);

anchoredVWAP.setStyle(Curve.Firm);
anchoredVWAP.SetLineWeight(3);
anchoredVWAP.SetDefaultColor(Color.Cyan);
 
Tradervic

Tradervic

New member
VIP
@FOTM_8888 If you look into the original concept and idea of Anchored VWAP, it should not have any signals at all.
Ben, you said because the signal is delayed, no point in scanning for it. But is there a way to scan even if its delayed? Second question is when I try the intraday Anchored VWAP, only the line shows up, but no arrows.
 
BenTen

BenTen

Administrative
Staff
VIP
@Tradervic You should be able to scan even if the signals are delayed. However, you may have to adjust the within X bar option to account for the lag. See the video tutorial below on how to use the scanner.


The intraday anchored VWAP does not have any arrows.
 
S

spencepuppy

New member
VIP
If you change "n" to 1 does it change to real-time and fires off a signal after previous one closes?
 
G

GERMANB1990

New member
Below is an indicator that will plot the high and low of previous days to the vwap as well as create deviation channels.

Code:
# study name: TheVWAP_HighLow
# author:     © Zachary M. Hurwitz
# date:       April 14, 2020
#
# email:      [email protected]
# twitter:    @ZachHurwitz
# website:    https://www.theVWAP.com

#hint: Plots VWAPs from the local (day) high and/or low of a (user-input) X days ago.
#
#hint Days_Ago: The number of days ago (current = 0) for which the HighVWAP or LowVWAP is calculated.
#hint VWAP_High_or_Low: Displays either the chart's Highest HighVWAP and Lowest LowVWAP ("HH_LL") on respective days, both HighVWAP <b> and </b> LowVWAP (default), or HighVWAP (or LowVWAP) individually.
#hint StDev1: Standard deviations from VWAP (primary band).
#hint StDev2: Standard deviations from VWAP (secondary band).
#hint Deviation_Bands: Displays standard deviation bands ('Yes) or hides them ('No') for the selected VWAPs.
#hint Deviation_Band_Color: Displays Green/Red colorization based on HighVWAP (Red to indicate likely resistance) or LowVWAP (Green to indicate likely support).
#hint price_type: Selects input price type for the VWAP calculation.  VWAP in this context refers to the bar's "pure" vwap as designated by AMTD/TOS and is not reflective of the daily cumulative VWAP study.

DefineGlobalColor("High VWAP + Deviations", CreateColor(240, 0, 0));
DefineGlobalColor("Low VWAP + Deviations", CreateColor(0, 199, 145));

input Days_Ago = 0;
input VWAP_High_or_Low = {default Both, HighVWAP, LowVWAP, HH_LL};
input Deviation_Bands = No;
input Deviation_Band_Color = Yes;
input price_type = {High, Low, default VWAP};
input StDev1 = 1.0;
input StDev2 = 2.0;

def date = GetYYYYMMDD();
def dateReset = date != date[1];
def DayCount = CompoundValue(1, date != date[1] and !IsNaN(close), yes);
def Days_Elapsed = TotalSum(DayCount);
def highestDays = HighestAll(Days_Elapsed);
def onDaysAgo = highestDays - Days_Ago == Days_Elapsed;
def afterDaysAgo = if VWAP_High_or_Low == VWAP_High_or_Low."HH_LL" then 1 else Days_Elapsed >= (highestDays - Days_Ago);

def vol = volume();
def TypicalPrice;
switch (price_type) {
case High:
    TypicalPrice = high;
case Low:
    TypicalPrice = low;
default:
    TypicalPrice = vwap;
}
def Money = TypicalPrice * vol;

def plotfilter_low = if Deviation_Bands and VWAP_High_or_Low != VWAP_High_or_Low."HighVWAP" then 1 else Double.NaN;
def plotfilter_high = if Deviation_Bands and VWAP_High_or_Low != VWAP_High_or_Low."LowVWAP" then 1 else Double.NaN;

def HH = HighestAll(high);
def LL = LowestAll(low);
def fut_mkt_open = 1800;

def day_high = high(period = AggregationPeriod.DAY);
def day_low = low(period = AggregationPeriod.DAY);
def track_High = CompoundValue(1, if dateReset then high else if high > track_High[1] then high else track_High[1], high);
def track_Low = CompoundValue(1, if dateReset then low else if low < track_Low[1] then low else track_Low[1], low);
def var_high = if IsNaN(day_high) or day_high != track_High then track_High else day_high;
def var_low = if IsNaN(day_low) or day_low != track_Low then track_Low else day_low;
def prc_High = CompoundValue(1, if afterDaysAgo then var_high else prc_High[1], if afterDaysAgo then var_high else 0);
def prc_Low = CompoundValue(1, if afterDaysAgo then var_low else prc_Low[1], if afterDaysAgo then var_low else 0);

def barNo = CompoundValue(1, barNo[1] + 1, 1);
def barNoH = CompoundValue(1, if high == prc_High then barNo else barNoH[1], 1);
def barNoL = CompoundValue(1, if low == prc_Low then barNo else barNoL[1], 1);
def latestBarNoH = HighestAll(if onDaysAgo then barNoH else Double.NaN);
def latestBarNoL = HighestAll(if onDaysAgo then barNoL else Double.NaN);

def showHVW = CompoundValue(1,
if ((VWAP_High_or_Low == VWAP_High_or_Low."Both" or VWAP_High_or_Low == VWAP_High_or_Low."HighVWAP") and barNo >= latestBarNoH)
or (VWAP_High_or_Low == VWAP_High_or_Low."HH_LL" and high == HH) then 1 else showHVW[1],
if ((VWAP_High_or_Low == VWAP_High_or_Low."Both" or VWAP_High_or_Low == VWAP_High_or_Low."HighVWAP") and barNo >= latestBarNoH)
or (VWAP_High_or_Low == VWAP_High_or_Low."HH_LL" and high == HH) then 1 else 0);

def showLVW = CompoundValue(1,
if ((VWAP_High_or_Low == VWAP_High_or_Low."Both" or VWAP_High_or_Low == VWAP_High_or_Low."LowVWAP") and barNo >= latestBarNoL)
or (VWAP_High_or_Low == VWAP_High_or_Low."HH_LL" and low == LL) then 1 else showLVW[1],
if ((VWAP_High_or_Low == VWAP_High_or_Low."Both" or VWAP_High_or_Low == VWAP_High_or_Low."LowVWAP") and barNo >= latestBarNoL)
or (VWAP_High_or_Low == VWAP_High_or_Low."HH_LL" and low == LL) then 1 else 0);

def afterHigh = CompoundValue(1, if high == prc_High then 1 else afterHigh[1], if high == prc_High then 1 else 0);
def afterLow = CompoundValue(1, if low == prc_Low then 1 else afterLow[1], if low == prc_Low then 1 else 0);

def TotalVolume_High = if showHVW then if IsNaN(TotalVolume_High[1]) then volume else TotalVolume_High[1] + volume else Double.NaN;
def TotalTransactions_High = if showHVW then if IsNaN(TotalTransactions_High[1]) then Money else TotalTransactions_High[1] + Money else Double.NaN;
def HighVW = if high == showHVW then TypicalPrice else if TotalVolume_High != 0 then TotalTransactions_High / TotalVolume_High else Double.NaN;
def startedVWAP_high = if !IsNaN(HighVW) then 1 else 0;
def deviation_High = Sqrt(TotalSum(Sqr(if startedVWAP_high then TypicalPrice - HighVW else 0) * volume) / TotalSum(if startedVWAP_high then volume else 0));
def volumeVWAP2SumH = if !IsNaN(HighVW) then volumeVWAP2SumH[1] + volume * Sqr(HighVW) else volume * Sqr(HighVW);
def DfVW_high = (close - HighVW) / deviation_High;

def TotalVolume_Low = if showLVW then if IsNaN(TotalVolume_Low[1]) then volume else TotalVolume_Low[1] + volume else Double.NaN;
def TotalTransactions_Low = if showLVW then if IsNaN(TotalTransactions_Low[1]) then Money else TotalTransactions_Low[1] + Money else Double.NaN;
def LowVW = if low == showLVW then TypicalPrice else if TotalVolume_Low != 0 then TotalTransactions_Low / TotalVolume_Low else Double.NaN;
def startedVWAP_low = if !IsNaN(LowVW) then 1 else 0;
def deviation_Low = Sqrt(TotalSum(Sqr(if startedVWAP_low then TypicalPrice - LowVW else 0) * volume) / TotalSum(if startedVWAP_low then volume else 0));
def volumeVWAP2SumL = if !IsNaN(LowVW) then volumeVWAP2SumL[1] + volume * Sqr(LowVW) else volume * Sqr(LowVW);
def DfVW_low = (close - LowVW) / deviation_Low;

def condition_High = if VWAP_High_or_Low == VWAP_High_or_Low."HH_LL" then HH else if afterDaysAgo then high(period = AggregationPeriod.DAY) else condition_High[1];
def condition_Low = if VWAP_High_or_Low == VWAP_High_or_Low."HH_LL" then LL else if afterDaysAgo then low(period = AggregationPeriod.DAY) else condition_Low[1];

plot VWAP_low = If(TotalVolume_Low != 0, TotalTransactions_Low / TotalVolume_Low, Double.NaN);
VWAP_low.SetHiding(VWAP_High_or_Low == VWAP_High_or_Low."HighVWAP");
VWAP_low.AssignValueColor(GlobalColor("Low VWAP + Deviations"));
VWAP_low.SetLineWeight(2);

plot VWAP_high = If(TotalVolume_High != 0, TotalTransactions_High / TotalVolume_High, Double.NaN);
VWAP_high.SetHiding(VWAP_High_or_Low == VWAP_High_or_Low."LowVWAP");
VWAP_high.AssignValueColor(GlobalColor("High VWAP + Deviations"));
VWAP_high.SetLineWeight(2);

plot r1L = VWAP_low + StDev1 * deviation_Low * plotfilter_low;
plot s1L = VWAP_low - StDev1 * deviation_Low * plotfilter_low;
plot r2L = VWAP_low + StDev2 * deviation_Low * plotfilter_low;
plot s2L = VWAP_low - StDev2 * deviation_Low * plotfilter_low;

r1L.AssignValueColor(if Deviation_Band_Color then GlobalColor("Low VWAP + Deviations") else Color.LIGHT_GRAY);
r2L.AssignValueColor(if Deviation_Band_Color then GlobalColor("Low VWAP + Deviations") else Color.LIGHT_GRAY);
s1L.AssignValueColor(if Deviation_Band_Color then GlobalColor("Low VWAP + Deviations") else Color.LIGHT_GRAY);
s2L.AssignValueColor(if Deviation_Band_Color then GlobalColor("Low VWAP + Deviations") else Color.LIGHT_GRAY);
r1L.SetStyle(Curve.SHORT_DASH);
r2L.SetStyle(Curve.FIRM);
s1L.SetStyle(Curve.SHORT_DASH);
s2L.SetStyle(Curve.FIRM);
r1L.HideBubble();
r2L.HideBubble();
s1L.HideBubble();
s2L.HideBubble();

plot r1H = VWAP_high + StDev1 * deviation_High * plotfilter_high;
plot s1H = VWAP_high - StDev1 * deviation_High * plotfilter_high;
plot r2H = VWAP_high + StDev2 * deviation_High * plotfilter_high;
plot s2H = VWAP_high - StDev2 * deviation_High * plotfilter_high;

r1H.AssignValueColor(if Deviation_Band_Color then GlobalColor("High VWAP + Deviations") else Color.LIGHT_GRAY);
r2H.AssignValueColor(if Deviation_Band_Color then GlobalColor("High VWAP + Deviations") else Color.LIGHT_GRAY);
s1H.AssignValueColor(if Deviation_Band_Color then GlobalColor("High VWAP + Deviations") else Color.LIGHT_GRAY);
s2H.AssignValueColor(if Deviation_Band_Color then GlobalColor("High VWAP + Deviations") else Color.LIGHT_GRAY);
r1H.SetStyle(Curve.SHORT_DASH);
r2H.SetStyle(Curve.FIRM);
s1H.SetStyle(Curve.SHORT_DASH);
s2H.SetStyle(Curve.FIRM);
r1H.HideBubble();
r2H.HideBubble();
s1H.HideBubble();
s2H.HideBubble();
 
Last edited by a moderator:
C

chIza=iChis1A?H

Member
VIP
@chillc15 Any updated version to take care of this delay. Ilove this it just UP and DOwn arreow shows with delay. Please help me. Thanks I am just using 1 Min chart.

@markos Its has two inputs mainly n and ticks , which one to update and what is the correct value to see this UP and down on right time ?? Thanks
 
Last edited by a moderator:
C

chIza=iChis1A?H

Member
VIP
I can give you one example. I am in front of my screen since 6 PM when In'day futures starts and since then I don't see any UP or down sign now....so its almost 2 and half hours.
 
E

ext99k

Member
I can give you one example. I am in front of my screen since 6 PM when In'day futures starts and since then I don't see any UP or down sign now....so its almost 2 and half hours.

what about if you're using longer time periods like days? does that mean it will produce a signal 2 days later?
 
C

chIza=iChis1A?H

Member
VIP
Of course it shoueld't be. But I changed my time frames to 5,10 mins and even 15 mins, no luck. See its weired now. I removed and then re added the same chart code again and apply it after that it is showing me that last UP arrow was on 8.22 pm ET. But this is weird I can't remove and add chart after every five min to show the arrow position.....
 
C

chIza=iChis1A?H

Member
VIP
I have an update on this script. The above script will works ONLY for TODAY during normal future hours which are 0930 to 1600. But here is my version which will work for ANY day and including any time chart. I had tested it , but you all feel free to test and use it. Enjoy !

Code:
#*******************************************************************************************************************************
#Intraday anchored VWAP - works for ANY day and works for all the different typs of time charts like 1,2,5,10,15...etc
# Created by Parag Sathe as on 11/05/2020
#*******************************************************************************************************************************

declare hide_on_daily;

def anchorTime = 0000;

input ShowTodayOnly = yes;
def Today = 1 ;
def postAnchorTime = 1;
def endAchorTime = 1 ;

#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);

def  volumeSum = compoundValue(1, volumeSum[1] + volume , volume);
def  volumeVwapSum = compoundValue(1,  volumeVwapSum[1] + volume * vwap , volume * vwap);


plot anchorVWAP = volumeVwapSum / volumeSum ;
anchorVWAP.setStyle(Curve.Firm);
anchorVWAP.setDefaultColor(Color.light_ORANGE);
anchorVWAP.setlineWeight(3);
 
BenTen

BenTen

Administrative
Staff
VIP
@ext99k Anchored VWAP shouldn't have any arrows in the first place (you can learn more about the original concept here). But it was added by "linus" in his thinkscript version. In short, yes, the arrows will appear later on, not in real-time.
 
E

ext99k

Member
@BenTen thanks for your reply. it appears to do a great job at identifying infliction points, wondering if it repaints and what that delay is... like is it a few days on daily bars? or is it weeks... even if it takes days, it still appears useful as long as no repaint - thanks
 
C

Craighaber71

Active member
2019 Donor
VIP
@GERMANB1990 Is it possible to just plot from the Hi/Lo and not from days ago...
 
C

chIza=iChis1A?H

Member
VIP
@ext99k Anchored VWAP shouldn't have any arrows in the first place (you can learn more about the original concept here). But it was added by "linus" in his thinkscript version. In short, yes, the arrows will appear later on, not in real-time.
@BenTen, I agree with you but since I am relying on this chat primarily to ENTER and EXIT the position so my valid concern is those Arrows should have appeared on time. Since now you said it delayed so need to figure out how to correct this issue.

IS the PAID version of your script is good for intraday for 1m to 15 mins of chart style? I am mainly using Micro futures to trade on a daily basis so expecting an indicator that works 100% correct, please advise so I can be a VIP member. Thanks
 
G

germanburrito

New member
@BenTen, I agree with you but since I am relying on this chat primarily to ENTER and EXIT the position so my valid concern is those Arrows should have appeared on time. Since now you said it delayed so need to figure out how to correct this issue.

IS the PAID version of your script is good for intraday for 1m to 15 mins of chart style? I am mainly using Micro futures to trade on a daily basis so expecting an indicator that works 100% correct, please advise so I can be a VIP member. Thanks
no bro, it needs to be delayed, so the arrows are fractals, fractals can only form after 2 bars, but it really doesnt matter if they form late because the point of those fractols are to create an anchored vwap so you can tell where future price might bounce.
 

Similar threads

Top