# How to code label that shows current daily bar exceeded 2ATR by x%?

#### c0der

##### Member
I want the label to show on my 1D5Min chart, but the study is based on Daily bar.

E.g. Current SPX Daily Bar Range = 62.81
1ATR = 32.28 today

Label will show either 1 of these:
Code:
``````#greenlabel
Exceeded 2ATR by 0.5

#yellowlabel
Between 90% to 99.9% of 2ATR Range
In this example it is 96%

#greylabel
Below 90% of 2ATR``````

Something like this should at least get you started, I didn't give it much thought to be honest. You might have to tweak it. I just used less than but not equal to at the top of the yellow threshold, I assume that is what you meant by %99.9. There is also no contingency if the range is greater than 2ATR but not by more than 0.5, so I added in a little error handler. Also, 0.5 of what? I used raw price, did you mean half a percent, 0.5 also translates to %50, or something else possibly?

Ruby:
``````input length = 14;
def ATR =
MovingAverage(
AverageType.WILDERS,
TrueRange(
high(period = aggregationPeriod.DAY),
close(period = aggregationPeriod.DAY),
low(period = aggregationPeriod.DAY)
),
length
)
;
def ATRx2 =
ATR * 2
;
def Range =
high(period = aggregationPeriod.DAY) -
low(period = aggregationPeriod.DAY)
;
def GrnCnd =
Range > (ATRx2) + 0.5
;
def YelCnd =
Range >= (ATRx2) * .9
and Range < ATR * 2
;
def GryCnd =
Range < (ATRx2) * .9
;
def ShowLabel =
GrnCnd
or YelCnd
or GryCnd
;
ShowLabel,
"ATR THINGIE",
if GrnCnd then
color.green
else if YelCnd then
color.yellow
else if GryCnd then
color.gray
else
color.RED
);
!ShowLabel,
"Error",
Color.RED
);``````

Last edited:
this example is good enough! thank you so much!

87k+ Posts
407 Online

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