Repaints Moxie for ThinkorSwim

Repaints
Here is a swing high/low pivot indicator with the barcount between changes as well as other options:
Hi I noticed that when you switch "showhorizontals" to NO there is an error. You are only left with LH and LL's. The HH and HL disappear off of the chart. I took a look at the #Horizontal Lines at Pivots1 code and could not find an error. Thank you.

 

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

@Charlotte said I am looking for the code I downloaded that has the Zig Zag high low indicator with just the lines not extras such as arrows and bubbles.

The standard TOS zigzaghighlow indicator does not have any extras.

See the red circled area in the image below.

Screenshot 2023-06-04 112701.png
 
Last edited:
Hi I noticed that when you switch "showhorizontals" to NO there is an error. You are only left with LH and LL's. The HH and HL disappear off of the chart. I took a look at the #Horizontal Lines at Pivots1 code and could not find an error. Thank you.


Thanks, this is fixed below and the post above. Instead of "double.nan" for "NO", it is now "sethiding". This allows the rest of the code to use the horizontal line plots even though they are hidden.

Code:
#Swing_HL_Pivots_Stats

input pivotlength = 5;
input showhorizontals = yes;
input HHLLlabels = yes;
input showbubbles = yes;
input showHHLL_in_bubbles = yes;
input showprice_in_bubbles = yes;
input showpercentpricechange_in_bubbles = yes;
input showbarcount_in_bubbles = yes;

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.RED);
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.GREEN);
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.WHITE);

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.WHITE);

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 "\n") +
(if showprice_in_bubbles then
AsText(high) + "\n" else "\n") +
(if showpercentpricechange_in_bubbles
then Round(chghigh) + "%\n" else "\n") +
if showbarcount_in_bubbles then
"" + barcountchange else "",
if xxhigh > xxhigh[1] then Color.GREEN else Color.RED);

AddChartBubble(showbubbles and !IsNaN(Low1) and PointCount == -1, low,
(if showHHLL_in_bubbles then
(if rl1 > rl2 then "HL\n" else "LL\n")
else "\n") +
(if showprice_in_bubbles then
AsText(low) + "\n" else "\n") +
(if showpercentpricechange_in_bubbles
then Round(chglow) + "%\n" else "\n") +
if showbarcount_in_bubbles then
"" + barcountchange else "",
if xxlow > xxlow[1] then Color.GREEN else Color.RED, no);
 
Is there a way to scan for the first green candle after a cyan using this code? I keep getting a error when trying to scan in tos

