The percent distance between the current candle price and previous hl2

alexo2022

New member
I need help in creating a watchlist column that will show me how far is the distance between the current candle price,
to the previous candle hl2.

the end result will a percentage value, for example 39%, 80% and 100%.

100% will mean the current price and the previous hl2 are equal.
------------------------------------------------------------------------------------------

this is my plan:

1. to check if current price > previous hl2 or current price < previous hl2

if yes then

Option 1 - current price > previous hl2

Step1 - to reduce the current price with the previous hl2


current price - previous hl2 = [ here will be the value ] - we can define it as a "price_result_after_reduction_ver1"

option 1 - current price > previous hl2
option 2- current price < previous hl2

Step2 - to take result and calculate how much this value is in percentage from the value of the previous hl2

and then to create another value named - " price_afer_reduction_percentage_option1"

this value will be -

The result in % should be rounded
price_afer_reduction_percentage = [(price_result_after_reduction_ver1/previous hl2)*100]rounded

_________________________________________________________________________________________________________________________

Option 2 - current price < previous hl2

Step1 - to reduce the current price with the previous hl2


previous hl2 - current price = [ here will be the value ] - we can define it as a "price_result_after_reduction_ver2"


Step2 - to take result and calculate how much this value is in percentage from the value of the previous hl2

and then to create another value named - " price_afer_reduction_percentage_option2"

this value will be -

The result in % should be rounded
price_afer_reduction_percentage = [(price_result_after_reduction_ver2/previous hl2)*100]rounded

_______________________________________________________________________________________________________

I need help in putting it all together, or if there's another way to get the same result will be fine too.

thanks.
 
Solution
I need help in creating a watchlist column that will show me how far is the distance between the current candle price,
to the previous candle hl2.

the end result will a percentage value, for example 39%, 80% and 100%.

you did well in describing what you want. but you made it overly complicated.
all you need is 1 percent formula.

if you make a study to show positive and negative numbers, then both groups can be shown in 1 column.

this shows the % difference between the 2 prices.


Code:
# watchlist column study
def diff = close - hl2[1];
def diff_per = round(100 * diff/hl2[1], 1);

plot z = diff_per;
z.setdefaultcolor(color.black);

assignbackgroundcolor(if diff_per > 0 then color.green else if diff_per < 0 then...

halcyonguy

Well-known member
VIP
Lifetime
I need help in creating a watchlist column that will show me how far is the distance between the current candle price,
to the previous candle hl2.

the end result will a percentage value, for example 39%, 80% and 100%.

you did well in describing what you want. but you made it overly complicated.
all you need is 1 percent formula.

if you make a study to show positive and negative numbers, then both groups can be shown in 1 column.

this shows the % difference between the 2 prices.


Code:
# watchlist column study
def diff = close - hl2[1];
def diff_per = round(100 * diff/hl2[1], 1);

plot z = diff_per;
z.setdefaultcolor(color.black);

assignbackgroundcolor(if diff_per > 0 then color.green else if diff_per < 0 then color.red else color.gray);
#
 
Last edited:
Solution

alexo2022

New member
you did well in describing what you want. but you made it overly complicated.
all you need is 1 percent formula.

if you make a study to show positive and negative numbers, then both groups can be shown in 1 column.

this shows the % difference between the 2 prices.


Code:
def diff = close - hl2[1];
def diff_per = round(100 * diff/hl2[1], 1);

plot z = diff_per;
z.setdefaultcolor(color.black);

assignbackgroundcolor(if diff_per > 0 then color.green else if diff_per < 0 then color.red else color.gray);

thanks for your answer, you helped me a lot :)

I want to see the changes live, during the trading hours,
how can I change to see the last/current price, instead of close price ?
 

halcyonguy

Well-known member
VIP
Lifetime
thanks for your answer, you helped me a lot

I want to see the changes live, during the trading hours,
how can I change to see the last/current price, instead of close price ?

did you load it and check it?
why do you think close is not the current price?
in a column , the data used/displayed, comes from the last bar.
 

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.
Top