# 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
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:

#### 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);``````

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

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.

#### alexo2022

##### New member
Thanks for you help !

#### vivekshahi

##### New member
Hi, How can I convert this into a scan ?

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?