simple code for % bar close from high/low

offshore

Member
Hey im tinkering with simple code to figure this out but cant seem to get what i want. Im just trying to get an indicator for the % a bull bar closes from its high as well as the % a bear bar closes from its low when I hover over any bar on a 5 minute chart.

plot pctCloseFromHigh = (high - close);.... ;
plot pctCloseFromLow = (close - low);

these are the 2 lines but cant seem to get the value i want in percentage. any help would be great, thanks
 
Last edited by a moderator:
Solution
Hey im tinkering with simple code to figure this out but cant seem to get what i want. Im just trying to get an indicator for the % a bull bar closes from its high as well as the % a bear bar closes from its low when I hover over any bar on a 5 minute chart.

plot pctCloseFromHigh = (high - close);.... ;
plot pctCloseFromLow = (close - low);

these are the 2 lines but cant seem to get the value i want in percentage. any help would be great, thanks

here is another version, that compares the price difference of close to x , to the height of the candle, ( not the price )

Code:
def ht = high - low;
def isup = (close > open);
def isdwn = (close < open);
# remove the *100, so will be #s < 1, so won't show up over candles
def hi_per...
Hey im tinkering with simple code to figure this out but cant seem to get what i want. Im just trying to get an indicator for the % a bull bar closes from its high as well as the % a bear bar closes from its low when I hover over any bar on a 5 minute chart.

plot pctCloseFromHigh = (high - close);.... ;
plot pctCloseFromLow = (close - low);

these are the 2 lines but cant seem to get the value i want in percentage. any help would be great, thanks

Name this study as Pct and place it at the top of the studies on your chart so that it appears as shown when you hover over any bar.

Screenshot-2022-12-17-112246.png
Ruby:
#Pct
plot pct = if close >= open
           then round((high - close) / close * 100)
           else if close < open
           then round((close - low) / low * 100)
           else Double.NaN;
pct.assignvalueColor(
if close>=open
then color.light_green
else color.light_red);
;
 
Hey im tinkering with simple code to figure this out but cant seem to get what i want. Im just trying to get an indicator for the % a bull bar closes from its high as well as the % a bear bar closes from its low when I hover over any bar on a 5 minute chart.

plot pctCloseFromHigh = (high - close);.... ;
plot pctCloseFromLow = (close - low);

these are the 2 lines but cant seem to get the value i want in percentage. any help would be great, thanks

here is another version, that compares the price difference of close to x , to the height of the candle, ( not the price )

Code:
def ht = high - low;
def isup = (close > open);
def isdwn = (close < open);
# remove the *100, so will be #s < 1, so won't show up over candles
def hi_per = round((high - close) / ht, 2);
def lo_per = round((close - low) / ht, 2);

plot pct = if isup then hi_per
           else if isdwn then lo_per
           else min(hi_per, lo_per);
pct.assignvalueColor(
  if isup then color.light_green
  else if isdwn then color.light_red
  else color.white);

input test1 = no;
addchartbubble(test1, low,
pct
, (if isup then color.light_green
  else if isdwn then color.light_red
  else color.white), no);
#
 
Solution
sorry, not sure what you are asking for. i'm not familiar with futures.
Thank you. I trade on 3minute candles. At the close of each candle, I was hoping to see how many points that candle was. It would be a quicker visual than having to manually figuring that out. This can be helpful when studying pull backs. Hope that makes more sense.
 
Thank you. I trade on 3minute candles. At the close of each candle, I was hoping to see how many points that candle was. It would be a quicker visual than having to manually figuring that out. This can be helpful when studying pull backs. Hope that makes more sense.
sorry, no it doesn't, you will have to describe your question more thoroughly
( for me anyway, i deal in dollars with stocks)
are points the same as dollars?
..that candle was.. was what? its height, high to low? or body height?
what do you want to see? a bubble above every candle? a label to show just the last candle?
 
sorry, no it doesn't, you will have to describe your question more thoroughly
( for me anyway, i deal in dollars with stocks)
are points the same as dollars?
..that candle was.. was what? its height, high to low? or body height?
what do you want to see? a bubble above every candle? a label to show just the last candle?
Thanks again for replying back. Futures points are in general the same as stock. If the candles high is 3950 and the low was 3940, then that candle was 10 points. A label on the last candle would be ideal. Thanks again for checking this out.
 
Thanks again for replying back. Futures points are in general the same as stock. If the candles high is 3950 and the low was 3940, then that candle was 10 points. A label on the last candle would be ideal. Thanks again for checking this out.

i think i was making this too hard...
does this do what you want ?

Code:
input label_last_bar_height = yes;
def rnd = 2;
def ht = round(high - low, rnd);
addlabel( label_last_bar_height , "Ht " + ht, color.yellow);
#
 
Last edited:
Maybe one more request, please. Can you code to add the last two candles instead of just the last one? Thanks!


this will show labels with the candle height of up to the last 6 candles.
the labels will be colored, based on if the current bar height is great or less than the previous bar, ( green or red).

can pick the quantity of heights to show , 1 to 6.
if a number out of the range is picked, it picks a valid number.


Code:
# bar_heights_6x_02

input label_last_bar_height = yes;
input bars_to_show = 2;
#hint bars_to_show: enter a number 1 to 6. if a number is out of the range, a 1 or 6 will be chosen.

def bars = if bars_to_show < 1 then 1
  else if bars_to_show > 6 then 6
  else bars_to_show;

def rnd = 2;
def ht = Round(high - low, rnd);
def hthigher = (ht > ht[1]);

addlabel( label_last_bar_height, " ", color.black);
addlabel( label_last_bar_height and bars >= 6 , "Ht " + ht[5], (if hthigher[5] then color.green else color.red));
addlabel( label_last_bar_height and bars >= 5 , "Ht " + ht[4], (if hthigher[4] then color.green else color.red));
addlabel( label_last_bar_height and bars >= 4 , "Ht " + ht[3], (if hthigher[3] then color.green else color.red));
addlabel( label_last_bar_height and bars >= 3 , "Ht " + ht[2], (if hthigher[2] then color.green else color.red));
addlabel( label_last_bar_height and bars >= 2 , "Ht " + ht[1], (if hthigher[1] then color.green else color.red));
addlabel( label_last_bar_height , "Ht " + ht, (if hthigher[0] then color.green else color.red));
#

TQ8JThJ.jpg
 

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
346 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