Daily ATR Support/Resistance Lines for ThinkorSwim

Hey all,

Created this simple "indicator" that draws lines at the previous day's close and the daily ATR levels. These often act as support/resistance, as in general the market stays within the ATR. If the price gets above/below these levels then it is unlikely to continue moving very far in that direction unless there is very strong buying/selling pressure.

Code:
input length = 14;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high(period=”DAY”)[1], close(period=”DAY”)[1], low(period=”DAY”)[1]), length);

plot DailyClose = close(period=”DAY”)[1];
plot hatr = dailyclose + ATR;
plot latr = dailyclose - ATR;
 
Last edited by a moderator:
I edited it to add lines for the current day's trading range vs the ATR, which can be indicative that moves won't continue or will reverse soon in the same way. Also added a label to show the % that the day's trading range has fulfilled the average trading range.

Code:
input length = 14;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;

def ATR = MovingAverage(averageType, TrueRange(high(period=”DAY”)[1], close(period=”DAY”)[1], low(period=”DAY”)[1]), length);
def Today_High = Highest(high(period = baseperiod)[0], 1);
def Today_Low = Lowest(low(period =baseperiod)[0], 1);
def DR = Today_High - Today_Low;

plot DailyClose = close(period=”DAY”)[1];
plot hatr = dailyclose + ATR;
plot latr = dailyclose - ATR;
plot hdtr = Today_Low + ATR;
plot ldtr = Today_High - ATR;

AddLabel(visible = Yes, text = "DTR: " + round(DR/ATR, 2)*100 + "%", color = Color.LIGHT_GRAY);
 
Last edited by a moderator:
Hi TraderKevin, I´m glad I found this thread. I am looking for something similar, based on my day trading strategy, I found using ATR´s as support and resistance is pretty powerful and simple at the same time, especially if you combine them with meaningful areas of support/resistance and VWAP. Your idea is very similar to mine, this is what I have in mind:
  1. Plot daily ATR from today (period:14), using daily close from today, for tomorrow's price activity
  2. 4 different ATR plots, with length being the variable value differentiating each ATR
  3. Horizontal lines plot on 15 min time frame or less
  4. Any of the 4 ATR's can be turned on / off from the studies menu
  5. Any of the 4 ATR length's can be modified from the studies menu
  6. Include label with S1 and R1 values and with ATR % (useful to determine volatility = (ATR/Close)*100 - in percentage )
Below an example on CWH ATRs lines :

uKnJFVw.png

KEg3MXi.png

WNFXsBy.png


Don´t mind the blue closing price line, I don´t think is very useful. I think fine dotted lines is cleaner. Hopefully you find it interesting and want to write the code. Best of luck!
 
Hi TraderKevin, I´m glad I found this thread. I am looking for something similar, based on my day trading strategy, I found using ATR´s as support and resistance is pretty powerful and simple at the same time, especially if you combine them with meaningful areas of support/resistance and VWAP. Your idea is very similar to mine, this is what I have in mind:
  1. Plot daily ATR from today (period:14), using daily close from today, for tomorrow's price activity
  2. 4 different ATR plots, with length being the variable value differentiating each ATR
  3. Horizontal lines plot on 15 min time frame or less
  4. Any of the 4 ATR's can be turned on / off from the studies menu
  5. Any of the 4 ATR length's can be modified from the studies menu
  6. Include label with S1 and R1 values and with ATR % (useful to determine volatility = (ATR/Close)*100 - in percentage )
Below an example on CWH ATRs lines :

uKnJFVw.png

KEg3MXi.png

WNFXsBy.png


Don´t mind the blue closing price line, I don´t think is very useful. I think fine dotted lines is cleaner. Hopefully you find it interesting and want to write the code. Best of luck!

