Is it possible to get the prior lowestall(low) on a given chart?

greco26

Active member
Hi All,

As the subject says, is this possible? I've made several unsuccessful attempts with some examples below. Im missing something....

Code:
def l = lowestall(low);
def lBN1 = if low == l then bn else lbn1[1];
def priorLBN = if bn < lbn1 then lowestall(low) else priorLBN[1];

#Attemt 1 Test bubble
addchartbubble(bn==highestall(priorlbn),low,priorlbn,color.yellow);

def lbn2 = if l != l[1] then l[1] else lbn2[1];

#Attempt 2 Test bubble
addchartbubble(bn==lbn2,low,lbn2,color.green);
 
Hi All,

As the subject says, is this possible? I've made several unsuccessful attempts with some examples below. Im missing something....


EDIT---6/15-------fixed

sorry for my bad code yesterday.
while passing some time in a hotel room, i tried to answer the question, by creating a study on my cell.
i try not to do that, as it's too easy for a typo to pop in, and a couple did.

here is a fixed study.
i added a 3rd lowest low.

Code:
# prev_lowest_0

def bn = barnumber();
def big = 999999;

#lowest low
def lo1 = lowestall(low);
def lo1bn = highestall(if low == lo1 then bn else 0);

# prev 1 low
def lo2 = lowestall(if bn < lo1bn then low else big);
def lo2bn = highestall(if low == lo2 and bn < lo1bn then bn else 0);

# prev 2 low
def lo3 = lowestall(if bn < lo2bn then low else big);
def lo3bn = highestall(if low == lo3 and bn < lo2bn then bn else 0);

addchartbubble( bn == lo1bn, low, "1\n" + lo1bn , color.green, no);
addchartbubble( bn == lo2bn, low, "2\n" + lo2bn , color.cyan, no);
addchartbubble( bn == lo3bn, low, "3\n" + lo3bn , color.yellow, no);

# test----------------------
addchartbubble(0 and bn <  lo1bn, low,
 low + "\n" +
 lo1bn + " 1bn\n" +
 lo2 + " lo2\n" +
 lo2bn + " 2bn"
, color.cyan);
#


green bubble is lowest low
cyan bubble is the next lowest price, on a bar that occurs before the lowest low.
yellow bubble is 3rd lowest low,...
1st row , is low # ( 1,2,3)
2nd row , is barnumber
NEE day
o33DNKn.jpg
 
Last edited:

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

Unfortunately, it doesn't work. Its having the same issue that I was having with my code in that it finds the 1st bar but the data for the 2nd bar is 1 bn less than lo1bn. FYI, I changed the second bubble to lo2bn assuming that was just a type-o

I I had another thought. Instead of me using Lowestall(low), what if use lowest(low,xxxxx) where as the xxxx is the number of bars present in the current chart. Once I identify that, I could do something like def LL = if Lowest(low,xxxxx) != Lowest(low,xxxxx)[1] then Lowest(low,xxxxx) else LL[1];
 
Unfortunately, it doesn't work. Its having the same issue that I was having with my code in that it finds the 1st bar but the data for the 2nd bar is 1 bn less than lo1bn. FYI, I changed the second bubble to lo2bn assuming that was just a type-o

I I had another thought. Instead of me using Lowestall(low), what if use lowest(low,xxxxx) where as the xxxx is the number of bars present in the current chart. Once I identify that, I could do something like def LL = if Lowest(low,xxxxx) != Lowest(low,xxxxx)[1] then Lowest(low,xxxxx) else LL[1];

This seems to identify all the lowestall lows prior to the bar first identifying the lowestall for the whole chart

Capture.jpg
Ruby:
plot bn = BarNumber();
#bn.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
def l  = LowestAll(low);
def lBN1 = if low == l then bn else lBN1[1];
AddChartBubble(bn == lBN1, low, low, Color.CYAN, no);

def nextlow = CompoundValue(1, if bn == 1 then low else if Between(bn, 2, HighestAll(lBN1 - 1)) then Min(low, nextlow[1]) else nextlow[1], low);
def nextbar = if low == nextlow then bn else nextbar[1];
#addlabel(1,nextlow+ " " +nextbar[1]);
AddChartBubble(bn == nextbar, low, nextlow, Color.YELLOW, no);
 
How would I exclude the bars that are in the downslope (14.42 and 12.77) leading to the 12.44 blue bubble? my objective would be to identify the 14.905 bar in the example you provided.
 
Plot L2 = LowestALl(if low > lowestall(low) then low else double.POSITIVE_INFINITY);
this would work if I can limit it to bars < lowestall(low) bar number. I tried the following but it didn't like the code.

def BN = Barnumber();
def LowestallBN = if low == lowestall(low) then BN else LowestallBN[1];
Plot L2 = LowestALl(if bn < lowestallbn and low > lowestall(low) then low else double.POSITIVE_INFINITY);
addchartbubble(l2,l2,l2,color.violet);
 