# Swing High and Swing Low
# tomsk
# 11.18.2019
# As requested by chillc15 I have modified @RobertPayne code to include SwingHigh
# points which are now plotted in CYAN with the swing high points painted in PINK.
# So now you have both swing high and low on your charts
# +------------------------------------------------------------+
# | Example: How to extend levels to the right of the chart |
# | Robert Payne |
# | https://funwiththinkscript.com |
# +------------------------------------------------------------+
# SWING LOW
# define swing low points
input length = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
# identify the very last swing low point
def lowPointOneBarNumber = HighestAll(if swingLow then bn else 0);
def lowPointOneValue = if bn == lowPointOneBarNumber then low else lowPointOneValue[1];
plot low1 = if bn < lowPointOneBarNumber then Double.NaN else lowPointOneValue;
low1.SetDefaultColor(Color.LIGHT_RED);
# identify the 2nd to last swing low point
def lowPointTwoBarNumber = HighestAll(if swingLow and bn < lowPointOneBarNumber then bn else 0);
def lowPointTwoValue = if bn == lowPointTwoBarNumber then low else lowPointTwoValue[1];
plot low2 = if bn < lowPointTwoBarNumber then Double.NaN else lowPointTwoValue;
low2.SetDefaultColor(Color.Light_RED);
# just keep doing ths for as many lines as you want to add to the chart
# identify then 3rd to last swingHigh point low
def lowPointThreeBarNumber = HighestAll(if swingLow and bn < lowPointTwoBarNumber then bn else 0);
def lowPointThreeValue = if bn == lowPointThreeBarNumber then low else lowPointThreeValue[1];
plot low3 = if bn < lowPointThreeBarNumber then Double.NaN else lowPointThreeValue;
low3.SetDefaultColor(Color.Light_RED);
# identify then 4th to last swingHigh point low
def lowPointFourBarNumber = HighestAll(if swingLow and bn < lowPointThreeBarNumber then bn else 0);
def lowPointFourValue = if bn == lowPointFourBarNumber then low else lowPointFourValue[1];
plot low4 = if bn < lowPointFourBarNumber then Double.NaN else lowPointFourValue;
low4.SetDefaultColor(Color.Light_RED);
# identify then 5th to last swingHigh point low
def lowPointFiveBarNumber = HighestAll(if swingLow and bn < lowPointFourBarNumber then bn else 0);
def lowPointFiveValue = if bn == lowPointFiveBarNumber then low else lowPointFiveValue[1];
plot low5 = if bn < lowPointFiveBarNumber then Double.NaN else lowPointFiveValue;
low5.SetDefaultColor(Color.Light_RED);
# identify then 6th to last swingHigh point low
def lowPointSixBarNumber = HighestAll(if swingLow and bn < lowPointFiveBarNumber then bn else 0);
def lowPointSixValue = if bn == lowPointSixBarNumber then low else lowPointSixValue[1];
plot low6 = if bn < lowPointSixBarNumber then Double.NaN else lowPointSixValue;
low6.SetDefaultColor(Color.Light_RED);
# identify then 7th to last swingHigh point low
def lowPointSevenBarNumber = HighestAll(if swingLow and bn < lowPointSixBarNumber then bn else 0);
def lowPointSevenValue = if bn == lowPointSevenBarNumber then low else lowPointSevenValue[1];
plot low7 = if bn < lowPointSevenBarNumber then Double.NaN else lowPointSevenValue;
low7.SetDefaultColor(Color.Light_RED);
# identify then 8th to last swingHigh point low
def lowPointEightBarNumber = HighestAll(if swingLow and bn < lowPointSevenBarNumber then bn else 0);
def lowPointEightValue = if bn == lowPointEightBarNumber then low else lowPointEightValue[1];
plot low8 = if bn < lowPointEightBarNumber then Double.NaN else lowPointEightValue;
low8.SetDefaultColor(Color.Light_RED);
# identify then 9th to last swingHigh point low
def lowPointNineBarNumber = HighestAll(if swingLow and bn < lowPointEightBarNumber then bn else 0);
def lowPointNineValue = if bn == lowPointNineBarNumber then low else lowPointNineValue[1];
plot low9 = if bn < lowPointNineBarNumber then Double.NaN else lowPointNineValue;
low9.SetDefaultColor(Color.Light_RED);
# identify then 10th to last swingHigh point low
def lowPointTenBarNumber = HighestAll(if swingLow and bn < lowPointNineBarNumber then bn else 0);
def lowPointTenValue = if bn == lowPointTenBarNumber then low else lowPointTenValue[1];
plot low10 = if bn < lowPointTenBarNumber then Double.NaN else lowPointTenValue;
low10.SetDefaultColor(Color.Light_RED);


