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


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:
Exceeded 2ATR by 0.5

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

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?

input length = 14;
def ATR =
            high(period = aggregationPeriod.DAY),
            close(period = aggregationPeriod.DAY),
            low(period = aggregationPeriod.DAY)
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 =
    or YelCnd
    or GryCnd
    if GrnCnd then
    else if YelCnd then
    else if GryCnd then
Last edited:

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