add anchored VWAP's to Fractal Pivots

Haidason7

New member
VIP
Is anyone able to add VWAP plots to this study pasted below; anchoring a VWAP line to each of the fractal pivots?



### OneNote Archive Name: Support Resistance Fractal Pivots _MobiusNube
## Archive Section: Support Resistance
## Suggested Tos Name: SupportResistanceFractalPivots_MobiusNube
## Archive Date: 6.18.2018

# Support and Resistance Fractal Pivots
# Mobius
# V01.01.2011
#hint: Fractal Pivots: use multiple instances of the study set with different lengths to find fractal pivots inside wider fractal ranges.

# Original S3 and R3 removed, scan plots and labels added - Nube
# Scan for [pattern] 'is equal to' 'R1'.
# 11.19.17 added Quasimodo pattern labels after seeing Q about it in the Lounge. Requisite comment about having a hunch it's not better than any other pattern - Nube
# 12.12.17 added broken uptrend/downtrend and turned off tightening label when price is above/below R2/S2

# User Inputs
input n = 5; #hint n: Length for calculations.
input labels = yes; #hint labels: pattern labels
input Bubbles = no; #hint Bubbles: at most recent S and R pivot

def h = high;
def l = low;
def c = close;
def na = Double.NaN;
def bar = BarNumber();

