Label candles with consecutive high or low

IB78

New member
New to this forum. Also has no coding experience. I want to label/draw line between consecutive candle bars (HA candle) that has same high or low. I got this part of this code from post on this forum together with the learning center. But the code only label a small percentage of those bars. Those bars with same high/low that were not identified by the code were marked with arrow below or under. These were identified based on the high/low readings on the chart up to 2 decimal points. Please see attached screenshot. Below is the code, could someone kindly help me to troubleshoot this?

zkty1IE.png


plot LowestClose = if Round(low[1]) == Round(low) then round(low) else double.NaN;
plot HighestClose = if Round(high[1]) == Round(high) then round(high) else double.NaN;
 
Solution
New to this forum. Also has no coding experience. I want to label/draw line between consecutive candle bars (HA candle) that has same high or low. I got this part of this code from post on this forum together with the learning center. But the code only label a small percentage of those bars. Those bars with same high/low that were not identified by the code were marked with arrow below or under. These were identified based on the high/low readings on the chart up to 2 decimal points. Please see attached screenshot. Below is the code, could someone kindly help me to troubleshoot this?


plot LowestClose = if Round(low[1]) == Round(low) then round(low) else double.NaN;
plot HighestClose = if Round(high[1]) == Round(high) then...
New to this forum. Also has no coding experience. I want to label/draw line between consecutive candle bars (HA candle) that has same high or low. I got this part of this code from post on this forum together with the learning center. But the code only label a small percentage of those bars. Those bars with same high/low that were not identified by the code were marked with arrow below or under. These were identified based on the high/low readings on the chart up to 2 decimal points. Please see attached screenshot. Below is the code, could someone kindly help me to troubleshoot this?


plot LowestClose = if Round(low[1]) == Round(low) then round(low) else double.NaN;
plot HighestClose = if Round(high[1]) == Round(high) then round(high) else double.NaN;

maybe this test program will help show what is happening.
it looks for 2 price levels that are within some amount ( default is 0.01 )

your condition is comparing the current bar to a the previous bar. so the 1st bar in a same price series won't be found.
need to add a check to see if it is the first bar and if the next bar is true.

i didn't try this on HA bars, but the principle is the same.

Code:
# within_x_price_0

# to start a line from a bar, it needs a true condition.
# include a line segment before the first condition bar, need to check a condition on the next bar.
#  if (isnan(HighestClose[1]) and absvalue( high[-1] - high[0] ) < within_price )

input within_price = 0.01;

#plot LowestClose = if Round(low[1]) == Round(low) then round(low) else double.NaN;
#plot HighestClose = if Round(high[1]) == Round(high) then round(high) else double.NaN;

def HighestClose = if (isnan(HighestClose[1]) and absvalue( high[-1] - high[0] ) < within_price ) or  absvalue( high[0] - high[1] ) < within_price then high else double.NaN;

def LowestClose =  if (isnan(lowestclose[1]) and absvalue( low[-1] - low[0] ) < within_price ) or absvalue( low[0] - low[1] ) < within_price then low else double.NaN;


plot zh = HighestClose;
plot zl = LowestClose;
zh.setdefaultcolor(color.white);
zl.setdefaultcolor(color.white);

#--------------------------
input test_vertical_lines = no;
addverticalline(test_vertical_lines and !isnan(HighestClose), "-", color.green);
addverticalline(test_vertical_lines and !isnan(lowestClose), "-", color.red);
#

mJ8NAtw.jpg
 
Last edited:
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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