# SWING HIGH
# define swing high points
def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);
# identify the very last swing high point
def highPointOneBarNumber = HighestAll(if swingHigh then bn else 0);
def highPointOneValue = if bn == highPointOneBarNumber then high else highPointOneValue[1];
plot high1 = if bn < highPointOneBarNumber then Double.NaN else highPointOneValue;
high1.SetDefaultColor(Color.CYAN);
# identify the 2nd to last swing high point
def highPointTwoBarNumber = HighestAll(if swingHigh and bn < highPointOneBarNumber then bn else 0);
def highPointTwoValue = if bn == highPointTwoBarNumber then high else highPointTwoValue[1];
plot high2 = if bn < highPointTwoBarNumber then Double.NaN else highPointTwoValue;
high2.SetDefaultColor(Color.CYAN);
# just keep doing ths for as many lines as you want to add to the chart
def highPointThreeBarNumber = HighestAll(if swingHigh and bn < highPointTwoBarNumber then bn else 0);
def highPointThreeValue = if bn == highPointThreeBarNumber then high else highPointThreeValue[1];
plot high3 = if bn < highPointThreeBarNumber then Double.NaN else highPointThreeValue;
high3.SetDefaultColor(Color.CYAN);
def highPointFourBarNumber = HighestAll(if swingHigh and bn < highPointThreeBarNumber then bn else 0);
def highPointFourValue = if bn == highPointFourBarNumber then high else highPointFourValue[1];
plot high4 = if bn < highPointFourBarNumber then Double.NaN else highPointFourValue;
high4.SetDefaultColor(Color.CYAN);
def highPointFiveBarNumber = HighestAll(if swingHigh and bn < highPointFourBarNumber then bn else 0);
def highPointFiveValue = if bn == highPointFiveBarNumber then high else highPointFiveValue[1];
plot high5 = if bn < highPointFiveBarNumber then Double.NaN else highPointFiveValue;
high5.SetDefaultColor(Color.CYAN);
def highPointSixBarNumber = HighestAll(if swingHigh and bn < highPointFiveBarNumber then bn else 0);
def highPointSixValue = if bn == highPointSixBarNumber then high else highPointSixValue[1];
plot high6 = if bn < highPointsixBarNumber then Double.NaN else highPointsixValue;
high6.SetDefaultColor(Color.CYAN);
def highPointSevenBarNumber = HighestAll(if swingHigh and bn < highPointSixBarNumber then bn else 0);
def highPointSevenValue = if bn == highPointSevenBarNumber then high else highPointSevenValue[1];
plot high7 = if bn < highPointSevenBarNumber then Double.NaN else highPointSevenValue;
high7.SetDefaultColor(Color.CYAN);
def highPointEightBarNumber = HighestAll(if swingHigh and bn < highPointSevenBarNumber then bn else 0);
def highPointEightValue = if bn == highPointEightBarNumber then high else highPointEightValue[1];
plot high8 = if bn < highPointEightBarNumber then Double.NaN else highPointEightValue;
high4.SetDefaultColor(Color.CYAN);
def highPointNineBarNumber = HighestAll(if swingHigh and bn < highPointEightBarNumber then bn else 0);
def highPointNineValue = if bn == highPointNineBarNumber then high else highPointNineValue[1];
plot high9 = if bn < highPointNineBarNumber then Double.NaN else highPointNineValue;
high4.SetDefaultColor(Color.CYAN);
def highPointTenBarNumber = HighestAll(if swingHigh and bn < highPointNineBarNumber then bn else 0);
def highPointTenValue = if bn == highPointTenBarNumber then high else highPointTenValue[1];
plot high10 = if bn < highPointTenBarNumber then Double.NaN else highPointTenValue;
high4.SetDefaultColor(Color.CYAN);

# ADJUST CANDLE COLORS
# change candle colors just to make it easier to see what we are working with
AssignPriceColor(if swingLow then Color.cyan else if swingHigh then Color.mageNTA else Color.current);
# End Swing High and Swing Low
plot HighArrow = swingHigh;
HighArrow.SetLineWeight(5);
HighArrow.SetDefaultColor(Color.RED);
HighArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot LowArrow = swingLow;
LowArrow.SetLineWeight(5);
LowArrow.SetDefaultColor(Color.GREEN);
LowArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
 
Is there a way to scan for the first green candle after a cyan using this code? I keep getting a error when trying to scan in tos

