Hi, is there a way to code the following ideas:
if there are higher high consecutively for 5 days, then plot the upswing, vice versa lower lows for the downswing. I checked TOS zigzag version is based on number of points or ATRs, not number of bars.
Any thoughts anyone?
input show_only_first_arrow = no;
input qty = 5;
def cond1 = high > high[1];
def cond1sum = Sum(cond1, qty);
def up = if cond1sum == qty then 1 else 0;
def up2 = if !show_only_first_arrow then up else if up[1] then 0 else up;
def cond2 = low < low[1];
def cond2sum = Sum(cond2, qty);
def dwn = if cond2sum == qty then 1 else 0;
def dwn2 = if !show_only_first_arrow then dwn else if dwn[1] then 0 else dwn;
plot z1 = up2;
z1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
z1.SetDefaultColor(Color.GREEN);
z1.SetLineWeight(2);
plot z2 = dwn2;
z2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
z2.SetDefaultColor(Color.red);
z2.SetLineWeight(2);
#
Thank you. I can follow your code. But instead of plotting arrows, i wanna connect the lines from a last swing low to a swing high. Lets say a swing low is identified, then market had 5 consecutive highs, on the 6th day, it failed to make new highs, so i wanna plot a up zigzag line connecting the swing low to the 5th day high, but on the 6th day(which i assume is the current day) NO line is plotted because the condition is not satisfied. If after the 6th, maket continues to make higher high for another 5 days to 12th day, then the upswing line will continue to connect to the high on 12th day. Same logic for downswings. The output is a zigzag line that looks like TOS zigzaghighlow version, but the logic is totally differentyou can have a variable check for a condition.
then have another variable add up those conditions and see if they equal a specific quantity.
then draw an arrow when that happens.
can choose to show only the first arrow in a series, or all of them.
can choose the quantity of bars to look for rising/falling values.
i don't know what you want to see , from these words, plot the upswing. i had it draw arrows,
Code:input show_only_first_arrow = no; input qty = 5; def cond1 = high > high[1]; def cond1sum = Sum(cond1, qty); def up = if cond1sum == qty then 1 else 0; def up2 = if !show_only_first_arrow then up else if up[1] then 0 else up; def cond2 = low < low[1]; def cond2sum = Sum(cond2, qty); def dwn = if cond2sum == qty then 1 else 0; def dwn2 = if !show_only_first_arrow then dwn else if dwn[1] then 0 else dwn; plot z1 = up2; z1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); z1.SetDefaultColor(Color.GREEN); z1.SetLineWeight(2); plot z2 = dwn2; z2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down); z2.SetDefaultColor(Color.red); z2.SetLineWeight(2); #
Thank you. I can follow your code. But instead of plotting arrows, i wanna connect the lines from a last swing low to a swing high. Lets say a swing low is identified, then market had 5 consecutive highs, on the 6th day, it failed to make new highs, so i wanna plot a up zigzag line connecting the swing low to the 5th day high, but on the 6th day(which i assume is the current day) NO line is plotted because the condition is not satisfied. If after the 6th, maket continues to make higher high for another 5 days to 12th day, then the upswing line will continue to connect to the high on 12th day. Same logic for downswings. The output is a zigzag line that looks like TOS zigzaghighlow version, but the logic is totally different
# count_x_higher_highs_01
# ver1
# can choose first or last or all. if all arrows, no line is drawn
# draw a line between those in series bars , first or last bars
# https://usethinkscript.com/threads/zigzag-based-on-number-of-bars.6941/#post-96433
def na = double.nan;
input show_series_arrows = { only_first , default only_last , all };
def arr;
switch (show_series_arrows) {
case only_first:
arr = 1;
case only_last:
arr = 2;
case all:
arr = 3;
}
addlabel(arr == 1, "lines from first bar in a series", color.yellow);
addlabel(arr == 2, "lines from last bar in a series", color.yellow);
#input show_only_first_arrow = no;
#input show_only_last_arrow = yes;
input qty = 7;
def cond1 = high > high[1];
def cond1sum = Sum(cond1, qty);
def up = if cond1sum == qty then 1 else 0;
#def upfirst = if !show_only_first_arrow then up else if up[1] then 0 else up;
def upfirst = if arr == 1 and !up[1] then up else 0;
#def uplast = if !show_only_last_arrow then up else if (up and !up[-1]) then up else 0;
def uplast = if arr == 2 and !up[-1] then up else 0;
def upall = if arr == 3 then up else 0;
def cond2 = low < low[1];
def cond2sum = Sum(cond2, qty);
def dwn = if cond2sum == qty then 1 else 0;
#def dwnfirst = if !show_only_first_arrow then dwn else if dwn[1] then 0 else dwn;
def dwnfirst = if arr == 1 and !dwn[1] then dwn else 0;
#def dwnlast = if !show_only_last_arrow then dwn else if (dwn and !dwn[-1]) then dwn else 0;
def dwnlast = if arr == 2 and !dwn[-1] then dwn else 0;
def dwnall = if arr == 3 then dwn else 0;
input arrow_size = 3;
plot z1 = upfirst or upall;
z1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
z1.SetDefaultColor(Color.GREEN);
z1.SetLineWeight(arrow_size);
plot z2 = dwnfirst or dwnall;
z2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
z2.SetDefaultColor(Color.red);
z2.SetLineWeight(arrow_size);
plot z3 = uplast;
z3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
z3.SetDefaultColor(Color.cyan);
z3.SetLineWeight(arrow_size);
plot z4 = dwnlast;
z4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
z4.SetDefaultColor(Color.yellow);
z4.SetLineWeight(arrow_size);
# -------------------------------
# draw a line between the first or last bars in each series
# save close during a last bar
def price = close;
def linedata = if (arr == 1 and (upfirst or dwnfirst)) or (arr == 2 and (uplast or dwnlast)) then price else na;
def lineprices = if !isnan(linedata) then linedata else lineprices[1];
def isup = if !isnan(linedata) and close > lineprices[1] then 1 else 0;
plot z5 = linedata;
z5.EnableApproximation();
#z5.SetStyle(Curve.MEDIUM_DASH);
z5.SetDefaultColor(Color.yellow);
z5.setlineweight(2);
z5.hidebubble();
#
This doesn't seem right to me, but thank your for your great effort, let me try refer to the zigzag highlow script and see if i can come up with something more close. Basically i wanna plot something like zigzag highlow as built in TOS, but based on numbers of barsver2
draw a line between points.
a series is 1 or more bars that has higher highs or lower lows, for x quantity of bars.
can choose first or last or all. if all arrows, no line is drawn.
draw a line between those in series bars , first or last bars
default is draw lines from the last in each series
Ruby:# count_x_higher_highs_01 # ver1 # can choose first or last or all. if all arrows, no line is drawn # draw a line between those in series bars , first or last bars # https://usethinkscript.com/threads/zigzag-based-on-number-of-bars.6941/#post-96433 def na = double.nan; input show_series_arrows = { only_first , default only_last , all }; def arr; switch (show_series_arrows) { case only_first: arr = 1; case only_last: arr = 2; case all: arr = 3; } addlabel(arr == 1, "lines from first bar in a series", color.yellow); addlabel(arr == 2, "lines from last bar in a series", color.yellow); #input show_only_first_arrow = no; #input show_only_last_arrow = yes; input qty = 7; def cond1 = high > high[1]; def cond1sum = Sum(cond1, qty); def up = if cond1sum == qty then 1 else 0; #def upfirst = if !show_only_first_arrow then up else if up[1] then 0 else up; def upfirst = if arr == 1 and !up[1] then up else 0; #def uplast = if !show_only_last_arrow then up else if (up and !up[-1]) then up else 0; def uplast = if arr == 2 and !up[-1] then up else 0; def upall = if arr == 3 then up else 0; def cond2 = low < low[1]; def cond2sum = Sum(cond2, qty); def dwn = if cond2sum == qty then 1 else 0; #def dwnfirst = if !show_only_first_arrow then dwn else if dwn[1] then 0 else dwn; def dwnfirst = if arr == 1 and !dwn[1] then dwn else 0; #def dwnlast = if !show_only_last_arrow then dwn else if (dwn and !dwn[-1]) then dwn else 0; def dwnlast = if arr == 2 and !dwn[-1] then dwn else 0; def dwnall = if arr == 3 then dwn else 0; input arrow_size = 3; plot z1 = upfirst or upall; z1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); z1.SetDefaultColor(Color.GREEN); z1.SetLineWeight(arrow_size); plot z2 = dwnfirst or dwnall; z2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down); z2.SetDefaultColor(Color.red); z2.SetLineWeight(arrow_size); plot z3 = uplast; z3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); z3.SetDefaultColor(Color.cyan); z3.SetLineWeight(arrow_size); plot z4 = dwnlast; z4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down); z4.SetDefaultColor(Color.yellow); z4.SetLineWeight(arrow_size); # ------------------------------- # draw a line between the first or last bars in each series # save close during a last bar def price = close; def linedata = if (arr == 1 and (upfirst or dwnfirst)) or (arr == 2 and (uplast or dwnlast)) then price else na; def lineprices = if !isnan(linedata) then linedata else lineprices[1]; def isup = if !isnan(linedata) and close > lineprices[1] then 1 else 0; plot z5 = linedata; z5.EnableApproximation(); #z5.SetStyle(Curve.MEDIUM_DASH); z5.SetDefaultColor(Color.yellow); z5.setlineweight(2); z5.hidebubble(); #
MDT 1hr 90day
find 5 higher highs or 5 lower lows. a series is 1 or more of them.
draw lines from the last bar in each series.
I have tried but this script is too difficult for me. Is there a way to make your script to show highs and lows alternatively? your code sometimes connected high to another high. I have some pieces of code that i see elsewhere and this is similar to my idea:ver2
draw a line between points.
a series is 1 or more bars that has higher highs or lower lows, for x quantity of bars.
can choose first or last or all. if all arrows, no line is drawn.
draw a line between those in series bars , first or last bars
default is draw lines from the last in each series
Ruby:# count_x_higher_highs_01 # ver1 # can choose first or last or all. if all arrows, no line is drawn # draw a line between those in series bars , first or last bars # https://usethinkscript.com/threads/zigzag-based-on-number-of-bars.6941/#post-96433 def na = double.nan; input show_series_arrows = { only_first , default only_last , all }; def arr; switch (show_series_arrows) { case only_first: arr = 1; case only_last: arr = 2; case all: arr = 3; } addlabel(arr == 1, "lines from first bar in a series", color.yellow); addlabel(arr == 2, "lines from last bar in a series", color.yellow); #input show_only_first_arrow = no; #input show_only_last_arrow = yes; input qty = 7; def cond1 = high > high[1]; def cond1sum = Sum(cond1, qty); def up = if cond1sum == qty then 1 else 0; #def upfirst = if !show_only_first_arrow then up else if up[1] then 0 else up; def upfirst = if arr == 1 and !up[1] then up else 0; #def uplast = if !show_only_last_arrow then up else if (up and !up[-1]) then up else 0; def uplast = if arr == 2 and !up[-1] then up else 0; def upall = if arr == 3 then up else 0; def cond2 = low < low[1]; def cond2sum = Sum(cond2, qty); def dwn = if cond2sum == qty then 1 else 0; #def dwnfirst = if !show_only_first_arrow then dwn else if dwn[1] then 0 else dwn; def dwnfirst = if arr == 1 and !dwn[1] then dwn else 0; #def dwnlast = if !show_only_last_arrow then dwn else if (dwn and !dwn[-1]) then dwn else 0; def dwnlast = if arr == 2 and !dwn[-1] then dwn else 0; def dwnall = if arr == 3 then dwn else 0; input arrow_size = 3; plot z1 = upfirst or upall; z1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); z1.SetDefaultColor(Color.GREEN); z1.SetLineWeight(arrow_size); plot z2 = dwnfirst or dwnall; z2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down); z2.SetDefaultColor(Color.red); z2.SetLineWeight(arrow_size); plot z3 = uplast; z3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); z3.SetDefaultColor(Color.cyan); z3.SetLineWeight(arrow_size); plot z4 = dwnlast; z4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down); z4.SetDefaultColor(Color.yellow); z4.SetLineWeight(arrow_size); # ------------------------------- # draw a line between the first or last bars in each series # save close during a last bar def price = close; def linedata = if (arr == 1 and (upfirst or dwnfirst)) or (arr == 2 and (uplast or dwnlast)) then price else na; def lineprices = if !isnan(linedata) then linedata else lineprices[1]; def isup = if !isnan(linedata) and close > lineprices[1] then 1 else 0; plot z5 = linedata; z5.EnableApproximation(); #z5.SetStyle(Curve.MEDIUM_DASH); z5.SetDefaultColor(Color.yellow); z5.setlineweight(2); z5.hidebubble(); #
MDT 1hr 90day
find 5 higher highs or 5 lower lows. a series is 1 or more of them.
draw lines from the last bar in each series.
I have tried but this script is too difficult for me. Is there a way to make your script to show highs and lows alternatively? your code sometimes connected high to another high. I have some pieces of code that i see elsewhere and this is similar to my idea:
def swinghigh = if high > high[1] and high > high[2] and high > high[-1] and high > high[-2] then 1 else 0;
def swinglow = if low < low[1] and low < low[2] and low < low[-1] and low < low[-2] then 1 else 0;
plot sh = if swinghigh then high else Double.NaN;
plot sl = if swinglow then low else Double.NaN;
sh.SetStyle(Curve.POINTS);
sl.SetStyle(Curve.POINTS);
The problem is what if I wanna find 5 consecutive higher highs or more? Instead of high>high[1] and high[1]>high[2]... high[4]>high[5], is there an easy way to do it so that i can input whatever numbers i want.
Next problem is how to draw the lines between each high-low dot in the above script? Appreciated if anyone can shed some light
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
R | Zigzag interval 10 or 20 K-bar | Questions | 1 | |
G | ZigZag Increases & Reversals In A Scan | Questions | 0 | |
M | ZIGZAG High Low length | Questions | 0 | |
R | ZigZag & Future Bars Are Repainting! | Questions | 1 | |
W | ZigZag Percent: Add labels displaying averages | Questions | 1 |
Start a new thread and receive assistance from our community.
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.
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.