 # Help with 60/40 percent of candle to show as label

#### germanburrito

##### Active member
Is there a way to have a label that turns green if price hits 60 percent or above the current candle, or red if 40 percent or below the current candle. i have this so far.

Code:
``````# germanburrito

def bound_high = high ;
def bound_low = low ;
def difference = bound_high - bound_low;
def T = difference* .4;
def L = difference* .6;
def up = bound_low + L;
def down = bound_low + T;

AddLabel(yes, Concat(" 60 UP = ", down), Color.yellow);
AddLabel(yes, Concat(" 60 Down = ", up), Color.yellow);``````

Last edited by a moderator:

#### XeoNoX

##### Well-known member
VIP
What you are referring to is called the ATR ( Average True Range ) of the candle.
Shows the average of the true range for Current Candle and percent of range relative to the the current price (close) and allows to change label color based of percentage threshold input

In the input you can change your percentage threshold in the input as well, i set it for you values you requested. Remember to hit the like button if you found this post useful. Code:
``````declare upper;
#min percentage required for green color (greater than)
input upper_threshold = 60;
#max percentage required for red color (lower than)
input lower_threshold = 40;

def range1 = high-low;
Def range2 = low -close;
def percent=  absValue(range2/range1)*100;

AddLabel(yes, "Price is " + round(percent)+ "%" + " of Current Range of " + Range1 ,if percent > upper_threshold then color.uptick else if percent < lower_threshold then color.dark_red else color.white);``````

Last edited:
• germanburrito and BenTen

#### germanburrito

##### Active member
@XeoNoX thank you a bunch sir!

#### XeoNoX

##### Well-known member
VIP
@XeoNoX thank you a bunch sir!
i just realized the formula is off... do you have the formula ? or know of a website with the formula to get percentage of the range from the current price? if you do i can plug it in for you.

#### germanburrito

##### Active member
i just realized the formula is off... do you have the formula ? or know of a website with the formula to get percentage of the range from the current price? if you do i can plug it in for you.
actually i sorta figuere it out, basically waht i wanted to do was inplent the strat strategy, its a cool concept to see basic price movement, but inotice that when a candle goes above or below 60 percent of the previous candle theres a much bigger chance the stock will keep goin in that direction heres the simple code i have
Code:
``````# germanburrito
# 60% candle direction.
def bound_high = high ;
def bound_low = low ;
def difference = bound_high - bound_low;
def T = difference* .4;
def L = difference* .6;
def up = bound_low + L;
def down = bound_low + T;

def U = close >= up ;
def D = close <= down;

AddLabel( U, " up 60% " , Color.Green);
AddLabel( D, " DOWN 60%" , Color.Red);``````

• ALV and zeek

#### XeoNoX

##### Well-known member
VIP
I updated the code in post#2. I think I have the formula correct now.

• germanburrito

#### germanburrito

##### Active member
I updated the code in post#2. I think I have the formula correct now.
once again thank you so much, i am trying to implement this using the STRAT strategy.

• XeoNoX