# Swing High and Swing Low
# tomsk
# 11.18.2019
# As requested by chillc15 I have modified @RobertPayne code to include SwingHigh
# points which are now plotted in CYAN with the swing high points painted in PINK.
# So now you have both swing high and low on your charts
# +------------------------------------------------------------+
# | Example: How to extend levels to the right of the chart |
# | Robert Payne |
# | https://funwiththinkscript.com |
# +------------------------------------------------------------+
# SWING LOW
# define swing low points
input length = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
# identify the very last swing low point
def lowPointOneBarNumber = HighestAll(if swingLow then bn else 0);
def lowPointOneValue = if bn == lowPointOneBarNumber then low else lowPointOneValue[1];
plot low1 = if bn < lowPointOneBarNumber then Double.NaN else lowPointOneValue;
low1.SetDefaultColor(Color.LIGHT_RED);
# identify the 2nd to last swing low point
def lowPointTwoBarNumber = HighestAll(if swingLow and bn < lowPointOneBarNumber then bn else 0);
def lowPointTwoValue = if bn == lowPointTwoBarNumber then low else lowPointTwoValue[1];
plot low2 = if bn < lowPointTwoBarNumber then Double.NaN else lowPointTwoValue;
low2.SetDefaultColor(Color.Light_RED);
# just keep doing ths for as many lines as you want to add to the chart
# identify then 3rd to last swingHigh point low
def lowPointThreeBarNumber = HighestAll(if swingLow and bn < lowPointTwoBarNumber then bn else 0);
def lowPointThreeValue = if bn == lowPointThreeBarNumber then low else lowPointThreeValue[1];
plot low3 = if bn < lowPointThreeBarNumber then Double.NaN else lowPointThreeValue;
low3.SetDefaultColor(Color.Light_RED);
# identify then 4th to last swingHigh point low
def lowPointFourBarNumber = HighestAll(if swingLow and bn < lowPointThreeBarNumber then bn else 0);
def lowPointFourValue = if bn == lowPointFourBarNumber then low else lowPointFourValue[1];
plot low4 = if bn < lowPointFourBarNumber then Double.NaN else lowPointFourValue;
low4.SetDefaultColor(Color.Light_RED);
# identify then 5th to last swingHigh point low
def lowPointFiveBarNumber = HighestAll(if swingLow and bn < lowPointFourBarNumber then bn else 0);
def lowPointFiveValue = if bn == lowPointFiveBarNumber then low else lowPointFiveValue[1];
plot low5 = if bn < lowPointFiveBarNumber then Double.NaN else lowPointFiveValue;
low5.SetDefaultColor(Color.Light_RED);
# identify then 6th to last swingHigh point low
def lowPointSixBarNumber = HighestAll(if swingLow and bn < lowPointFiveBarNumber then bn else 0);
def lowPointSixValue = if bn == lowPointSixBarNumber then low else lowPointSixValue[1];
plot low6 = if bn < lowPointSixBarNumber then Double.NaN else lowPointSixValue;
low6.SetDefaultColor(Color.Light_RED);
# identify then 7th to last swingHigh point low
def lowPointSevenBarNumber = HighestAll(if swingLow and bn < lowPointSixBarNumber then bn else 0);
def lowPointSevenValue = if bn == lowPointSevenBarNumber then low else lowPointSevenValue[1];
plot low7 = if bn < lowPointSevenBarNumber then Double.NaN else lowPointSevenValue;
low7.SetDefaultColor(Color.Light_RED);
# identify then 8th to last swingHigh point low
def lowPointEightBarNumber = HighestAll(if swingLow and bn < lowPointSevenBarNumber then bn else 0);
def lowPointEightValue = if bn == lowPointEightBarNumber then low else lowPointEightValue[1];
plot low8 = if bn < lowPointEightBarNumber then Double.NaN else lowPointEightValue;
low8.SetDefaultColor(Color.Light_RED);
# identify then 9th to last swingHigh point low
def lowPointNineBarNumber = HighestAll(if swingLow and bn < lowPointEightBarNumber then bn else 0);
def lowPointNineValue = if bn == lowPointNineBarNumber then low else lowPointNineValue[1];
plot low9 = if bn < lowPointNineBarNumber then Double.NaN else lowPointNineValue;
low9.SetDefaultColor(Color.Light_RED);
# identify then 10th to last swingHigh point low
def lowPointTenBarNumber = HighestAll(if swingLow and bn < lowPointNineBarNumber then bn else 0);
def lowPointTenValue = if bn == lowPointTenBarNumber then low else lowPointTenValue[1];
plot low10 = if bn < lowPointTenBarNumber then Double.NaN else lowPointTenValue;
low10.SetDefaultColor(Color.Light_RED);


