This scanner MUST be run on the Daily TimeFrametomsk, to use this Scan first needs to be imported as a Study or I can just use it as Scan?
The script can be saved as a study first.
or
Feel free to stuff the script into the Scan Hacker
This scanner MUST be run on the Daily TimeFrametomsk, to use this Scan first needs to be imported as a Study or I can just use it as Scan?
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Can you insert a sound signal when an arrow appears???I modified and merged Mobius Fractal Pivots to just R1/S1 with Linus VWAP code, which does not plot properly without refreshing the chart. Now this should plot timely, but since it uses future bars, it will plot the pivot arrows/lenes only after the future bar requirement is met. As this worked to overcome the problem in Linus' code, I did not spend anytime to try to figure out how to fix Linus' code
[Edit] - Corrected R1/S1 lines to appear on their most recent pivots. As Linus code was a zigzag type pattern for drawing the VWAP, I had excluded the pivots in the same direction with the PointCount code. These are now included for just drawing the R1/S1 lines and may be useful.
Code:# Mobius Fractal Pivots and Linus Anchored VWAP Combo # 20180223 BLT modified Linus Anchored VWAP to work with Mobius Fractal Pivots # 20210427 Sleepyz modified Mobius Fractal Pivots to just R1/S1 to more mimic Linus VWAP code, which does not plot properly without refreshing the chart. Now it should plot timely, but since it uses future bars, it will plot the pivot only after the future bar requirement is met. As this worked to overcome the problem in Linus' code, I did not spend anytime to try to figure out how to fix Linus' code # ___________________________________________ # Support and Resistance Fractal Pivots # Mobius # V01.01.2011 # User Inputs input n = 5; #hint n: Length for calculations. # Internal Script Reference script LinePlot { input LineLimit = 0; input OnExpansion = yes; input data = close; input bar = 0; def ThisBar = HighestAll(bar); def cLine = if bar == ThisBar then data else Double.NaN; plot P = if ThisBar - LineLimit <= bar then HighestAll(cLine) else Double.NaN; } # Variables def o = open; def h = high; def l = low; def c = close; def bar = BarNumber(); def hh = fold i = 1 to n + 1 with p = 1 while p do h > GetValue(h, -i); def PH = if (bar > n and h == Highest(h, n) and hh) then h else Double.NaN; def ll = fold j = 1 to n + 1 with q = 1 while q do l < GetValue(l, -j); def PL = if (bar > n and l == Lowest(l, n) and ll) then l else Double.NaN; def PHBar = if !IsNaN(PH) then bar else PHBar[1]; def PLBar = if !IsNaN(PL) then bar else PLBar[1]; def PointCount = if BarNumber() == 1 then 0 else if IsNaN(c) then PointCount[1] else if !IsNaN(PH) then Max(1, PointCount[1] + 1) else if !IsNaN(PL) then Min(-1, PointCount[1] - 1) else PointCount[1]; def PHL = if !IsNaN(PH) then PH else PHL[1]; def priorPHBar = if PHL != PHL[1] then PHBar[1] else priorPHBar[1]; def PLL = if !IsNaN(PL) then PL else PLL[1]; def priorPLBar = if PLL != PLL[1] then PLBar[1] else priorPLBar[1]; def HighPivots = bar >= HighestAll(priorPHBar); def LowPivots = bar >= HighestAll(priorPLBar); def R1pivot = if PHL > 0 and PointCount == 1 then PH else Double.NaN; def S1pivot = if PLL > 0 and PointCount == -1 then PL else Double.NaN; def R1value = R1pivot; def S1value = S1pivot; # Plots input x = 1; def x1 = x + 1; input showbubbles = yes; input showlines = yes; plot R1 = if !showlines then Double.NaN else LinePlot(Linelimit = 0, data = phl, bar = PHBar); R1.SetDefaultColor(Color.ORANGE); R1.SetLineWeight(3); AddChartBubble(showbubbles and IsNaN(c[x]) and !IsNaN(c[x1]), R1, "R1", Color.RED); plot S1 = if !showlines then Double.NaN else LinePlot(LineLimit = 0, data = pll, bar = PLBar); S1.SetDefaultColor(Color.WHITE); S1.SetLineWeight(3); AddChartBubble(showbubbles and IsNaN(c[x]) and !IsNaN(c[x1]), S1, "S1", Color.GREEN); input showarrows = yes; plot R1arrow = if showarrows and R1value then high else double.nan; R1arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); R1arrow.SetLineWeight(3); R1arrow.SetDefaultColor(Color.ORANGE); plot S1arrow = if showarrows and S1value then low else double.nan; S1arrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP); S1arrow.SetLineWeight(3); S1arrow.SetDefaultColor(Color.WHITE); # End Code Support and Resistance Fractal Pivots # ______________________________ # Linus Anchored VWAP code def up = !IsNaN(S1value);#modified def dn = !IsNaN(R1value);#modified input ticks = 0.0; 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 PHV;#modified rec VH; rec PLV;#modified 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 { PHV = LocH; VH = volume; PH2 = PHV[1]; VH2 = VH[1]; } else { PHV = CompoundValue(1, LocH + PHV[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 { PLV = LocL; VL = volume; PL2 = PLV[1]; VL2 = VL[1]; } else { PLV = CompoundValue(1, LocL + PLV[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 PHV / VH; plot VwapL = if up then Double.NaN else PLV / 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.GREEN); VwapL.HideBubble(); VwapH2.SetDefaultColor(Color.DARK_RED); VwapH2.SetStyle(Curve.SHORT_DASH); VwapH2.HideBubble(); VwapL2.SetDefaultColor(Color.GREEN); VwapL2.SetStyle(Curve.SHORT_DASH); VwapL2.HideBubble(); ## END modified Linus Anchored VWAP STUDY
Hi BenTen sorry to bug ya but could you create a scan for VWAP ANCHORED _V02 where it'll scan for wherever it plots the arrows at? I think its pretty useful on a lot of stocks but a lot of the time I'd miss the move.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 different Anchored VWAP indicators for ThinkorSwim. Feel free to test them out and use any that fits your trading style.
Anchored VWAP with adjustable date and time
Code:input anchorDate = 20200422; 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);
Intraday Anchored VWAP
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);
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: https://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: https://tos.mx/s17BmB
Video Tutorial
can someone help to scan for the up and dn arrows?@thinky Most likely because these indicators require more than just a single day of data.
Hi, The Anchored VWAP with Stops. Do the Arrows come way after the move? Thank you
Hi, can this be done to plot a daily anchored VWAP starting at 6PM the night before, each day?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 different Anchored VWAP indicators for ThinkorSwim. Feel free to test them out and use any that fits your trading style.
Anchored VWAP with adjustable date and time
Code:input anchorDate = 20200422; 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);
Intraday Anchored VWAP
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);
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: https://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: https://tos.mx/s17BmB
Video Tutorial
Hi, can this be done to plot a daily anchored VWAP starting at 6PM the night before, each day?
My aim is to be able to begin the anchored VWAP at the 6PM Globex session start, and have it continue until 4 PM close the next day.
i.e. 07/01/2022 at 6PM until 07/02/2022 at 4 PM, and reset each day.
Thank you in advance for your help/guidance.
Ruby:## START STUDY ## Anchored_VWAP3 ## linus, 2014-06-28, v0.3 ## 20211117 Sleepyz modified to use a cond to anchor vwap input openingTime = 1800; input closingTime = 1600; input show = {default Cloud, Lines}; def sec1 = SecondsFromTime(openingTime); def sec2 = SecondsFromTime(closingTime); def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0); def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0); def inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0); def anchor = inRange; def ymd = GetYYYYMMDD(); def bn = BarNumber(); def c = close; def v = volume; def vw = vwap; def volumesum; def volumevwapsum; def volumevwap2sum; def price; def deviation; volumesum = if (anchor) then volumesum[1] + volume else 0; volumevwapsum = if (anchor) then volumevwapsum[1] + volume * vwap else 0; volumevwap2sum = if (anchor) then volumevwap2sum[1] + volume * Sqr(vwap) else 0; price = volumevwapsum / volumesum; deviation = Sqrt(Max(volumevwap2sum / volumesum - Sqr(price), 0)); ; plot VWAP = price; 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 );
I am using this StudyAnchored 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 different Anchored VWAP indicators for ThinkorSwim. Feel free to test them out and use any that fits your trading style.
Anchored VWAP with adjustable date and time
Code:input anchorDate = 20200422; 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);
Intraday Anchored VWAP
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);
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: https://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: https://tos.mx/s17BmB
Video Tutorial
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 different Anchored VWAP indicators for ThinkorSwim. Feel free to test them out and use any that fits your trading style.
Anchored VWAP with adjustable date and time
Code:input anchorDate = 20200422; 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);
Intraday Anchored VWAP
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);
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: https://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: https://tos.mx/s17BmB
Video Tutorial
I am using this Study
## 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.
I am using this Study, from original post, on 300 Tick Chart of /ES. Based on this study every 20 bars new VWAP should be drawn. This does not happen, and VWAP is just a continues line. The only way to update is to open "Edit Studies" "the Flask" & click on Apply, then new lines are drawn. Any one has any idea how to correct this? Below i put the STUDY & pictures of chart.
## 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.
Image, chart not updating
Image, opening Edit Studies & Apply to update
Image in updated with correct lines
If anyone know how to correct this so VWAP is drawn automatically , please post.
Thank you so much for this, this is perfect.These, input openingTime = 1800; and input closingTime = 1600; control the plotting of the VWAP
It works with no need to refresh the chart. Thank You.Try this fix I made to the above script https://usethinkscript.com/threads/anchored-vwap-indicator-for-thinkorswim.171/post-102127
Is there a study out there that will post an arrow every time the price crosses above or below one of the VWAP bands, for example when price crosses above the upper band at 1 standard deviation, if so is there a watchlist column as well, thanks
Ruby:plot vwapupper = reference VWAP().UpperBand; vwapupper.SetDefaultColor(Color.CYAN); plot uparrow = close crosses above vwapupper; uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); uparrow.SetDefaultColor(Color.CYAN); plot vwaplower = reference VWAP().LowerBand; vwaplower.SetDefaultColor(Color.MAGENTA); plot dnarrow = close crosses below vwaplower; dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); dnarrow.SetDefaultColor(Color.MAGENTA);
Ruby:def vwapupper = reference VWAP().UpperBand; def vwaplower = reference VWAP().LowerBand; def uparrow = close crosses above vwapupper; def dnarrow = close crosses below vwaplower; addlabel(1, " ", color.black); assignbackgroundColor(if uparrow then color.cyan else if dnarrow then color.magenta else color.black);
@SleepyZ Any way to make this so the arrows show up at the 1 standard deviation instead of the 2?
Here is watchlistRuby:input num_dev = 1; plot vwapupper = reference VWAP("num dev dn" = -num_dev, "num dev up" = num_dev).UpperBand; vwapupper.SetDefaultColor(Color.CYAN); plot uparrow = close crosses above vwapupper; uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); uparrow.SetDefaultColor(Color.CYAN); plot vwaplower = reference VWAP("num dev dn" = -num_dev, "num dev up" = num_dev).LowerBand; vwaplower.SetDefaultColor(Color.MAGENTA); plot dnarrow = close crosses below vwaplower; dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); dnarrow.SetDefaultColor(Color.MAGENTA);
Ruby:input num_dev = 1 def vwapupper = reference VWAP("num dev dn" = -num_dev, "num dev up" = num_dev).UpperBand; def vwaplower = reference VWAP("num dev dn" = -num_dev, "num dev up" = num_dev).LowerBand; def uparrow = close crosses above vwapupper; def dnarrow = close crosses below vwaplower; addlabel(1, " ", color.black); assignbackgroundColor(if uparrow then color.cyan else if dnarrow then color.magenta else color.black);
Without a greater understanding of what the TC2000 version is doing exactly and the logic being used, it is not possible to provide an answer,Hi everybody.
Just to clarify, this anchored vwap (atleast the first version at the top) can't be used like TC2000 where the anchoring is done in individual stocks? In this TOS version, once the date/time is adjusted, the whole thing is applied to every stock right?
Any workaround it?
Tnx!
Thanks @MerryDayWithout a greater understanding of what the TC2000 version is doing exactly and the logic being used, it is not possible to provide an answer,
Your understanding of the ToS version is correct,
Wow! What an informative post, guru that nobody asked for. You must have watched a lot of Youtube videos.I want to add something to this thread not code but a logical thread expressed in simple English. I have enough AI code to last me a lifetime of trading so I will communicate as follows Purpose of VWAP is to be on the right side of volume weighted average price no matter if long or short (reasons: keeps you on the side of the accumulation or distribution-whatever is most dominant price discovery in the time in which you are setting the VWAP). Second, you have a VWAP on TOS and on this Thread repeated in one form or another many times , that you can split into standard deviations of any length and width and duration (# of deviations down and up for a day, a week or even a month). ---Properly set up to desired specifications it should allow the individual chartist to accomplish the purpose desired by an active trader discretionary like myself - not, let me repeat, Not!, to build a black box but to build an indivualized guidance indicator to enable me to remain on the dominant side of the trade. It is already on the thread, so I will not clutter the thread with more Code: My personal philosophy has always been consistent, I am looking for an interactive real-time experience. not an abstrated MetaVerse of a cluttered Chart full of electronic signals that are jumble of noise/symbols. I suggest if the chartist keeps the monitor clean of clutter and concentrates one one best indicator on the Price Channel with one indicator for Price and and another best one indiicator for Volume, he will see price discovery unfold before his eyes: Price and volume order flow in real time. That is a Signal Price and Volume over time, not a predictor. There is no perfect predictor in my experience. You can try all kinds of Linear or non-linear signals but I tell you they are guesses not Price Discovery. Best to all. Excuse my caveman use of words to communicate in a computerized world. Best to all
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.