#Example Fractal Pivots Anchored VWAP
#20170817 BLT using Fractal Pivot study shared in TSL, Linus Anchored VWAP
#Fractal Pivots are plotted to hopefully create a zigzag pattern (pointcount tries to do this)
#Forming Pivots are plotted when the left side criteria is met and 1 future candle. A bar count is then captured in a label and/or chartbubble. Yellow is unconfirmed and Green/Red is confirmed. The next forming fractal will also plot a bubble (P-?) and anchored VWAP lines (these will change if the fractal goes unconfirmed)
#This studies anchored VWAP dynamically plots the VWAP vs the current version of Linus' original study that does not (only updates when the chart is refreshed, either through changing symbols or aggregations, for example)
def h = high;
def l = low;
def c = close;
def o = open;
def v = volume;
# Simple Fractal Recon
input length = 5;
def HH1 = h >= Highest(h, length) and h >= Highest(h, length)[-length];
def High1 = if HH1 then h else Double.NaN;
def LL1 = l <= Lowest(l, length) and l <= Lowest(l, length)[-length];
def Low1 = if LL1 then l else Double.NaN;
def PointCount = if BarNumber() == 1 then 0 else
if IsNaN(c) then PointCount[1] else
if !IsNaN(High1) then Max(1, PointCount[1] + 1) else
if !IsNaN(Low1) then Min(-1, PointCount[1] - 1)
else PointCount[1];
input showhorizontals = yes;
def RangeHI = if !IsNaN(High1) and PointCount == 1
then h else RangeHI[1];
plot Rhi = if !showhorizontals then Double.NaN else RangeHI;
Rhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Rhi.SetLineWeight(1);
Rhi.SetDefaultColor(Color.RED);
def RangeLO = if !IsNaN(Low1) and PointCount == -1
then l else RangeLO[1];
plot Rlo = if !showhorizontals then Double.NaN else RangeLO;
Rlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Rlo.SetLineWeight(1);
Rlo.SetDefaultColor(Color.GREEN);
#Harndog
input HHLLlabels = yes;
def rh1 = if !IsNaN(rhi) then rhi else rh1[1];
rec rh2 = if rh1 != rh1[1] then rh1[1] else rh2[1];
AddLabel(HHLLlabels, if rh1 > rh2
then "Higher Highs"
else "Lower Highs",
if rh1 > rh2
then Color.GREEN
else Color.RED);
def rl1 = if !IsNaN(rlo) then rlo else rl1[1];
rec rl2 = if rl1 != rl1[1] then rl1[1] else rl2[1];
addlabel(HHLLlabels, if rl1 > rl2
then "Higher Lows"
else "Lower Lows",
if rl1 > rl2
then color.green
else color.red);
input HHLLBubbles = yes;
input HHLLbubblemover = 6;
def hb = HHLLbubblemover;
def hb1 = hb + 1;
AddChartBubble(!IsNaN(c[hb1]) and IsNaN(c[hb]) and HHLLBubbles , c[hb1], if rl1[hb1]>rl2[hb1] then "HL" else "LL" , if rl1[hb1]>rl2[hb1] then color.green else Color.RED, yes);
AddChartBubble(!IsNaN(c[hb1]) and IsNaN(c[hb]) and HHLLBubbles , c[hb1], if rh1[hb1]>rh2[hb1] then "HH" else "LH" , if rh1[hb1]>rh2[hb1] then color.green else Color.RED, yes);
#ZigZags
def zHI;
def zLO;
zHI = if !IsNaN(High1) and PointCount == 1 then h else Double.NaN;
zLO = if !IsNaN(Low1) and PointCount == -1 then l else Double.NaN;
plot hilowline = if !IsNaN(zHI) then zHI else zLO;
hilowline.EnableApproximation();