So, if I understand correctly, you want the following as compared to my original study:
  • Use just the ATR based on previous day's close, leaving out the daily trading range
  • 4 ATR lines that are different based on length? What do you mean by length? The period (ie, one based on 14 period ATR, one on 9, 5, and 20, or something like that?) Or do you mean to introduce a multiplier (ie, 1 x ATR, 1.25 x ATR, 1.5 x ATR, 1.75 x ATR)?
  • include labels for S1 and R1 pivot points, and for ATR/Close * 100 (which will by definition not change much throughout the day, as compared to the formula I used in my original study which shows the percentage of the ATR that has been filled by the current day's trading action). Also, what formula would you like me to use for S1 and R1? There are several slightly different pivot point formulas folks use.

It sounds like this should be pretty easy once I fully understand the above.
 
Yeah I think is pretty easy one
  • Use just the ATR based on previous day's close, leaving out the daily trading range
  • that is correct
  • 4 ATR lines that are different based on length? What do you mean by length? The period (ie, one based on 14 period ATR, one on 9, 5, and 20, or something like that?) Or do you mean to introduce a multiplier (ie, 1 x ATR, 1.25 x ATR, 1.5 x ATR, 1.75 x ATR)?
  • I mean 4 upper ATRs (ATRX1 ATRX2 ATRX3 ATRX4) And same for lower atrs. The reason is I´ve seen a few cases when a stock is ripping or getting destroyed and runs 3 or even 4 atrs.
  • Include labels for S1 and R1 pivot points, and for ATR/Close * 100 (which will by definition not change much throughout the day, as compared to the formula I used in my original study which shows the percentage of the ATR that has been filled by the current day's trading action). Also, what formula would you like me to use for S1 and R1? There are several slightly different pivot point formulas folks use.
  • In the pics I sent you, S1 = Lower ATR1 as support and R1 = Upper ATR1 as resistance.
  • I find it very useful to determine if a stock has volatility (for next day trading) or not based on it´s ATR%, so based on my experience 5%+ indicates good volatility. That percentage is useful. This is the table I use to plan my trading for the next day: https://prnt.sc/uie7ov
 
Try this out:

Code:
input ATRperiod = 14;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1;
input ATRMultiplier2 = 2;
input ATRMultiplier3 = 3;
input ATRMultiplier4 = 4;

def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRperiod);


def DailyClose = close(period = ”DAY”)[1];
plot HighATR = DailyClose + ATR;
plot LowATR = DailyClose - ATR;
plot HighATR2 = DailyClose + ATR * ATRMultiplier2;
plot LowATR2 = DailyClose - ATR * ATRMultiplier2;
plot HighATR3 = DailyClose + ATR * ATRMultiplier3;
plot LowATR3 = DailyClose - ATR * ATRMultiplier3;
plot HighATR4 = DailyClose + ATR * ATRMultiplier4;
plot LowATR4 = DailyClose - ATR * ATRMultiplier4;

HighATR.SetDefaultColor(color = Color.RED);
HighATR2.SetDefaultColor(color = Color.RED);
HighATR3.SetDefaultColor(color = Color.RED);
HighATR4.SetDefaultColor(color = Color.RED);
LowATR.SetDefaultColor(color = Color.GREEN);
LowATR2.SetDefaultColor(color = Color.GREEN);
LowATR3.SetDefaultColor(color = Color.GREEN);
LowATR4.SetDefaultColor(color = Color.GREEN);

HighATR.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR4.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR4.SetPaintingStrategy(PaintingStrategy.DASHES);


AddLabel(visible = yes, text = "ATR: " + Round(ATR / close * 100, 2)  + "%", color = Color.LIGHT_GRAY);
AddLabel(visible = Yes, text = "S1: " + Round(LowATR, 2), color = Color.Green);
AddLabel(visible = Yes, text = "R1: " + Round(HighATR, 2), color = Color.Red);
 
That is awesome, Thank you!
One question, for the label, how can I change it so it shows next day´s ATR% and S1 R1?
 
That is awesome, Thank you!
One question, for the label, how can I change it so it shows next day´s ATR% and S1 R1?

Since those are calculated based off the day's closing price, you can't calculate the next day's values until the current day closes. If this is what you are wanting to see, then use the following code for the labels instead, just knowing that the values will be updating throughout the current day but won't be correct until the market closes:

Code:
AddLabel(visible = yes, text = "ATR: " + Round(ATR[-1] / close[-1] * 100, 2)  + "%", color = Color.LIGHT_GRAY);
AddLabel(visible = Yes, text = "S1: " + Round(LowATR[-1], 2), color = Color.Green);
AddLabel(visible = Yes, text = "R1: " + Round(HighATR[-1], 2), color = Color.Red);

Also, just as a note, the more I use both ATR and the Daily trading range compared to ATR (see my updated study above), the more I realize that the daily trading range is the better support/resistance. I'd encourage you to try out this instead. It updates throughout the day as new daily highs/lows are created and seems far better. For example, look at how it did on Monday (September 14th) on the SPY... it acted as strong resistance as the price bounced off it at least 6 times and never broke it.
 
Last edited:
Sweet, thank you TraderKevin, you´re the man!

That sounds very interesting, I´ll check it out and let you know. I day trade stocks and options, I don´t trade penny stocks, I trade mainly Nasdaq tech stocks and some large and small caps. I also swing trade. I learned from Brian Shanon, SMB Capital and Kunal Desai. How about you?
 
Last edited by a moderator:
Is it possible to modify this indicator to display % change instead of ATR? So looking for lines to display % change positive and negative from the previous day close in increments of 0.25% to 2% or 3%
 
Is it possible to modify this indicator to display % change instead of ATR? So looking for lines to display % change positive and negative from the previous day close in increments of 0.25% to 2% or 3%

Sorry, but I'm not sure what you mean. % change of what.. the stock price from the previous day's close? If so, that's the regular % Change feature in thinkorswim (and every other website/platform) is. You just want lines drawn on the chart that show where each 0.25% change is?
 
Correct, draw lines at 0.25 % change from yesterday's close. So draw a line at 0.25, 0.50, 0.75, etc from yesterday's closing price. And the same in the negative direction.
 
Correct, draw lines at 0.25 % change from yesterday's close. So draw a line at 0.25, 0.50, 0.75, etc from yesterday's closing price. And the same in the negative direction.
Kinda sorta like a VWAP with Standard Deviations, but based on yesterdays close... Hmmm...
 
Kinda sorta like a VWAP with Standard Deviations, but based on yesterdays close... Hmmm...

That's not what I got from what he said. Think he literally just wants to have horizontal lines at each 0.25% interval from previous day's close. I think these lines would be irrelevant and just clutter up the chart big time. Not something I'm interested in, personally.
 
@alvaro hi, I m looking something similar to show the ATR plot at horizontal levels on Daily timeframe, do u mind sharing the script for your plot? thank u
 
@alvaro hi, I m looking something similar to show the ATR plot at horizontal levels on Daily timeframe, do u mind sharing the script for your plot? thank u
Sure Nick:

Code:
input ATRperiod = 14;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1;
input ATRMultiplier2 = 2;
input ATRMultiplier3 = 3;
input ATRMultiplier4 = 4;

def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRperiod);