# SWING HIGH
# define swing high points
def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);
# identify the very last swing high point
def highPointOneBarNumber = HighestAll(if swingHigh then bn else 0);
def highPointOneValue = if bn == highPointOneBarNumber then high else highPointOneValue[1];
plot high1 = if bn < highPointOneBarNumber then Double.NaN else highPointOneValue;
high1.SetDefaultColor(Color.CYAN);
# identify the 2nd to last swing high point
def highPointTwoBarNumber = HighestAll(if swingHigh and bn < highPointOneBarNumber then bn else 0);
def highPointTwoValue = if bn == highPointTwoBarNumber then high else highPointTwoValue[1];
plot high2 = if bn < highPointTwoBarNumber then Double.NaN else highPointTwoValue;
high2.SetDefaultColor(Color.CYAN);
# just keep doing ths for as many lines as you want to add to the chart
def highPointThreeBarNumber = HighestAll(if swingHigh and bn < highPointTwoBarNumber then bn else 0);
def highPointThreeValue = if bn == highPointThreeBarNumber then high else highPointThreeValue[1];
plot high3 = if bn < highPointThreeBarNumber then Double.NaN else highPointThreeValue;
high3.SetDefaultColor(Color.CYAN);
def highPointFourBarNumber = HighestAll(if swingHigh and bn < highPointThreeBarNumber then bn else 0);
def highPointFourValue = if bn == highPointFourBarNumber then high else highPointFourValue[1];
plot high4 = if bn < highPointFourBarNumber then Double.NaN else highPointFourValue;
high4.SetDefaultColor(Color.CYAN);
def highPointFiveBarNumber = HighestAll(if swingHigh and bn < highPointFourBarNumber then bn else 0);
def highPointFiveValue = if bn == highPointFiveBarNumber then high else highPointFiveValue[1];
plot high5 = if bn < highPointFiveBarNumber then Double.NaN else highPointFiveValue;
high5.SetDefaultColor(Color.CYAN);
def highPointSixBarNumber = HighestAll(if swingHigh and bn < highPointFiveBarNumber then bn else 0);
def highPointSixValue = if bn == highPointSixBarNumber then high else highPointSixValue[1];
plot high6 = if bn < highPointsixBarNumber then Double.NaN else highPointsixValue;
high6.SetDefaultColor(Color.CYAN);
def highPointSevenBarNumber = HighestAll(if swingHigh and bn < highPointSixBarNumber then bn else 0);
def highPointSevenValue = if bn == highPointSevenBarNumber then high else highPointSevenValue[1];
plot high7 = if bn < highPointSevenBarNumber then Double.NaN else highPointSevenValue;
high7.SetDefaultColor(Color.CYAN);
def highPointEightBarNumber = HighestAll(if swingHigh and bn < highPointSevenBarNumber then bn else 0);
def highPointEightValue = if bn == highPointEightBarNumber then high else highPointEightValue[1];
plot high8 = if bn < highPointEightBarNumber then Double.NaN else highPointEightValue;
high4.SetDefaultColor(Color.CYAN);
def highPointNineBarNumber = HighestAll(if swingHigh and bn < highPointEightBarNumber then bn else 0);
def highPointNineValue = if bn == highPointNineBarNumber then high else highPointNineValue[1];
plot high9 = if bn < highPointNineBarNumber then Double.NaN else highPointNineValue;
high4.SetDefaultColor(Color.CYAN);
def highPointTenBarNumber = HighestAll(if swingHigh and bn < highPointNineBarNumber then bn else 0);
def highPointTenValue = if bn == highPointTenBarNumber then high else highPointTenValue[1];
plot high10 = if bn < highPointTenBarNumber then Double.NaN else highPointTenValue;
high4.SetDefaultColor(Color.CYAN);

# ADJUST CANDLE COLORS
# change candle colors just to make it easier to see what we are working with
AssignPriceColor(if swingLow then Color.cyan else if swingHigh then Color.mageNTA else Color.current);
# End Swing High and Swing Low
plot HighArrow = swingHigh;
HighArrow.SetLineWeight(5);
HighArrow.SetDefaultColor(Color.RED);
HighArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot LowArrow = swingLow;
LowArrow.SetLineWeight(5);
LowArrow.SetDefaultColor(Color.GREEN);
LowArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
https://usethinkscript.com/threads/swing-high-low-indicator-for-thinkorswim.3109/page-7#post-122313
 
Here is a swing high/low pivot indicator with the barcount between changes as well as other options:
For :

HH
17.64 = highest close price
44.24% = Total % increase from bottom
16 = increase 16 bars
+$5.44 (Can you include this value, as this is the gaining value, if I drag from the bottom to top?)
 
For :

HH
17.64 = highest close price
44.24% = Total % increase from bottom
16 = increase 16 bars
+$5.44 (Can you include this value, as this is the gaining value, if I drag from the bottom to top?)

The dollar change option has been added

Screenshot 2023-08-17 144549.png
Code:
#Swing_HL_Pivots_Stats_v1

input pivotlength = 5;
input showhorizontals = yes;
input HHLLlabels = yes;
input showbubbles = yes;
input showHHLL_in_bubbles = yes;
input showprice_in_bubbles = yes;
input showpercentpricechange_in_bubbles = yes;
input showbarcount_in_bubbles = yes;
input showdollarchange_in_bubbles = yes;

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.RED);
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.GREEN);
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.WHITE);

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.WHITE);

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 "\n") +
(if showprice_in_bubbles then
AsText(high) + "\n" else "\n") +
(if showpercentpricechange_in_bubbles
then Round(chghigh) + "%\n" else "\n") +
(if showbarcount_in_bubbles then
"" + barcountchange else "\n") +
(if showdollarchange_in_bubbles then
"\n" + AsDollars((rh1 - xxlow[1])) else "") ,
if xxhigh > xxhigh[1] then Color.GREEN else Color.RED);

