Intraday Lower Low, followed by a Higher High Indicator

itsmikejb

New member
Is it possible to write a script that displays when an intraday lower low, followed by a higher high is created? Kind of like price is expanding in a way. Thank you for your time, if this is possible I would appreciate any insight.
 
Is it possible to write a script that displays when an intraday lower low, followed by a higher high is created? Kind of like price is expanding in a way. Thank you for your time, if this is possible I would appreciate any insight.

find peaks and valleys, defined by, x bars before and after the current bar,
default is 7 bars,
input length = 7;

a higher peak or valley gets a green dot.
a lower peak or valley gets a red dot.

look for lower low , red dot under a valley
then look for a higher high , green dot above a peak

draw horizontal lines, between the valley and peak bars
draw a cloud , between the valley and peak bars

Ruby:
# lolo_then_hihi_0

#https://usethinkscript.com/threads/intraday-lower-low-followed-by-a-higher-high-indicator.12563/
#  display when an intraday lower low, followed by a higher high is created

#---------------------------------
# robert_peaks_updated_01
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# define swing low points
#------------------------

def bn = BarNumber();
def na = double.nan;
input length = 7;
def lastbn = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastbn - bn);

def peak = high > highest(high[1], length - 1) and high == GetValue(highest(high, length), -offset);
def valley = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);

# determine if peaks are higher or lower
def peak_bn;
def peak_pr;
def peak_dir;
if bn == 1 then {
  peak_bn = 0;
  peak_pr = 0;
  peak_dir = 0;
} else if peak then {
  peak_bn = bn;
  peak_pr = high;
  peak_dir = if (peak_pr < peak_pr[1]) then -1 else if (peak_pr > peak_pr[1]) then 1 else 0;
} else {
  peak_bn = peak_bn[1];
  peak_pr = peak_pr[1];
  peak_dir = peak_dir[1];
}

# determine if valleys are higher or lower
def valley_bn;
def valley_pr;
def valley_dir;
if bn == 1 then {
  valley_bn = 0;
  valley_pr = 0;
  valley_dir = 0;
} else if valley then {
  valley_bn = bn;
  valley_pr = low;
  valley_dir = if (valley_pr < valley_pr[1]) then -1 else if (valley_pr > valley_pr[1]) then 1 else 0;
} else {
  valley_bn = valley_bn[1];
  valley_pr = valley_pr[1];
  valley_dir = valley_dir[1];
}

# is this a valley and a lower valley ?
def vlo = (valley and valley_dir < 0);

# if a lolo, look ahead for a hihi
def next_off;
def hihibn;
def hihipr;
def lolobn;
def lolopr;
if bn == 1 or peak[1] then {
# reset vars after a peak
  next_off = 0;
  hihibn = 0;
  hihipr = 0;
  lolobn = 0;
  lolopr = 0;
} else if vlo then {
  # find next peak
  next_off = fold i = 0 to (lastbn - bn + 1)
    with p
    while !isnan(getvalue(close, -i)) and !getvalue(peak, -i)
    do p + 1;
  # read next peak, is it a hihi ?  then get bn of it
  hihibn = if getvalue(peak_dir, -next_off) > 0 then (bn + next_off) else 0;
  # if peak is a hihi then get high of peak
  hihipr = if hihibn > 0 then getvalue(high, -next_off) else 0;

  # if next peak is a hihi , then get bn of current low
  lolobn = if hihibn > 0 then bn else 0;
  # if next peak is a hihi , then get current low
  lolopr = if hihibn > 0 then low else 0;

} else {
  hihibn = hihibn[1];
  next_off = next_off[1];
  hihipr =  hihipr[1];
  lolobn = lolobn[1];
  lolopr = lolopr[1];
}

#----------------
# up arrow on hihi peak
plot hihipeak = if bn == hihibn then low*0.998 else na;
hihipeak.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
hihipeak.SetDefaultColor(Color.cyan);
hihipeak.setlineweight(3);
hihipeak.hidebubble();

plot hitop = if hihibn > 0 then hihipr else na;
plot hibot = if hihibn > 0 then lolopr else na;
hitop.SetDefaultColor(Color.light_gray);
hibot.SetDefaultColor(Color.light_gray);

input show_cloud = yes;
def ztop = if show_cloud then hitop else na;
addcloud( ztop, hibot, color.light_gray);

#-------------------------------------
# draw dots above peaks and below valleys
#  colored , green if a higher, red if a lower
input peak_valley_dots = yes;
def vert = 0.002;
plot z1 = if peak_valley_dots and peak then high*(1+vert) else na;
z1.SetPaintingStrategy(PaintingStrategy.POINTS);
#z1.AssignValueColor(if peak_dir < 0 then color.blue else if peak_dir > 0 then color.cyan else color.gray);
z1.AssignValueColor(if peak_dir < 0 then color.red else if peak_dir > 0 then color.green else color.gray);
#z1.SetDefaultColor(Color.magenta);
z1.setlineweight(3);
z1.hidebubble();

plot z2 = if peak_valley_dots and valley then low*(1-vert) else na;
z2.SetPaintingStrategy(PaintingStrategy.POINTS);
#z2.AssignValueColor(if valley_dir < 0 then color.red else if valley_dir > 0 then color.yellow else color.gray);
z2.AssignValueColor(if valley_dir < 0 then color.red else if valley_dir > 0 then color.green else color.gray);
z2.SetDefaultColor(Color.magenta);
z2.setlineweight(3);
z2.hidebubble();


#---------------------------
# test stuff

input test1_bn = no;
addchartbubble(test1_bn and vlo, low*0.99,
bn + "\n" +
next_off + "\n" +
hihibn + "\n" +
lolobn
, color.yellow, no);

# x.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
# x.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#

Du7405T.jpg
 
Last edited:

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

@halcyonguy Is it possible to have a short line right on top of the candle wick like this, showing HH or LH etc.?


I tried changing POINTS to the below:
z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

but that doesn't extend the line a bit more to the right, just shows pretty much as before. What do I need to change please?
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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