Repaints Moxie for ThinkorSwim

Repaints
@ext99k yes, it repaints.
If you look at a script and if there is a fold operation using highest and/or lowest that is the indication that it repaints.
Fold is a recursive operation that keeps redefining the highest and lowest and redrawing them.
MerryDay,
Is there a code for highest high and lowest low for first fifteen minutes (9:45) without a repainting? And can then be adjusted for another 15' increment?
TY in advance!
 

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

I tried this
input end = 1600;
def active = if secondsFromTime(start) == 0 then 1 else 0;
def h = high;
def hh = if active && h then h else if h > hh[1] then h else hh[1];
def l = low;
def ll = if active && l then l else if l < ll[1] then l else ll[1];
plot RTH_High = hh;
RTH_High.hide();
plot RTH_Low = ll;
RTH_Low.hide();
RTH_High.setpaintingStrategy(paintingStrategy.ARROW_DOWN);
RTH_Low.setPaintingStrategy(paintingStrategy.ARROW_UP);

addlabel(1,"Range = " + (hh - ll)+ "; " + "Range% = " + Round(100*(hh - ll)/open,2) +"%",color.white);

but I'm getting error message
Only constants expected here: start CL constant function parameter 'fromTime' at 2:33
Expected double at 2:17
No such variable: start at 2:33
Only constants expected here: start CL constant function parameter 'fromTime' at 2:33
 
I tried this
input end = 1600;
def active = if secondsFromTime(start) == 0 then 1 else 0;
def h = high;
def hh = if active && h then h else if h > hh[1] then h else hh[1];
def l = low;
def ll = if active && l then l else if l < ll[1] then l else ll[1];
plot RTH_High = hh;
RTH_High.hide();
plot RTH_Low = ll;
RTH_Low.hide();
RTH_High.setpaintingStrategy(paintingStrategy.ARROW_DOWN);
RTH_Low.setPaintingStrategy(paintingStrategy.ARROW_UP);

addlabel(1,"Range = " + (hh - ll)+ "; " + "Range% = " + Round(100*(hh - ll)/open,2) +"%",color.white);

but I'm getting error message
Only constants expected here: start CL constant function parameter 'fromTime' at 2:33
Expected double at 2:17
No such variable: start at 2:33
Only constants expected here: start CL constant function parameter 'fromTime' at 2:33
You did not define start. Try adding: input start = 0930;
 
I tried this
input end = 1600;
def active = if secondsFromTime(start) == 0 then 1 else 0;
def h = high;
def hh = if active && h then h else if h > hh[1] then h else hh[1];
def l = low;
def ll = if active && l then l else if l < ll[1] then l else ll[1];
plot RTH_High = hh;
RTH_High.hide();
plot RTH_Low = ll;
RTH_Low.hide();
RTH_High.setpaintingStrategy(paintingStrategy.ARROW_DOWN);
RTH_Low.setPaintingStrategy(paintingStrategy.ARROW_UP);

addlabel(1,"Range = " + (hh - ll)+ "; " + "Range% = " + Round(100*(hh - ll)/open,2) +"%",color.white);

but I'm getting error message
Only constants expected here: start CL constant function parameter 'fromTime' at 2:33
Expected double at 2:17
No such variable: start at 2:33
Only constants expected here: start CL constant function parameter 'fromTime' at 2:33
These are the repainting statements:
def hh = if active && h then h else if h > hh[1] then h else hh[1];
def ll = if active && l then l else if l < ll[1] then l else ll[1];
it says if this candle is a high then save to variable "hh" THEN it says. if the next candle is even higher erase that last candle and call this one the high, so it is endlessly repainting.
 
Forgive me if this has already been answered, but I searched the fourm and couldn't find it. Is there a way to scan for the high and low? I've tried "If HighArrow is true" and "If HighArrow is equal to 1" but I get an error on both scripts. Thanks in advance
 