# 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 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 na;
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 na;
def PHBar = if !IsNaN(PH)
then bar
else PHBar[1];
def PLBar = if !IsNaN(PL)
then bar
else PLBar[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
HighPivots
then PHL
else na;
def S1pivot = if LowPivots
then PLL
else na;
def R1value = R1pivot;
def R1bar = PHbar;
def R1limit = bar - R1bar;
def R2bar = priorPHbar;
def R2limit = bar - R2bar;
def R2value = if bar == HighestAll(R2bar)
then h
else R2value[1];
def S1value = S1pivot;
def S1bar = PLbar;
def S1limit = bar - S1bar;
def S2bAR = PriorPLBar;
def S2limit = bar - S2bar;
def S2value = if bar == HighestAll(S2bar)
then l
else S2value[1];
# Plots
plot R1 = LinePlot(Linelimit = R1Limit, data = R1value, bar = R1bar);
plot R2 = LinePlot(LineLimit = R2limit, data = R2value, bar = R2bar).P;
plot S1 = LinePlot(LineLimit = S1limit, data = S1value, bar = S1bar).P;
plot S2 = LinePlot(LineLimit = S2limit, data = S2value, bar = S2bar).P;

def minR12 = Min(R1, R2);
def maxR12 = Max(R1, R2);
def minS12 = Min(S1, S2);
def maxS12 = Max(S1, S2);

R1.HideBubble();
R1.HideTitle();
R1.SetStyle(Curve.Long_Dash);
R1.AssignValueColor(if R1 == minR12
then CreateColor(105,55,55)
else CreateColor(140,55,55));
R2.HideBubble();
R2.HideTitle();
R2.SetStyle(Curve.Long_Dash);
R2.AssignValueColor(if R2 == minR12
then CreateColor(105,55,55)
else CreateColor(140,55,55));
addChartBubble(if Bubbles
&& Bar == HighestAll(PHBar)
then PHBar
else na, R1,
if R1 == minR12
then "R1"
else "R2",
GetColor(5));

S1.HideBubble();
S1.HideTitle();
S1.SetStyle(Curve.Long_Dash);
S1.AssignValueColor(if S1 == minS12
then CreateColor(55,115,55)
else CreateColor(55,85,55));
S2.HideBubble();
S2.HideTitle();
S2.SetStyle(Curve.Long_Dash);
S2.AssignValueColor(if S2 == minS12
then CreateColor(55,115,55)
else CreateColor(55,85,55));
addChartBubble(if Bubbles
&& Bar == HighestAll(PLBar)
then PLBar
else na, S1,
if S1 == MaxS12
then "S1"
else "S2",
CreateColor(50,175,105),0);

# scan plots for up/down trend and broadening, tightening and Quasimodo
# Remember: Scan for pattern being equal to 1
# Quasimodo pattern here is being defined as a broadening pattern that pivots opposite the primary trend.

def Trend = InertiaAll(c);
def TrendUp = trend > trend[1];
def TrendDn = trend < trend[1];
def maxR12bar = Max(R1bar, R2bar);
def maxS12bar = Max(S1bar, S2bar);
def upt = sum(h >= h[1] ,2) == 2;
def dnt = sum(h < h[1] ,2) == 2;
def upb = sum(l > l[1] ,2) == 2;
def dnb = sum(l <= l[1] ,2) == 2;

def quasiDNpvt = if upt && dnt[-2]
then 1
else na;
def quasiDNbar = if !IsNaN(quasiDNpvt)
then bar
else quasidnbar[1];
def quasiDNval = if bar == quasiDNbar
then h
else quasiDNval[1];
def quasiUPpvt = if dnb && upb[-2]
then 1
else na;
def quasiUPbar = if !IsNaN(quasiUPpvt)
then bar
else quasiUPbar[1];
def quasiUPval = if bar == quasiUPbar
then l
else quasiUpval[1];

def Broaden = if(S1 == minS12
&& R2 == minR12,1,0);
def QuasiUp = if(Broaden == 1 && TrendDn
&& quasiUPbar > Max(maxS12bar, maxR12bar)
&& quasiUPbar > quasiDNbar
&& between(quasiUPval, S1Value, S2Value),
1,0);
def QuasiDn = if(Broaden == 1 && TrendUp
&& quasiDNbar > Max(maxS12bar, maxR12bar)
&& quasiDNbar > quasiUPbar
&& between(quasiDNval, R1Value, R2Value), 1,0);

plot DownTrend = if(S1 == minS12 && R2 == maxR12
&& c < R2value,1,0);
plot UpTrend = if(S1 == maxS12 && R2 == minR12
&& c > S2value,1,0);
plot BrokenDownTrend = if(S1 == minS12 && R2 == maxR12
&& c > R2value,1,0);
plot BrokenUpTrend = if(S1 == maxS12 && R2 == minR12
&& c < S2value,1,0);
plot Tightening = if(S1 == maxS12 && R2 == maxR12
&& c < R2value && c > S2value,1,0);
plot Broadening = if(Broaden == 1 &&
QuasiUp == 0 &&
QuasiDn == 0,1,0);
plot Quasimodo = if(QuasiUp == 1 or
QuasiDn == 1,1,0);

DownTrend.Hide();
UpTrend.Hide();
Broadening.Hide();
Tightening.Hide();
Quasimodo.Hide();
BrokenDownTrend.Hide();
BrokenUpTrend.Hide();

addlabel(if(labels && DownTrend == 1,1,0), "Down Trend", Color.Light_Red);
addlabel(if(labels && Uptrend == 1,1,0), "Up Trend", Color.Green);
addlabel(if(labels && Broadening == 1,1,0), "Broadening", GetColor(8));
addlabel(if(labels && Tightening == 1,1,0), "Tightening", GetColor(3));
addlabel(if(labels && Quasimodo == 1,1,0), "Quasimodo", Color.Orange);
addlabel(if(labels && BrokenDownTrend == 1,1,0), "Broken Down Trend", CreateColor(185,40,40));
addlabel(if(labels && BrokenUptrend == 1,1,0), "Broken Up Trend", CreateColor(50,185,80));
 
Is anyone able to add VWAP plots to this study pasted below; anchoring a VWAP line to each of the fractal pivots?



### OneNote Archive Name: Support Resistance Fractal Pivots _MobiusNube
## Archive Section: Support Resistance
## Suggested Tos Name: SupportResistanceFractalPivots_MobiusNube
## Archive Date: 6.18.2018

# Support and Resistance Fractal Pivots
# Mobius
# V01.01.2011
#hint: Fractal Pivots: use multiple instances of the study set with different lengths to find fractal pivots inside wider fractal ranges.

# Original S3 and R3 removed, scan plots and labels added - Nube
# Scan for [pattern] 'is equal to' 'R1'.
# 11.19.17 added Quasimodo pattern labels after seeing Q about it in the Lounge. Requisite comment about having a hunch it's not better than any other pattern - Nube
# 12.12.17 added broken uptrend/downtrend and turned off tightening label when price is above/below R2/S2

# User Inputs
input n = 5; #hint n: Length for calculations.
input labels = yes; #hint labels: pattern labels
input Bubbles = no; #hint Bubbles: at most recent S and R pivot

def h = high;
def l = low;
def c = close;
def na = Double.NaN;
def bar = BarNumber();

# 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 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 na;
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 na;
def PHBar = if !IsNaN(PH)
then bar
else PHBar[1];
def PLBar = if !IsNaN(PL)
then bar
else PLBar[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
HighPivots
then PHL
else na;
def S1pivot = if LowPivots
then PLL
else na;
def R1value = R1pivot;
def R1bar = PHbar;
def R1limit = bar - R1bar;
def R2bar = priorPHbar;
def R2limit = bar - R2bar;
def R2value = if bar == HighestAll(R2bar)
then h
else R2value[1];
def S1value = S1pivot;
def S1bar = PLbar;
def S1limit = bar - S1bar;
def S2bAR = PriorPLBar;
def S2limit = bar - S2bar;
def S2value = if bar == HighestAll(S2bar)
then l
else S2value[1];
# Plots
plot R1 = LinePlot(Linelimit = R1Limit, data = R1value, bar = R1bar);
plot R2 = LinePlot(LineLimit = R2limit, data = R2value, bar = R2bar).P;
plot S1 = LinePlot(LineLimit = S1limit, data = S1value, bar = S1bar).P;
plot S2 = LinePlot(LineLimit = S2limit, data = S2value, bar = S2bar).P;

def minR12 = Min(R1, R2);
def maxR12 = Max(R1, R2);
def minS12 = Min(S1, S2);
def maxS12 = Max(S1, S2);

R1.HideBubble();
R1.HideTitle();
R1.SetStyle(Curve.Long_Dash);
R1.AssignValueColor(if R1 == minR12
then CreateColor(105,55,55)
else CreateColor(140,55,55));
R2.HideBubble();
R2.HideTitle();
R2.SetStyle(Curve.Long_Dash);
R2.AssignValueColor(if R2 == minR12
then CreateColor(105,55,55)
else CreateColor(140,55,55));
addChartBubble(if Bubbles
&& Bar == HighestAll(PHBar)
then PHBar
else na, R1,
if R1 == minR12
then "R1"
else "R2",
GetColor(5));

S1.HideBubble();
S1.HideTitle();
S1.SetStyle(Curve.Long_Dash);
S1.AssignValueColor(if S1 == minS12
then CreateColor(55,115,55)
else CreateColor(55,85,55));
S2.HideBubble();
S2.HideTitle();
S2.SetStyle(Curve.Long_Dash);
S2.AssignValueColor(if S2 == minS12
then CreateColor(55,115,55)
else CreateColor(55,85,55));
addChartBubble(if Bubbles
&& Bar == HighestAll(PLBar)
then PLBar
else na, S1,
if S1 == MaxS12
then "S1"
else "S2",
CreateColor(50,175,105),0);

# scan plots for up/down trend and broadening, tightening and Quasimodo
# Remember: Scan for pattern being equal to 1
# Quasimodo pattern here is being defined as a broadening pattern that pivots opposite the primary trend.

def Trend = InertiaAll(c);
def TrendUp = trend > trend[1];
def TrendDn = trend < trend[1];
def maxR12bar = Max(R1bar, R2bar);
def maxS12bar = Max(S1bar, S2bar);
def upt = sum(h >= h[1] ,2) == 2;
def dnt = sum(h < h[1] ,2) == 2;
def upb = sum(l > l[1] ,2) == 2;
def dnb = sum(l <= l[1] ,2) == 2;

def quasiDNpvt = if upt && dnt[-2]
then 1
else na;
def quasiDNbar = if !IsNaN(quasiDNpvt)
then bar
else quasidnbar[1];
def quasiDNval = if bar == quasiDNbar
then h
else quasiDNval[1];
def quasiUPpvt = if dnb && upb[-2]
then 1
else na;
def quasiUPbar = if !IsNaN(quasiUPpvt)
then bar
else quasiUPbar[1];
def quasiUPval = if bar == quasiUPbar
then l
else quasiUpval[1];

def Broaden = if(S1 == minS12
&& R2 == minR12,1,0);
def QuasiUp = if(Broaden == 1 && TrendDn
&& quasiUPbar > Max(maxS12bar, maxR12bar)
&& quasiUPbar > quasiDNbar
&& between(quasiUPval, S1Value, S2Value),
1,0);
def QuasiDn = if(Broaden == 1 && TrendUp
&& quasiDNbar > Max(maxS12bar, maxR12bar)
&& quasiDNbar > quasiUPbar
&& between(quasiDNval, R1Value, R2Value), 1,0);

plot DownTrend = if(S1 == minS12 && R2 == maxR12
&& c < R2value,1,0);
plot UpTrend = if(S1 == maxS12 && R2 == minR12
&& c > S2value,1,0);
plot BrokenDownTrend = if(S1 == minS12 && R2 == maxR12
&& c > R2value,1,0);
plot BrokenUpTrend = if(S1 == maxS12 && R2 == minR12
&& c < S2value,1,0);
plot Tightening = if(S1 == maxS12 && R2 == maxR12
&& c < R2value && c > S2value,1,0);
plot Broadening = if(Broaden == 1 &&
QuasiUp == 0 &&
QuasiDn == 0,1,0);
plot Quasimodo = if(QuasiUp == 1 or
QuasiDn == 1,1,0);

DownTrend.Hide();
UpTrend.Hide();
Broadening.Hide();
Tightening.Hide();
Quasimodo.Hide();
BrokenDownTrend.Hide();
BrokenUpTrend.Hide();

addlabel(if(labels && DownTrend == 1,1,0), "Down Trend", Color.Light_Red);
addlabel(if(labels && Uptrend == 1,1,0), "Up Trend", Color.Green);
addlabel(if(labels && Broadening == 1,1,0), "Broadening", GetColor(8));
addlabel(if(labels && Tightening == 1,1,0), "Tightening", GetColor(3));
addlabel(if(labels && Quasimodo == 1,1,0), "Quasimodo", Color.Orange);
addlabel(if(labels && BrokenDownTrend == 1,1,0), "Broken Down Trend", CreateColor(185,40,40));
addlabel(if(labels && BrokenUptrend == 1,1,0), "Broken Up Trend", CreateColor(50,185,80));

I did this quit awhile ago. See if it works how you want https://usethinkscript.com/threads/anchored-vwap-indicator-for-thinkorswim.171/post-62228
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
467 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top