def DailyClose = close(period = ”DAY”)[1];
plot HighATR = DailyClose + ATR;
plot LowATR = DailyClose - ATR;
plot HighATR2 = DailyClose + ATR * ATRMultiplier2;
plot LowATR2 = DailyClose - ATR * ATRMultiplier2;
plot HighATR3 = DailyClose + ATR * ATRMultiplier3;
plot LowATR3 = DailyClose - ATR * ATRMultiplier3;
plot HighATR4 = DailyClose + ATR * ATRMultiplier4;
plot LowATR4 = DailyClose - ATR * ATRMultiplier4;

HighATR.SetDefaultColor(color = Color.RED);
HighATR2.SetDefaultColor(color = Color.RED);
HighATR3.SetDefaultColor(color = Color.RED);
HighATR4.SetDefaultColor(color = Color.RED);
LowATR.SetDefaultColor(color = Color.GREEN);
LowATR2.SetDefaultColor(color = Color.GREEN);
LowATR3.SetDefaultColor(color = Color.GREEN);
LowATR4.SetDefaultColor(color = Color.GREEN);

HighATR.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR4.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR4.SetPaintingStrategy(PaintingStrategy.DASHES);


AddLabel(visible = yes, text = "ATR: " + Round(ATR / close * 100, 2) * 100 + "%", color = Color.LIGHT_GRAY);
 
Try this out:

Code:
input ATRperiod = 14;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1;
input ATRMultiplier2 = 2;
input ATRMultiplier3 = 3;
input ATRMultiplier4 = 4;

def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRperiod);


def DailyClose = close(period = ”DAY”)[1];
plot HighATR = DailyClose + ATR;
plot LowATR = DailyClose - ATR;
plot HighATR2 = DailyClose + ATR * ATRMultiplier2;
plot LowATR2 = DailyClose - ATR * ATRMultiplier2;
plot HighATR3 = DailyClose + ATR * ATRMultiplier3;
plot LowATR3 = DailyClose - ATR * ATRMultiplier3;
plot HighATR4 = DailyClose + ATR * ATRMultiplier4;
plot LowATR4 = DailyClose - ATR * ATRMultiplier4;

HighATR.SetDefaultColor(color = Color.RED);
HighATR2.SetDefaultColor(color = Color.RED);
HighATR3.SetDefaultColor(color = Color.RED);
HighATR4.SetDefaultColor(color = Color.RED);
LowATR.SetDefaultColor(color = Color.GREEN);
LowATR2.SetDefaultColor(color = Color.GREEN);
LowATR3.SetDefaultColor(color = Color.GREEN);
LowATR4.SetDefaultColor(color = Color.GREEN);

HighATR.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
HighATR4.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR2.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR3.SetPaintingStrategy(PaintingStrategy.DASHES);
LowATR4.SetPaintingStrategy(PaintingStrategy.DASHES);


AddLabel(visible = yes, text = "ATR: " + Round(ATR / close * 100, 2)  + "%", color = Color.LIGHT_GRAY);
AddLabel(visible = Yes, text = "S1: " + Round(LowATR, 2), color = Color.Green);
AddLabel(visible = Yes, text = "R1: " + Round(HighATR, 2), color = Color.Red);

Please forgive me for what I am about to ask, but this script is pretty close to something I have been wondering if possible.

Would there be any way to create these lines intraday (dynamically), based on the previous 14 closed candles?
My example would be something like:
  • I'm on a 10-min timeframe (day trading)
  • Indicator starts the lookback at the previous (completed) candle, and goes back the traditional 14 candles for ATR
  • Paints two lines based on that previously close candle
    • First Line - 1 ATR above
    • Second Line - 1 ATR below
  • Lines would "extend" to the right, acting as support and resistance
  • Lines would repaint each time a candle closes on the intraday chart
  • Then, the same ATR multiple lines (as in above code) could be added as well
I know this is a lot, but your code rocks and you seem to have a pretty good grasp, so I figured I would ask.
 
If I understand correctly, what you want is a Keltner Channel, except that the bands of a KC don't extend to the right (no reason to), and the channel shows a history of where the +/- 1 ATR values have been at each candle rather than updating at each candle and only showing the newest value.

If I'm understanding correctly, it would seem the KC would be more helpful, no?
 

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
223 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.
Back
Top