I have this indicator and am wanting to extend the lines to the right. Is there anyone that can add something to the code to do this? TY
https://usethinkscript.com/threads/moxie-for-thinkorswim.3109/page-8#post-130140
https://usethinkscript.com/threads/moxie-for-thinkorswim.3109/page-8#post-130140
Code:
#Swing_HL_Pivots_Stats_v1
input pivotlength = 7;
input showhorizontals = yes;
input show_zigzag_line = no;
input HHLLlabels = no;
input showbubbles = no;
input showHHLL_in_bubbles = no;
input showprice_in_bubbles = no;
input showpercentpricechange_in_bubbles = no;
input showbarcount_in_bubbles = no;
input showdollarchange_in_bubbles = no;
def h = high;
def l = low;
def c = close;
def o = open;
def v = volume;
# Simple Swing Pivots
def HH1 = h >= Highest(h, pivotlength) and h >= Highest(h, pivotlength)[-pivotlength];
def High1 = if HH1 then h else Double.NaN;
def LL1 = l <= Lowest(l, pivotlength) and l <= Lowest(l, pivotlength)[-pivotlength];
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];
#Horizontal Lines at Pivots1
def RangeHI = if !IsNaN(High1) and PointCount == 1
then h else RangeHI[1];
plot Rhi = RangeHI;
Rhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Rhi.SetLineWeight(1);
Rhi.SetDefaultColor(Color.CYAN);
Rhi.SetHiding(!showhorizontals);
def RangeLO = if !IsNaN(Low1) and PointCount == -1
then l else RangeLO[1];
plot Rlo = RangeLO;
Rlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Rlo.SetLineWeight(1);
Rlo.SetDefaultColor(Color.MAGENTA);
Rlo.SetHiding(!showhorizontals);
#HH/LH & LH/LL1 Labels
def rh1 = if !IsNaN(Rhi) then Rhi else rh1[1];
def 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];
def 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);
#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;
def bn = BarNumber();
def lastzhi = if !IsNaN(zHI) then bn else lastzhi[1];
def lastzlo = if !IsNaN(zLO) then bn else lastzlo[1];
#ZigZag Line
plot hilowline = if !IsNaN(zHI) then zHI else zLO;
hilowline.EnableApproximation();
hilowline.SetLineWeight(3);
hilowline.SetDefaultColor(Color.GRAY);
hilowline.SetHiding(!show_zigzag_line);
def last = if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN;
def lastbar = if BarNumber() == HighestAll(last) then 1 else 0;
def lastvalue = if lastbar then close else Double.NaN;
plot hilowline1 = if bn < Max(lastzhi, lastzlo)
then Double.NaN
else if lastzlo > lastzhi and !IsNaN(zLO)
then zLO
else if lastzlo < lastzhi and !IsNaN(zHI)
then zHI else lastvalue;
hilowline1.EnableApproximation();
hilowline1.SetLineWeight(3);
hilowline1.SetDefaultColor(Color.GRAY);
hilowline1.SetHiding(!show_zigzag_line);
def xxhigh = if rh1 == high then high else xxhigh[1];
def xxlow = if rl1 == low then low else xxlow[1];
#Percent Price Change between ZigZags
def chghigh = (rh1 - xxlow[1]) / xxlow[1] * 100;
def chglow = (rl1 - xxhigh[1]) / xxhigh[1] * 100;
#Bar Count between ZigZags
def barcountchange = AbsValue(lastzhi - lastzlo);
AddChartBubble(showbubbles and !IsNaN(High1) and PointCount == 1, high,
(if showHHLL_in_bubbles then
(if rh1 > rh2 then "HH\n" else "LH\n")
else "") +
(if showprice_in_bubbles then
AsText(high) + "\n" else "") +
(if showpercentpricechange_in_bubbles
then Round(chghigh) + "%\n" else "") +
(if showbarcount_in_bubbles then
barcountchange + "\n" else "") +
(if showdollarchange_in_bubbles then
"" + AsDollars(rh1 - xxlow[1]) else "") ,
if xxhigh > xxhigh[1] then Color.GREEN else Color.RED, no);
#Color.GRAY,
AddChartBubble(showbubbles and !IsNaN(Low1) and PointCount == -1, low,
(if showHHLL_in_bubbles then
(if rl1 > rl2 then "HL\n" else "LL\n")
else "") +
(if showprice_in_bubbles then
AsText(low) + "\n" else "") +
(if showpercentpricechange_in_bubbles
then Round(chglow) + "%\n" else "") +
(if showbarcount_in_bubbles then
barcountchange + "\n" else "") +
(if showdollarchange_in_bubbles then
"" + AsDollars(rl1 - xxhigh[1]) else ""),
if xxlow > xxlow[1] then Color.GREEN else Color.RED, no);
#Color.GRAY,
#Price_only_at_Swings
input show_price_Only_at_swings = yes;
plot Rhi_price = if !IsNaN(High1) and PointCount == 1
then h else Double.NaN;
Rhi_price.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
Rhi_price.SetHiding(!show_price_Only_at_swings);
plot Rlo_price = if !IsNaN(Low1) and PointCount == -1
then l else Double.NaN;
Rlo_price.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
Rlo_price.SetHiding(!show_price_Only_at_swings);
Last edited by a moderator: