chuckthetrader
New member
Does anyone have a Thinkorswim scan for when the stock price crosses over the Anchored VWAP? Not vwap but AVWAP
Hello SleepyZ. I had somewhat the same question on the Anchored VWAP. I understand that studies have the settings persistent and transfer to the next symbol selected. The way I look at an Anchored VWAP is that it should be an optional item with specifics to only that symbol. The closest thing I can think of is a drawing which is symbol specific. Take fibonaccis for instance. You cannot transfer that to another symbol.You can load multiple copies of the script and change the symbols at the input. The scripts will only display the one associated with the chart symbol
Sorry, I am not.Hello SleepyZ. I had somewhat the same question on the Anchored VWAP. I understand that studies have the settings persistent and transfer to the next symbol selected. The way I look at an Anchored VWAP is that it should be an optional item with specifics to only that symbol. The closest thing I can think of is a drawing which is symbol specific. Take fibonaccis for instance. You cannot transfer that to another symbol.
I did a search on drawings to see if custom drawings could be coded but did not find anywhere where that is possible. I do appreciate your helping on this indicator and recognize that adding the Anchored VWAP multiple times does allow one to apply this to multiple symbols with specific entries, but was hoping there was a way to code more like the drawing tools. Are you aware of any way to accomplish this? Thank you.
ez
In reference to the code in post #1 (Anchored VWAP Stops), is there a way to paint the candlesticks RED when the Down Arrow appears and continue to paint all subsequent candlesticks RED until an Up Arrow appears? At which point the candlesticks would paint GREEN and continue to paint all subsequent candlesticks GREEN until a Down Arrow appears?
I really appreciate any assistance with this! Thanks in advance!
Ruby:#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. def slow = if up then 1 else if slow[1]==1 and !dn then 1 else 0; assignpriceColor(if slow==1 then color.green else color.red);
This is exactly what I am looking for as well. Any possible updates? Custom Input for date and time with standard deviation bands similar to the TV indicator. Thank you all.My title may not make a lot of sense, but let me explain it.Code:# VWAP Standard Deviation Bands # lar # 12.12.2015 # V1.0 - 12.12.2015 - lar - Initial release of VWAP Standard Deviation bands # V1.1 - 12.17.2019 - tomsk - Minor edits input timeFrame = {Day, Week, Month, default Year, Chart, "March"}; input BandType = {default Standard, "1/4 Day Range", "3x Avg Bar Range", ThinkScripter, None}; input ShowCloud = yes; input HideSdLines = no; def cap = GetAggregationPeriod(); def errorInAggregation = timeFrame == timeFrame.Day and cap >= AggregationPeriod.WEEK or timeFrame == timeFrame.Week and cap >= AggregationPeriod.MONTH; Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period"); def yyyyMmDd = GetYYYYMMDD(); def seconds = SecondsFromTime(0); def month = GetYear() * 12 + GetMonth(); def year = GetYear(); def day_number = DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd)); def dom = GetDayOfMonth(yyyyMmDd); def dow = GetDayOfWeek(yyyyMmDd - dom + 1); def expthismonth = (if dow > 5 then 27 else 20) - dow; def exp_opt = month + (dom > expthismonth); def periodIndx; switch (timeFrame) { case Chart: periodIndx = 0; case Day: periodIndx = CountTradingDays(Min(First(yyyyMmDd), yyyyMmDd), yyyyMmDd) - 1; case Week: periodIndx = Floor(day_number / 7); case Month: periodIndx = Floor(month - First(month)); case Year: periodIndx = Floor(year - First(year)); case "March": periodIndx = Floor(2020 - First(2020)); } 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 deviation; switch (BandType) { case Standard: deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0)); case "1/4 Day Range": deviation = Sqrt(AbsValue(high(Period = timeFrame) - low(Period = timeFrame)) * .25); case "3x Avg Bar Range": deviation = Sqrt(Average(TrueRange(high, close, low), 20) * 3); case ThinkScripter: deviation = Sqrt(TotalSum(Sqr(((open + high + low + close) / 4) - price) * volume) / TotalSum(volume)); case None: deviation = Double.NaN; } plot VWAP = price; VWAP.AssignValueColor(if VWAP > VWAP[1] then Color.Cyan else if VWAP < VWAP[1] then Color.Red else Color.Yellow); VWAP.SetStyle(Curve.SHORT_DASH); VWAP.SetLineWeight(2); # TS_CHART_VWAP_SD_BANDS # http://www.thinkscripter.com # [email protected] # Last Update 03 APR 2010 input VWAPStdev1 = 1.0; input VWAPStdev2 = 2.0; input VWAPStdev3 = 3.0; plot r1 = VWAP + VWAPStdev1 * deviation; plot s1 = VWAP - VWAPStdev1 * deviation; plot r2 = VWAP + VWAPStdev2 * deviation; plot s2 = VWAP - VWAPStdev2 * deviation; plot r3 = VWAP + VWAPStdev3 * deviation; plot s3 = VWAP - VWAPStdev3 * deviation; DefineGlobalColor("sDev1", (CreateColor(40, 40, 40))); DefineGlobalColor("sDev2", (CreateColor(128, 128, 128))); DefineGlobalColor("sDev3", (CreateColor(100, 100, 100))); r1.SetDefaultColor(GlobalColor("sDev1")); s1.SetDefaultColor(GlobalColor("sDev1")); r2.SetDefaultColor(GlobalColor("sDev2")); s2.SetDefaultColor(GlobalColor("sDev2")); r3.SetDefaultColor(GlobalColor("sDev2")); s3.SetDefaultColor(GlobalColor("sDev2")); r1.SetStyle(Curve.SHORT_DASH); r2.SetStyle(Curve.SHORT_DASH); r3.SetStyle(Curve.SHORT_DASH); s1.SetStyle(Curve.SHORT_DASH); s2.SetStyle(Curve.SHORT_DASH); s3.SetStyle(Curve.SHORT_DASH); VWAP.HideBubble(); r1.HideBubble(); r2.HideBubble(); r3.HideBubble(); s1.HideBubble(); s2.HideBubble(); s3.HideBubble(); r1.SetHiding(HideSdLines); r2.SetHiding(HideSdLines); r3.SetHiding(HideSdLines); s1.SetHiding(HideSdLines); s2.SetHiding(HideSdLines); s3.SetHiding(HideSdLines); # CLOUD ########################## def CloudR1 = if ShowCloud then r1 else Double.NaN; def CloudR2 = if ShowCloud then r2 else Double.NaN; def CloudR3 = if ShowCloud then r3 else Double.NaN; def CloudS1 = if ShowCloud then s1 else Double.NaN; def CloudS2 = if ShowCloud then s2 else Double.NaN; def CloudS3 = if ShowCloud then s3 else Double.NaN; AddCloud(CloudR1, CloudR2, GlobalColor("sDev1"), GlobalColor("sDev1")); AddCloud(CloudS1, CloudS2, GlobalColor("sDev1"), GlobalColor("sDev1")); AddCloud(CloudR2, CloudR3, GlobalColor("sDev2"), GlobalColor("sDev2")); AddCloud(CloudS2, CloudS3, GlobalColor("sDev2"), GlobalColor("sDev2")); # End VWAP Standard Deviation Bands
As you know, with the anchored VWAP, you can anchor it at any date you want. I've been trying to translate this specific date code over to a VWAP w/ Standard Deviation Bands indicator I found on this website, but to no avail. The VWAP w/ SD Bands indicator only allows me to choose between: year, day, week and quarter. I don't want any of those, I want to pick the date where the bands and VWAP start, similar to an anchored VWAP. For example, I want the date to start at the bottom of the COVID March crash, March 23, 2020. Any ideas?
EDIT
https://www.tradingview.com/script/h8mk3PRk-Anchored-VWAP-w-STD-bands/
Here's an indicator in tradingview, with the idea I'm talking about, where it lets you anchor it at whatever date you want.
This is exactly what I am looking for as well. Any possible updates? Custom Input for date and time with standard deviation bands similar to the TV indicator. Thank you all.
Ruby:#VWAP Anchored to Date/Time input usehigher = {default current, higher}; input agg = AggregationPeriod.FIFTEEN_MIN; input startdate = 20211015; input starttime = 0930; def bn = BarNumber(); def c = close; def v = volume(period = agg); def vw = vwap(period = agg); def anchor; def volumesum; def volumevwapsum; def volumevwap2sum; def price; def deviation; if usehigher == usehigher.current and GetAggregationPeriod() < AggregationPeriod.DAY or usehigher == usehigher.higher and agg < AggregationPeriod.DAY { anchor = if GetYYYYMMDD() == startdate and SecondsFromTime(starttime)[1] <= 0 and SecondsFromTime(starttime) >= 0 then bn else anchor[1]; volumesum = if bn >= HighestAll(anchor) then volumesum[1] + volume else 0; volumevwapsum = if bn >= HighestAll(anchor) then volumevwapsum[1] + volume * vwap else 0; volumevwap2sum = if bn >= HighestAll(anchor) then volumevwap2sum[1] + volume * Sqr(vwap) else 0; price = volumevwapsum / volumesum; deviation = Sqrt(Max(volumevwap2sum / volumesum - Sqr(price), 0)); } else { anchor = if GetYYYYMMDD() >= startdate then 1 else 0; volumesum = if anchor then CompoundValue(1, volumesum[1] + v, v) else 0; volumevwapsum = if anchor then CompoundValue(1, volumevwapsum[1] + v * vw, v * vw) else 0; volumevwap2sum = if anchor then CompoundValue(1, volumevwap2sum[1] + v * Sqr(vw), v * Sqr(vw)) else 0; price = volumevwapsum / volumesum; deviation = Sqrt(Max(volumevwap2sum / volumesum - Sqr(price), 0)); } plot VWAP = price; VWAP.SetDefaultColor(GetColor(0)); input showbands = yes; input numDev1 = 1.0; input numDev2 = 2.0; input numDev3 = 3.0; plot UpperBand1 = if !showbands then Double.NaN else VWAP + numDev1 * deviation; plot LowerBand1 = if !showbands then Double.NaN else VWAP - numDev1 * deviation; plot UpperBand2 = if !showbands then Double.NaN else VWAP + numDev2 * deviation; plot LowerBand2 = if !showbands then Double.NaN else VWAP - numDev2 * deviation; plot UpperBand3 = if !showbands then Double.NaN else VWAP + numDev3 * deviation; plot LowerBand3 = if !showbands then Double.NaN else VWAP - numDev3 * deviation; VWAP.SetDefaultColor(Color.CYAN); UpperBand1.SetDefaultColor(Color.GREEN); LowerBand1.SetDefaultColor(Color.RED); UpperBand2.SetDefaultColor(Color.GREEN); LowerBand2.SetDefaultColor(Color.RED); UpperBand3.SetDefaultColor(Color.GREEN); LowerBand3.SetDefaultColor(Color.RED); VWAP.HideBubble(); UpperBand1.HideBubble(); LowerBand1.HideBubble(); UpperBand2.HideBubble(); LowerBand2.HideBubble(); UpperBand3.HideBubble(); LowerBand3.HideBubble(); input showclouds = yes; AddCloud(if showclouds then UpperBand3 else Double.NaN, UpperBand2, Color.LIGHT_GREEN, Color.LIGHT_GREEN); AddCloud(if showclouds then LowerBand3 else Double.NaN, LowerBand2, Color.LIGHT_RED, Color.LIGHT_RED); input showbubblesline = yes; input bubblemoverVWAP_Labels = 5;#Hint bubblemoverVWAP_Labels: Number of Spaces bubble offset in expansion area def n = bubblemoverVWAP_Labels; def n1 = n + 1; AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] , "V:\n" + Round(price[n1] , 2), Color.ORANGE); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] + numDev1 * deviation[n1] , "V1:\n" + Round((price[n1] + numDev1 * deviation[n1]), 2), Color.GREEN); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] + numDev2 * deviation[n1] , "V2:\n" + Round(price[n1] + numDev2 * deviation[n1], 2), Color.GREEN); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] + numDev3 * deviation[n1] , "V3:\n" + Round(price[n1] + numDev3 * deviation[n1], 2), Color.GREEN); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] - numDev1 * deviation[n1] , "V1:\n" + Round(price[n1] - numDev1 * deviation[n1], 2), Color.RED, no); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] - numDev2 * deviation[n1] , "V2:\n" + Round(price[n1] - numDev2 * deviation[n1] , 2), Color.RED, no); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] - numDev3 * deviation[n1] , "V3:\n" + Round(price[n1] - numDev3 * deviation[n1] , 2), Color.RED, no); input showbubblescurrSTD = no; input bubblemoverVSTD = 1;#Hint bubblemoverVSTD: Number of Spaces VSTD bubble offset in expansion def p = bubblemoverVSTD; def p1 = p + 1; AddChartBubble(showbubblescurrSTD and IsNaN(c[p]) and !IsNaN(c[p1]) , c[p1], Round(((c[p1] - price[p1]) / deviation[p1]), 1) + "\n" + Round(c[p1], 2) , if c[p1] > VWAP[p1] then Color.GREEN else Color.RED, if c[p1] > VWAP[p1] then yes else no );
noDoes this repaint
Dear Friend, thank you for the great work you have done! I have added 0.5 bands to your code because I use them for my strategy. Also this works exactly like the TV script. Well done!This is something I did awhile ago that might work. You can either choose to have the vwap plotted using the current chart agg or a higher agg. Input a date that is on the chart. If the date is not on the chart, it will plot the VWAP for the whole chart displayed.
#VWAP Anchored to Date/Time
input usehigher = {default current, higher};
input agg = AggregationPeriod.FIFTEEN_MIN;
input startdate = 20211015;
input starttime = 0930;
def bn = BarNumber();
def c = close;
def v = volume(period = agg);
def vw = vwap(period = agg);
def anchor;
def volumesum;
def volumevwapsum;
def volumevwap2sum;
def price;
def deviation;
if usehigher == usehigher.current and GetAggregationPeriod() < AggregationPeriod.DAY or
usehigher == usehigher.higher and agg < AggregationPeriod.DAY {
anchor = if GetYYYYMMDD() == startdate and
SecondsFromTime(starttime)[1] <= 0 and
SecondsFromTime(starttime) >= 0
then bn else anchor[1];
volumesum = if bn >= HighestAll(anchor) then volumesum[1] + volume else 0;
volumevwapsum = if bn >= HighestAll(anchor) then volumevwapsum[1] + volume * vwap else 0;
volumevwap2sum = if bn >= HighestAll(anchor) then volumevwap2sum[1] + volume * Sqr(vwap) else 0;
price = volumevwapsum / volumesum;
deviation = Sqrt(Max(volumevwap2sum / volumesum - Sqr(price), 0));
} else {
anchor = if GetYYYYMMDD() >= startdate then 1 else 0;
volumesum = if anchor then CompoundValue(1, volumesum[1] + v, v) else 0;
volumevwapsum = if anchor then CompoundValue(1, volumevwapsum[1] + v * vw, v * vw) else 0;
volumevwap2sum = if anchor then CompoundValue(1, volumevwap2sum[1] + v * Sqr(vw), v * Sqr(vw))
else 0;
price = volumevwapsum / volumesum;
deviation = Sqrt(Max(volumevwap2sum / volumesum - Sqr(price), 0));
}
plot VWAP = price;
VWAP.SetDefaultColor(GetColor(0));
input showbands = yes;
input numDev1 = 1.0;
input numDev2 = 2.0;
input numDev3 = 3.0;
input numDev4 = 0.5;
plot UpperBand1 = if !showbands then Double.NaN else VWAP + numDev1 * deviation;
plot LowerBand1 = if !showbands then Double.NaN else VWAP - numDev1 * deviation;
plot UpperBand2 = if !showbands then Double.NaN else VWAP + numDev2 * deviation;
plot LowerBand2 = if !showbands then Double.NaN else VWAP - numDev2 * deviation;
plot UpperBand3 = if !showbands then Double.NaN else VWAP + numDev3 * deviation;
plot LowerBand3 = if !showbands then Double.NaN else VWAP - numDev3 * deviation;
plot UpperBand4 = if !showbands then Double.NaN else VWAP + numDev4 * deviation;
plot LowerBand4 = if !showbands then Double.NaN else VWAP - numDev4 * deviation;
VWAP.SetDefaultColor(Color.CYAN);
UpperBand1.SetDefaultColor(Color.GREEN);
LowerBand1.SetDefaultColor(Color.RED);
UpperBand2.SetDefaultColor(Color.GREEN);
LowerBand2.SetDefaultColor(Color.RED);
UpperBand3.SetDefaultColor(Color.GREEN);
LowerBand3.SetDefaultColor(Color.RED);
UpperBand4.SetDefaultColor(Color.GREEN);
LowerBand4.SetDefaultColor(Color.RED);
VWAP.HideBubble();
UpperBand1.HideBubble();
LowerBand1.HideBubble();
UpperBand2.HideBubble();
LowerBand2.HideBubble();
UpperBand3.HideBubble();
LowerBand3.HideBubble();
UpperBand4.HideBubble();
LowerBand4.HideBubble();
input showclouds = yes;
AddCloud(if showclouds then UpperBand3 else Double.NaN, UpperBand2, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showclouds then LowerBand3 else Double.NaN, LowerBand2, Color.LIGHT_RED, Color.LIGHT_RED);
input showbubblesline = yes;
input bubblemoverVWAP_Labels = 5;#Hint bubblemoverVWAP_Labels: Number of Spaces bubble offset in expansion area
def n = bubblemoverVWAP_Labels;
def n1 = n + 1;
AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) ,
price[n1] ,
"V:\n" + Round(price[n1] , 2),
Color.ORANGE);
AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) ,
price[n1] + numDev1 * deviation[n1] ,
"V1:\n" + Round((price[n1] + numDev1 * deviation[n1]), 2),
Color.GREEN);
AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) ,
price[n1] + numDev2 * deviation[n1] ,
"V2:\n" + Round(price[n1] + numDev2 * deviation[n1], 2),
Color.GREEN);
AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) ,
price[n1] + numDev3 * deviation[n1] ,
"V3:\n" + Round(price[n1] + numDev3 * deviation[n1], 2),
Color.GREEN);
AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) ,
price[n1] - numDev1 * deviation[n1] ,
"V1:\n" + Round(price[n1] - numDev1 * deviation[n1], 2),
Color.RED, no);
AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) ,
price[n1] - numDev2 * deviation[n1] ,
"V2:\n" + Round(price[n1] - numDev2 * deviation[n1] , 2),
Color.RED, no);
AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) ,
price[n1] - numDev3 * deviation[n1] ,
"V3:\n" + Round(price[n1] - numDev3 * deviation[n1] , 2),
Color.RED, no);
input showbubblescurrSTD = no;
input bubblemoverVSTD = 1;#Hint bubblemoverVSTD: Number of Spaces VSTD bubble offset in expansion
def p = bubblemoverVSTD;
def p1 = p + 1;
AddChartBubble(showbubblescurrSTD and IsNaN(c[p]) and !IsNaN(c[p1]) ,
c[p1],
Round(((c[p1] - price[p1]) / deviation[p1]), 1) +
"\n" + Round(c[p1], 2) ,
if c[p1] > VWAP[p1]
then Color.GREEN
else Color.RED,
if c[p1] > VWAP[p1]
then yes else no );
#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);
Strange question, but looking at this thread I think it MIGHT be possible.
Would there be a way to anchor VWAP to the "moment" a condition happens?
Example: The first time intraday a candle opens below VWAP and closes above VWAP --> Start the anchor there
Any way to make that work?
(thanks in advance, I'm stumped)
Ruby:## START STUDY ## Anchored_VWAP3 ## linus, 2014-06-28, v0.3 ## 20211117 Sleepyz modified to use a cond to anchor vwap input ticks = 2; input nhighlow = 5; input hidegaps = yes; #Cond defined------------------------------------------------------------------- plot prevdayhigh = high(period = AggregationPeriod.DAY)[1]; plot prevdaylow = low(period = AggregationPeriod.DAY)[1]; def cond = if close crosses prevdayhigh then 1 else if close crosses prevdaylow then -1 else 0; #------------------------------------------------------------------------------- def dir = cond; def up = dir crosses above 0; def dn = dir crosses below 0; def h = if dir crosses 0 then Highest(high, nhighlow) else high; def l = if dir crosses 0 then Lowest(low, nhighlow) else low; def LocH = (h + (TickSize() * ticks)) * volume; def LocL = (l - (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; plot VwapC2; plot VwapH; plot VwapL; plot VwapH2; plot VwapL2; if hidegaps { VwapC = if dn or up then Double.NaN else PC / VC; VwapC2 = if dn or up then Double.NaN else PC2 / VC2; VwapH = if dn then Double.NaN else PH / VH; VwapL = if up then Double.NaN else PL / VL; VwapH2 = if dn then Double.NaN else PH2 / VH2; VwapL2 = if up then Double.NaN else PL2 / VL2; } else { VwapC = PC / VC; VwapC2 = PC2 / VC2; VwapH = PH / VH; VwapL = PL / VL; VwapH2 = PH2 / VH2; VwapL2 = 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();
#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
@SleepyZ, this is a GREAT study, THANK YOU! May I request one modification?This is something I did awhile ago that might work. You can either choose to have the vwap plotted using the current chart agg or a higher agg. Input a date that is on the chart. If the date is not on the chart, it will plot the VWAP for the whole chart displayed.
Hey guys Can someone get this version of the anchored VWAP to just appear on the most recent move instead of showing all previous anchored vwaps depending on the chart.
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
#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;
#Limit plot of cond to count, based upon Linus' logic ------------------------------------------
input show_last_vwap_only = yes;
input Count = 2;
def cond = !isnan(pivH) or !isnan(pivL);
def dataCount = CompoundValue(1, if (cond) then dataCount[1] + 1 else dataCount[1], 0);
#-----------------------------------------------------------------------------------------------
plot Up = if !show_last_vwap_only then !isnan(PivL) else if HighestAll(dataCount) - dataCount <= Count - 1 then !isNaN(PivL) else double.nan;
Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Up.SetLineWeight(3);
Up.SetDefaultColor(Color.WHITE);
plot Dn = if !show_last_vwap_only then !isnan(PivH) else if HighestAll(dataCount) - dataCount <= Count - 1 then !isNaN(PivH) else double.nan;
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
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
J | High/Low Anchored VWAP For ThinkOrSwim | Indicators | 16 | |
RSI (or MACD) with VWAP & MA & div for ThinkOrSwim | Indicators | 11 | ||
Opening Range Indicator with Measured Moves and VWAP For ThinkOrSwim | Indicators | 43 | ||
RSI-VWAP Indicator for ThinkorSwim | Indicators | 68 | ||
Squeeze Clouds based on SMA and VWAP | Indicators | 7 |
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.