Forgive me if this has already been answered, but I searched the fourm and couldn't find it. Is there a way to scan for the high and low? I've tried "If HighArrow is true" and "If HighArrow is equal to 1" but I get an error on both scripts. Thanks in advance
This script is too complex for the Scan Hacker :(
 
@cswu1211

Code:
# Swing High and Swing Low
# tomsk
# 11.18.2019

# As requested by chillc15 I have modified [USER=1174]@RobertPayne[/USER] 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                        |
#  |               [URL]https://funwiththinkscript.com[/URL]               |
#  +------------------------------------------------------------+

# 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
 
HI @tenacity11 . I don't know if you can help me. I was looking at your code for Swing Highs and Swing Lows...
What I'm looking for is first find the Last Swing high..... once I found the Swing High... after than I would like to find the last Swing Low after that... I want to built and scanner that find possible pullbacks and once it found it, look for the pullback and once starts to do new Highs enter into that position. I tried to take from the code the last Swing Low and the last Swing High.... but I will get this. It will give the previous Swing Low before finding the last Swing high... I tried to modified but it doesn't work. Or I would like a scanner that finds the price retrace certain percentage from the Last swing High. thanks in advance

TSpBXFS.jpg
 
HI @tenacity11 . I don't know if you can help me. I was looking at your code for Swing Highs and Swing Lows...
What I'm looking for is first find the Last Swing high..... once I found the Swing High... after than I would like to find the last Swing Low after that... I want to built and scanner that find possible pullbacks and once it found it, look for the pullback and once starts to do new Highs enter into that position. I tried to take from the code the last Swing Low and the last Swing High.... but I will get this. It will give the previous Swing Low before finding the last Swing high... I tried to modified but it doesn't work. Or I would like a scanner that finds the price retrace certain percentage from the Last swing High. thanks in advance

TSpBXFS.jpg
I understand what you're asking for but I'm unable to do it. We have many who may be able to. I do remember seeing a scanner for percentage retraces and the best thing to do is go to the search bar for price percent retrace scans. I had one at one time and if I find it I will post it for you. Tomsk was the one who put it together and I'm not sure if he is still here or not.
 
Hello All - Would it be possible to added connecting lines to the Swing points [like zig zag lines]. I've attached a photo as an example. Thanks in advance.


See if this script I made awhile ago might work how you requested. It is part of a larger scirpt and it may need tweeking as I never tested/used it enough.

Ruby:
#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();
 
@flyingfalcon Moxie indicator is same as MACD but on a higher time frame. For daily, it is MACD on weekly time frame. Hahn-tech as it available here - https://www.hahn-tech.com/thinkorswim-mtf-macd-indicator/

I found this in 2018, but did not think it was very useful. After checking out recent promo videos on Moxie trader, it seems like a useful tool.
the default setting on hahn-tech has current time frame MACD enabled. make sure to disable 'Value', 'Avg' and 'Diff' by unchecking 'Show plot'. And enable 'midTermDiff' plot.

Hope this helps
I'm using the below code to create previous high and low levels. seems to work well.

How can i get this to allow me to store the 2nd previous swing high or 2nd previous swing low?

My goal is to compare the the 2nd previous high to the current previous high to determine up or down trend.

I have tried using the simple Support[1] > Support[2] but it doesn't seem to work. When i add these to a label, it only gives me to current high or low no matter what value i put into the [ ].

Please help.

Code:
#SWING HIGH LOW
input LookbackPeriod = 3;
input HideCurrentTF = no;

#--------------------------------------------------------------
def _highInPeriod1 = Highest(high, LookbackPeriod);
def _lowInPeriod1 = Lowest(low, LookbackPeriod);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod];
def _markedLow1 = low == marketLow1;

rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow1[1] else if _markedLow1 then low else _lastMarkedLow1[1], low);
#--------------------------------------------------------------
def marketHigh1 = if _highInPeriod1 > _highInPeriod1[-LookbackPeriod] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod];
def _markedHigh1 = high == marketHigh1;

rec _lastMarkedHigh1 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh1[1] else if _markedHigh1 then high else _lastMarkedHigh1[1], high);
#--------------------------------------------------------------
plot Resistance1 = _lastMarkedHigh1;
plot Support1 = _lastMarkedLow1 ;

#--------------------------------------------------------------
Resistance1.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance1.SetDefaultColor(Color.GREEN);
Resistance1.SetHiding(HideCurrentTF);
#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.DASHES);
Support1.SetDefaultColor(Color.RED);
Support1.SetHiding(HideCurrentTF);

I'm struggling with this. I feel like this should be something relatively easy to figure out but i can't seem to crack the logic on this. Simply doubling the lookback period doesn't help.

For example - I just want to record the previous 2 highs of 82.94 and 82.90 as well as the 2 previous lows of 82.25 and 82.33. Once i can do that, i can use them for comparison.

zxF0IRY.png
Can you please show the scripts to add the price for high and low?
 

Here is the code you provided in the link with the zigzag snippet added. The snippet tries to eliminate multiple plots of highs or lows between zigzags.

I have emphasized the zigzag in the image below.

Capture.jpg
Ruby:
# Swing High and Swing Low
# tomsk
# 11.18.2019
# As requested by chillc15 I have modified [USER=1174]@RobertPayne[/USER] 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);

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

# End Swing High and Swing Low
def h=high;
def l=low;
def c=close;
def HH1 = swinghigh;#h >= Highest(h, length) and h >= Highest(h, length)[-length];
def Hi1 = if HH1 then h else Double.NaN;
def LL1 = swinglow;#l <= Lowest(l, length) and l <= Lowest(l, length)[-length];
def Lo1 = if LL1 then l else Double.NaN;
def PointCount = if BarNumber() == 1 then 0 else
                 if IsNaN(c) then PointCount[1] else
                 if !IsNaN(Hi1) then Max(1, PointCount[1] + 1) else
                 if !IsNaN(Lo1) then Min(-1, PointCount[1] - 1)
                 else PointCount[1];

#ZigZags
def zHI;
def zLO;
zHI = if !IsNaN(hi1) and PointCount == 1 then h else Double.NaN;
zLO = if !IsNaN(lo1) and PointCount == -1 then l else Double.NaN;
plot hilowline = if !IsNaN(zHI) then zHI else zLO;
hilowline.EnableApproximation();
 
Here is the code you provided in the link with the zigzag snippet added. The snippet tries to eliminate multiple plots of highs or lows between zigzags.

I have emphasized the zigzag in the image below.
Thank you so much! Is it also possible to have a label how showing where the last swing was up or down? For example, if the last swing point was a swing-low then there would be a label showing swing low, until a swing high occurs.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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