Hi - can someone create an indicator and a scan that shows when a higher low or lower high is created? The strength of the swing/pivot can be user-defined.
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Hi - so based on swing/pivot strength i.e. a strength of 1 means the a bar is a high if it's higher than those 1 bar before and after it. strength of 2 means it's higher than those 2 bars before and after it, etc.can you be more specific?
almost every bar has a higher low or a lower high.
i think so. so you want to find a,Hi - so based on swing/pivot strength i.e. a strength of 1 means the a bar is a high if it's higher than those 1 bar before and after it. strength of 2 means it's higher than those 2 bars before and after it, etc.
Does that help?
yupi think so. so you want to find a,
higher pivot valley
or lower pivot peak.
not just a high or a low.
Hi - can someone create an indicator and a scan that shows when a higher low or lower high is created? The strength of the swing/pivot can be user-defined.
# find_next_peak_valley_00_upper
# https://usethinkscript.com/threads/higher-low-lower-high.13855/
# Higher Low , Lower High
#------------------------
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# define swing low points , robert payne
# modifified by halcyonguy to ignore last bar
#------------------------
def bn = BarNumber();
def na = double.nan;
input length = 7;
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
input ignore_last_bar = yes;
def ignorelast = if (ignore_last_bar and bn == lastbar) then 0 else 1;
def peak = ignorelast and high > highest(high[1], length - 1) and high == GetValue(highest(high, length), -offset);
def valley = ignorelast and low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
#-------------------------------------
input show_dots_on_peaks_valleys = yes;
def vert = 0.001;
plot z1 = if show_dots_on_peaks_valleys and peak then high*(1+vert) else na;
z1.SetPaintingStrategy(PaintingStrategy.POINTS);
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(3);
z1.hidebubble();
plot z2 = if show_dots_on_peaks_valleys and valley then low*(1-vert) else na;
z2.SetPaintingStrategy(PaintingStrategy.POINTS);
z2.SetDefaultColor(Color.cyan);
z2.setlineweight(3);
z2.hidebubble();
#-------------------------------------
input peak_valley_within_last_xbars = 4;
# save high of peak to compare to next peak
def peak_lvl = if bn == 1 then 0
else if peak then high
else peak_lvl[1];
def peak_higher = (peak and peak_lvl[1] > 0 and peak_lvl > peak_lvl[1]);
def peak_lower = (peak and peak_lvl[1] > 0 and peak_lvl < peak_lvl[1]);
def pkhi_lastx = (sum(peak_higher, peak_valley_within_last_xbars) > 0);
def pklo_lastx = (sum(peak_lower, peak_valley_within_last_xbars) > 0);
# save low of valley to compare to next valley
def valley_lvl = if bn == 1 then 0
else if valley then low
else valley_lvl[1];
def valley_higher = (valley and valley_lvl[1] > 0 and valley_lvl > valley_lvl[1]);
def valley_lower = (valley and valley_lvl[1] > 0 and valley_lvl < valley_lvl[1]);
def valhi_lastx = (sum(valley_higher, peak_valley_within_last_xbars) > 0);
def vallo_lastx = (sum(valley_lower, peak_valley_within_last_xbars) > 0);
#-------------------------------------
input look_for_peak_higher = yes;
input look_for_peak_lower = yes;
input look_for_valley_higher = yes;
input look_for_valley_lower = yes;
def hipk = (if look_for_peak_higher and pkhi_lastx then 1 else 0);
def lopk = (if look_for_peak_lower and pklo_lastx then 1 else 0);
def hival = (if look_for_valley_higher and valhi_lastx then 1 else 0);
def loval = (if look_for_valley_lower and vallo_lastx then 1 else 0);
def scan = hipk or lopk or hival or loval;
addlabel(1, " ", color.black);
addlabel(1, (if scan then "" else "no ") + "pivot, within " + peak_valley_within_last_xbars + " bars", (if scan then color.white else color.gray));
addlabel(hipk, (if hipk then " > peak " else ""), color.green);
addlabel(hival, (if hival then " > valley " else ""), color.green);
addlabel(lopk, (if lopk then " < peak " else ""), color.red);
addlabel(loval, (if loval then " < valley " else ""), color.red);
addlabel(1, " ", color.black);
#
# find_next_peak_valley_00_lower
# lower / scan
# https://usethinkscript.com/threads/higher-low-lower-high.13855/
# Higher Low Lower High
#------------------------
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# define swing low points , robert payne
# modifified by halcyonguy to ignore last bar
#------------------------
declare lower;
def bn = BarNumber();
def na = double.nan;
input length = 7;
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
input ignore_last_bar = yes;
def ignorelast = if (ignore_last_bar and bn == lastbar) then 0 else 1;
def peak = ignorelast and high > highest(high[1], length - 1) and high == GetValue(highest(high, length), -offset);
def valley = ignorelast and low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
#-------------------------------------
#input show_dots_on_peaks_valleys = yes;
#def vert = 0.001;
#plot z1 = if show_dots_on_peaks_valleys and peak then high*(1+vert) else na;
#z1.SetPaintingStrategy(PaintingStrategy.POINTS);
#z1.SetDefaultColor(Color.cyan);
#z1.setlineweight(3);
#z1.hidebubble();
#plot z2 = if show_dots_on_peaks_valleys and valley then low*(1-vert) else na;
#z2.SetPaintingStrategy(PaintingStrategy.POINTS);
#z2.SetDefaultColor(Color.cyan);
#z2.setlineweight(3);
#z2.hidebubble();
#-------------------------------------
input peak_valley_within_last_xbars = 4;
# save high of peak to compare to next peak
def peak_lvl = if bn == 1 then 0
else if peak then high
else peak_lvl[1];
def peak_higher = (peak and peak_lvl[1] > 0 and peak_lvl > peak_lvl[1]);
def peak_lower = (peak and peak_lvl[1] > 0 and peak_lvl < peak_lvl[1]);
def pkhi_lastx = (sum(peak_higher, peak_valley_within_last_xbars) > 0);
def pklo_lastx = (sum(peak_lower, peak_valley_within_last_xbars) > 0);
# save low of valley to compare to next valley
def valley_lvl = if bn == 1 then 0
else if valley then low
else valley_lvl[1];
def valley_higher = (valley and valley_lvl[1] > 0 and valley_lvl > valley_lvl[1]);
def valley_lower = (valley and valley_lvl[1] > 0 and valley_lvl < valley_lvl[1]);
def valhi_lastx = (sum(valley_higher, peak_valley_within_last_xbars) > 0);
def vallo_lastx = (sum(valley_lower, peak_valley_within_last_xbars) > 0);
#-------------------------------------
input look_for_peak_higher = yes;
input look_for_peak_lower = yes;
input look_for_valley_higher = yes;
input look_for_valley_lower = yes;
def hipk = (if look_for_peak_higher and pkhi_lastx then 1 else 0);
def lopk = (if look_for_peak_lower and pklo_lastx then 1 else 0);
def hival = (if look_for_valley_higher and valhi_lastx then 1 else 0);
def loval = (if look_for_valley_lower and vallo_lastx then 1 else 0);
def scan = hipk or lopk or hival or loval;
# add a plot for scanner output
plot z = scan;
#addlabel(1, " ", color.black);
#addlabel(1, (if scan then "" else "no ") + "pivot, within " + peak_valley_within_last_xbars + " bars", (if scan then color.white else color.gray));
#addlabel(hipk, (if hipk then " > peak " else ""), color.green);
#addlabel(hival, (if hival then " > valley " else ""), color.green);
#addlabel(lopk, (if lopk then " < peak " else ""), color.red);
#addlabel(loval, (if loval then " < valley " else ""), color.red);
#addlabel(1, " ", color.black);
#
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.