AddChartBubble(showbubbles and !IsNaN(Low1) and PointCount == -1, low,
(if showHHLL_in_bubbles then
(if rl1 > rl2 then "HL\n" else "LL\n")
else "\n") +
(if showprice_in_bubbles then
AsText(low) + "\n" else "\n") +
(if showpercentpricechange_in_bubbles
then Round(chglow) + "%\n" else "\n") +
(if showbarcount_in_bubbles then
"" + barcountchange else "\n") +
(if showdollarchange_in_bubbles then
"\n" + AsDollars(rl1 - xxhigh[1]) else ""),
if xxlow > xxlow[1] then Color.GREEN else Color.RED, no);
 
1693899191166.png

Is there a thinkscript for something just like this that works on any time frame? Trying to find something just like this.
 
View attachment 19654
Is there a thinkscript for something just like this that works on any time frame? Trying to find something just like this.

Thinkscript only allows text to be displayed as you wanted is through using addchartbubbles();

Here is the script in the prior post with only the HH/LH and HL/LL displayed. The colors have been changed to gray.


Screenshot 2023-09-19 075634.png

Code:
#Swing_HL_Pivots_Stats_v1

input pivotlength = 5;
input showhorizontals = yes;
input show_zigzag_line = no;
input HHLLlabels = no;
input showbubbles = yes;
input showHHLL_in_bubbles = yes;
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.GRAY);
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.GRAY);
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 "") ,
Color.GRAY
#if xxhigh > xxhigh[1] then Color.GREEN else Color.RED
);

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,
Color.GRAY, no);
 
Last edited:
Thinkscript only allows text to be displayed as you wanted is through using addchartbubbles();

Here is the script in the prior post with only the HH/LH and HL/LL displayed. The colors have been changed to gray.
How do I only get the HH and LL bubbles to show?
 
Thinkscript only allows text to be displayed as you wanted is through using addchartbubbles();

Here is the script in the prior post with only the HH/LH and HL/LL displayed. The colors have been changed to gray.
Hi SleepyZ, can you please help to add price bubble instead of HH or HL,...
 
Thinkscript only allows text to be displayed as you wanted is through using addchartbubbles();

Here is the script in the prior post with only the HH/LH and HL/LL displayed. The colors have been changed to gray.
@SleepyZ Like the script, sure makes it easier to spot lows and highs. Is there a way to code the script to take away the previous lows and highs once broken or invalidated? Seems like it will make the chart a little bit more cleaner.

The price bubble is already an option in the above code https://usethinkscript.com/threads/swing-high-low-indicator-for-thinkorswim.3109/post-131719

It can be selected at the input screen to YES as shown in the image below. Set the other options to NO as shown that you do not want.

View attachment 19861
@SleepyZ I have one of the other scripts you modified a few pages back with price on the chart but not in the bubble, can you input this into this script since it has all the other options. Bubble be in the way :)
 
@SleepyZ Like the script, sure makes it easier to spot lows and highs. Is there a way to code the script to take away the previous lows and highs once broken or invalidated? Seems like it will make the chart a little bit more cleaner.

That would require each one of the swings to be an individual plot and extended so that it could be done. There is only one plot for each of the highs/lows in the current code.

Here is an example using VolumeProfile of code to handle broken lines. https://usethinkscript.com/threads/...ume-profile-for-thinkorswim.10893/post-106420

@SleepyZ I have one of the other scripts you modified a few pages back with price on the chart but not in the bubble, can you input this into this script since it has all the other options. Bubble be in the way :)

This snippet was added to the script below and the bubble display set to no.

Code:
#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);

Here is the full revised code
Screenshot 2023-11-15 120245.png
Code:
#Swing_HL_Pivots_Stats_v1

input pivotlength = 5;
input showhorizontals = yes;
input show_zigzag_line = no;
input HHLLlabels = no;
input showbubbles = no;
input showHHLL_in_bubbles = yes;
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.GRAY);
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.GRAY);
Rlo.SetHiding(!showhorizontals);

#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);

#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 "") ,
Color.GRAY
#if xxhigh > xxhigh[1] then Color.GREEN else Color.RED
);

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,
Color.GRAY, no);
 
Here is a swing high/low pivot indicator with the barcount between changes as well as other options:
Hi @SleepyZ

I cleaned up some code for you concerning the "Addchartbubble" on the last two lines of each part (lines 125,126 and 140,141) where you have the choice of using Grey or Red and Green. There was an error when you switch from Grey to Color...I hope this helps!


Code:
#Swing_HL_Pivots_Stats_v1

input pivotlength = 5;
input showhorizontals = yes;
input show_zigzag_line = no;
input HHLLlabels = no;
input showbubbles = yes;
input showHHLL_in_bubbles = yes;
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);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
373 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