ATR Quick Calculator?


New member
Hi all,

I am VERY new to thinkscript and I am working on how to code an ATR quick calculator but can't seem to figure it out. I've created it in excel but can't figure out how to translate it to a chart bubble in ToS. Essentially, what I am looking for is a way to use a multiple (1.5 for example) of the current ATR to figure out the number of ticks (rounded to the tick size of the security) for stop-loss and take profit with the ATR multiple as an input. I am really only going to be using this for trading futures in S&P, DOW, Russel2k, and the Nasdaq if that's helpful at all. (micros- /MYM /MES /MNQ /M2k and the minis- /ES /YM /NQ /RTY). Again, I'm not sure if this is helpful at all but I would only be really using this during regular trading hours, NOT during extended hours/overnight.

For example, if the current price of the /MYM is trading at 34,400 and the ATR is 9.5, I'd like a chat bubble that shows the following:

[(current ATR multiple), STOP: XXXXX, TICK: XXXXX, Target: XXXXX] or with using that example above [(1.5), STOP: 34414, TICK: 14, TARGET: 34386}

This is what I have coded so far:

#Default values are set to trade /MYM- is it possible to dynamically change the tick size and value based on what symbol is on the chart? Ideally, I'd only like to have to change the ATR Length and the multiple.
input ATRLength = 14;
input ATRmultiple = 1.5;
input TickSize = 1;
input TickValue= .50;

#Calculating ATR value
def ATR = Average(TrueRange(high, close, low), ATRLength);

#Calulating ATR with multiple
def ATRMulti = (ATR * ATRmultiple);

#Define currentprice
def CP = close(pricetype.last);

#Define stop and target
def Stop = absvalue(ATRMulti - CP);
def Target = absvalue(ATRMulti + CP);

#define number of ticks
def TickNum = (CP - Stop);

#ATR Multiple, number of ticks, STOP/TARGET label
addlabel(yes, ( ATRmulti =(ATRMulti), "STOP:" =Stop, "TICK:" =TickNum, "TARGET:" =Target) , color.yellow);

Is what I'm asking about possible in ToS? I think my biggest challenge right now is figuring out how to code the current price and how to format the chart code itself. As of right now, all I'm getting is N/A on the chart bubble. I know there is probably ALOT missing so any help would be greatly appreciated!!

Thanks everyone!
@AntCar This will only round atr down to nearest tick and not up. You can add more logic to ATRtick to make it round up as well.
input ATRmultiple = 1.5;
input length = 14;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);

#Calulating ATR with multiple
def ATRMulti = (ATR * ATRmultiple);

#Round down to nearest ticksize
def ATRtick = if ticksize() == .01 then ATRmulti else ATRMulti - (ATRMulti % ticksize());

#Define currentprice
def CP = close;

#Define stop and target
def Stop = CP - ATRtick;
def Target = CP + ATRtick;

#ATR Multiple, number of ticks, STOP/TARGET label
addlabel(yes, "STOP:" + Stop + "TICK:" + ATRtick + "TARGET:" + Target , color.yellow);

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