this would work if I can limit it to bars < lowestall(low) bar number. I tried the following but it didn't like the code.

def BN = Barnumber();
def LowestallBN = if low == lowestall(low) then BN else LowestallBN[1];
Plot L2 = LowestALl(if bn < lowestallbn and low > lowestall(low) then low else double.POSITIVE_INFINITY);
addchartbubble(l2,l2,l2,color.violet);
Try this
Ruby:
plot bn = BarNumber();
#bn.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
def l  = LowestAll(low);
def lBN1 = if low == l then bn else lBN1[1];
AddChartBubble(bn == lBN1, low, low, Color.CYAN, no);

def nextlow = CompoundValue(1, if bn == 1 then low else if Between(bn, 2, HighestAll(lBN1 - 1)) then Min(low, nextlow[1]) else nextlow[1], low);
def nextbar = if low == nextlow then bn else nextbar[1];
AddLabel(1, nextlow + " " + nextbar[1]);
AddChartBubble(bn == nextbar, low, nextlow, Color.YELLOW, no);
def n1 = if nextlow != nextlow[1] then nextlow[1] else n1[1];
def n2 = if n1 != n1[1] then n1[1] else n2[1];

AddLabel(1, n1 + " " + n2, Color.WHITE);
 
I think your code is correct however I think my ask was incorrect. I suppose I dont want the prior lowestall(low). A better way of stating what I need to identify is the prior (moving left on the chart) lowest swing low above the lowestall(low) value.

In the following image of /MES on the 1min/1day chart, 3708.75 is the lowestall(low). I want to identity the prior lowest swing low which would be 3728.25.

 
Post the snippet of code that represents your method for finding a swing low.
Here you go!
Code:
input TakeProfitPct = .5; #hint, 1 is 1 pct, .5 is 1/2 percent, etc
def takeprofitconverstionLong = 1 + (TakeProfitPct / 100);
AddLabel(1, (takeprofitconverstionLong * close) - close, Color.WHITE);
def takeprofitconverstionshort = 1 - (TakeProfitPct / 100);
AddLabel(1, (takeprofitconverstionshort * close) - close, Color.WHITE);
def bn = BarNumber();
def Latest_bar = if IsNaN(close[-1]) then bn else Latest_bar[1];

def HourH = high(period = AggregationPeriod.HOUR);
def HourL = low(period = AggregationPeriod.HOUR);
def HourH1ba = high(period = AggregationPeriod.HOUR)[1];
def HourL1ba = low(period = AggregationPeriod.HOUR)[1];

def hourlong = close > HourH1ba;
def hourshort = close < HourL1ba;


input Major_bubbleoffset = .0005;
input Major_percentamount = .15;
input Major_revAmount = .2;
input Major_atrreversal = 3.75;
input Major_atrlength = 5;
def zz = ZigZagHighLow("price h" = high, "price l" = low, "percentage reversal" = Major_percentamount, "absolute reversal" = Major_revAmount, "atr length" = Major_atrlength, "atr reversal" = Major_atrreversal);
def reversalAmount        = if (close * Major_percentamount / 100) > Max(Major_revAmount < Major_atrreversal * Major_atrlength, Major_revAmount) then (close * Major_percentamount / 100) else if Major_revAmount < Major_atrreversal * Major_atrlength then Major_atrreversal * Major_atrlength else Major_revAmount;
rec zzSave = if !IsNaN(zz) then zz else GetValue(zzSave, 1);
def chg = (if zzSave == high then high else low) - GetValue(zzSave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(zz, 1)) and GetValue(isConf, 1));
def zzd = if isUp then 1 else 0;
plot zzp = if zzd <= 1 then zz else Double.NaN;
zzp.AssignValueColor(if zzd == 1 then Color.GREEN else if zzd == 0 then Color.RED else Color.DARK_ORANGE);
zzp.SetStyle(Curve.FIRM);
zzp.EnableApproximation();
zzp.SetLineWeight(1);
 
#Price Change between zigzags
def xxhigh = if zzSave == high then  high else xxhigh[1];
def chghigh = high - xxhigh[1];
def xxlow = if zzSave == low then low else xxlow[1];
def chglow = low - xxlow[1];
input showMagnitudeBubbles = yes;
AddChartBubble(showMagnitudeBubbles and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + Major_bubbleoffset)  else low * (1 - Major_bubbleoffset)   , "$" + chg , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, isUp);
 
 
#Price at High/Low
input Major_showBubblesprice = no;
AddChartBubble(Major_showBubblesprice and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + Major_bubbleoffset)  else low * (1 - Major_bubbleoffset)   , if isUp then "$" + high else "$" + low , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, isUp);
 
Unfortunately, it doesn't work. Its having the same issue that I was having with my code in that it finds the 1st bar but the data for the 2nd bar is 1 bn less than lo1bn. FYI, I changed the second bubble to lo2bn assuming that was just a type-o

I I had another thought. Instead of me using Lowestall(low), what if use lowest(low,xxxxx) where as the xxxx is the number of bars present in the current chart. Once I identify that, I could do something like def LL = if Lowest(low,xxxxx) != Lowest(low,xxxxx)[1] then Lowest(low,xxxxx) else LL[1];
fixed my code in post2
 
This might help as well

Code:
input Major_percentamount = .15;
input Major_revAmount = .2;
input Major_atrreversal = 3.75;
input Major_atrlength = 5;
def zz = ZigZagHighLow("price h" = high, "price l" = low, "percentage reversal" = Major_percentamount, "absolute reversal" = Major_revAmount, "atr length" = Major_atrlength, "atr reversal" = Major_atrreversal);

def ZigLow =
    if !isnan(zz) and BarNumber() != 1
    then zz == low
    else no
;
def TrackLow =
    if ZigLow then Low
    else if !TrackLow[1] then double.nan
    else TrackLow[1];
;
def Bottom = LowestAll(if TrackLow != 0 then TrackLow else Double.PoSITIVE_INFINITY);
def BottomIndex = HighestAll(if Low == Bottom then BarNumber() else Double.NaN);
def PriorBottom = LowestAll(if TrackLow > Bottom and BarNumber() < BottomIndex then TrackLow else Double.PoSITIVE_INFINITY);
plot Zig = zz;
zig.enableApproximation();
plot Current = Bottom;
Current.setdefaultColor(color.blue);
plot Prior = PriorBottom;
Prior.setdefaultColor(color.red);
plot Track = tracklow;
Track.setDefaultColor(color.green);
 
This might help as well

Code:
input Major_percentamount = .15;
input Major_revAmount = .2;
input Major_atrreversal = 3.75;
input Major_atrlength = 5;
def zz = ZigZagHighLow("price h" = high, "price l" = low, "percentage reversal" = Major_percentamount, "absolute reversal" = Major_revAmount, "atr length" = Major_atrlength, "atr reversal" = Major_atrreversal);

def ZigLow =
    if !isnan(zz) and BarNumber() != 1
    then zz == low
    else no
;
def TrackLow =
    if ZigLow then Low
    else if !TrackLow[1] then double.nan
    else TrackLow[1];
;
def Bottom = LowestAll(if TrackLow != 0 then TrackLow else Double.PoSITIVE_INFINITY);
def BottomIndex = HighestAll(if Low == Bottom then BarNumber() else Double.NaN);
def PriorBottom = LowestAll(if TrackLow > Bottom and BarNumber() < BottomIndex then TrackLow else Double.PoSITIVE_INFINITY);
plot Zig = zz;
zig.enableApproximation();
plot Current = Bottom;
Current.setdefaultColor(color.blue);
plot Prior = PriorBottom;
Prior.setdefaultColor(color.red);
plot Track = tracklow;
Track.setDefaultColor(color.green);
both of these solutions look amazing. Thank you both so much!!!!!
 
EDIT---6/15-------fixed

sorry for my bad code yesterday.
while passing some time in a hotel room, i tried to answer the question, by creating a study on my cell.
i try not to do that, as it's too easy for a typo to pop in, and a couple did.

here is a fixed study.
i added a 3rd lowest low.

Code:
# prev_lowest_0

def bn = barnumber();
def big = 999999;

#lowest low
def lo1 = lowestall(low);
def lo1bn = highestall(if low == lo1 then bn else 0);

# prev 1 low
def lo2 = lowestall(if bn < lo1bn then low else big);
def lo2bn = highestall(if low == lo2 and bn < lo1bn then bn else 0);

# prev 2 low
def lo3 = lowestall(if bn < lo2bn then low else big);
def lo3bn = highestall(if low == lo3 and bn < lo2bn then bn else 0);

addchartbubble( bn == lo1bn, low, "1\n" + lo1bn , color.green, no);
addchartbubble( bn == lo2bn, low, "2\n" + lo2bn , color.cyan, no);
addchartbubble( bn == lo3bn, low, "3\n" + lo3bn , color.yellow, no);

# test----------------------
addchartbubble(0 and bn <  lo1bn, low,
 low + "\n" +
 lo1bn + " 1bn\n" +
 lo2 + " lo2\n" +
 lo2bn + " 2bn"
, color.cyan);
#


green bubble is lowest low
cyan bubble is the next lowest price, on a bar that occurs before the lowest low.
yellow bubble is 3rd lowest low,...
1st row , is low # ( 1,2,3)
2nd row , is barnumber
NEE day
o33DNKn.jpg
Is There a way To catch the stochastic Full, values Either K or D , on the last two lowest values so that to be able to see if there is a divergence or convergence? Thank you very much!
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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