Daily ATR Support/Resistance Lines for ThinkorSwim

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?

Thanks for responding! Not sure, I'd have to see the Keltner Channels. Is that a simple indicator in TOS?

Ultimately, I think I am trying to see - intraday - possible "future" support and resistance levels based on ATR of previous 14 candles (10min each)

If I sound dumb, let me know.
 
Thanks for responding! Not sure, I'd have to see the Keltner Channels. Is that a simple indicator in TOS?

Ultimately, I think I am trying to see - intraday - possible "future" support and resistance levels based on ATR of previous 14 candles (10min each)

If I sound dumb, let me know.
So if we plot a horizontal line that is 1 ATR above the previous candle close, that would be actually be a little different than a Keltner Channel, which uses a moving average. I'll take a crack at coding this this afternoon.
 
Try this. It's not a changing horizontal line, but lines that connect each bar's "close +/- 1 ATR" value, which I think will be more helpful for you to see how it has worked over time. I looked only briefly, but I think if you tried to trade this consistently you'd get a lot of small winners and some large losers that wiped out your gains.
Code:
input length = 14;
input averageType = AverageType.WILDERS;

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

plot hatr = close[1] + ATR;
plot latr = close[1] - ATR;

hatr.SetDefaultColor(color = Color.DARK_RED);
latr.SetDefaultColor(color = Color.DARK_GREEN);
 
Try this. It's not a changing horizontal line, but lines that connect each bar's "close +/- 1 ATR" value, which I think will be more helpful for you to see how it has worked over time. I looked only briefly, but I think if you tried to trade this consistently you'd get a lot of small winners and some large losers that wiped out your gains.
Code:
input length = 14;
input averageType = AverageType.WILDERS;

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

plot hatr = close[1] + ATR;
plot latr = close[1] - ATR;

hatr.SetDefaultColor(color = Color.DARK_RED);
latr.SetDefaultColor(color = Color.DARK_GREEN);
Makes total sense and I agree - wouldn't trade this straight up. Wondering if possible to tweak slightly.

Would there be a way to show the two lines (above and below active candle) based on ONLY the previously closed candle?
That way there would be one set of lines (1 red, 1 green) on the current candle, based on the ATR of the previous 14.

I can set the Painting Strategy to something like this:
hatr.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); -- but that puts a small horizontal line above/below EVERY candle.

In my mind, only one pair of red/green lines would be visible at a time.
 
@C4men I'm sure there's a way to do that, but I don't know how off the top of my head, and to be honest I don't care much to put a lot of effort into figuring it out. If I were able to, it'd just be an inferior product anyway. It'd show the same thing the code I already made shows, just without being able to see where it was for previous candles also. So just less information for no reason... unless I'm misunderstanding something
 
@C4men I'm sure there's a way to do that, but I don't know how off the top of my head, and to be honest I don't care much to put a lot of effort into figuring it out. If I were able to, it'd just be an inferior product anyway. It'd show the same thing the code I already made shows, just without being able to see where it was for previous candles also. So just less information for no reason... unless I'm misunderstanding something
No worries. I appreciate all the help thus far. I'll continue to play around with it and see what I can figure out. Thank you!
 
plz can u make this renko atr?

Code:
# Renko
# Mobius

input brickSize = 10.0;

def c = close;
def bricks = CompoundValue(1, if c > bricks[1] + brickSize
then bricks[1] + brickSize
else if c < bricks[1] - brickSize
then bricks[1] - brickSize
else bricks[1] , bricks[1]);

plot bricks_ = Round(Bricks/TickSize(),0) * TickSize();
def mortar = CompoundValue(1, if bricks_ != bricks_[1]
then bricks_[1]
else mortar[1], mortar[1]);
plot mortar_ = Round(mortar/TickSize(),0) * TickSize();
AddCloud(bricks_, mortar_, color.green, color.red, yes);
# End Code
 
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);
Modified to correct ATRMultiplier to floating point also HighATR and LowATR where not taking ATRMultiplier

Code:
# https://usethinkscript.com/threads/daily-atr-support-resistance-lines-for-thinkorswim.3633/

input ATRperiod = 14;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1.0;
input ATRMultiplier2 = 2.0;
input ATRMultiplier3 = 3.0;
input ATRMultiplier4 = 4.0;

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 *  ATRMultiplier;
plot LowATR = DailyClose - ATR * ATRMultiplier;
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);

AddLabel(visible = Yes, text = "S2: " + Round(LowATR2, 2), color = Color.Green);
AddLabel(visible = Yes, text = "R2: " + Round(HighATR2, 2), color = Color.Red);
~
 
Is it possible to show only the latest plots and hide for previous day? I find past data points clutter the chart too much. Thanks
 
i'd love to know this, too, but only to show the previous days and not the current day.

This has an input showplots that is defaulted to all or a choice between prior_only or current_only

The image shows prior_only plots

Screenshot-2023-02-22-090831.png
Code:
# https://usethinkscript.com/threads/daily-atr-support-resistance-lines-for-thinkorswim.3633/

input showplots = {default all, current_only, prior_only};
input showcurrentonly = yes;
input ATRperiod = 14;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1.0;
input ATRMultiplier2 = 2.0;
input ATRMultiplier3 = 3.0;
input ATRMultiplier4 = 4.0;

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

def DailyClose = if showplots == showplots.prior_only and GetDay() == GetLastDay() then Double.NaN else if showplots == showplots.current_only and GetDay() != GetLastDay() then Double.NaN else close(period = ”DAY”)[1];
plot HighATR = DailyClose + ATR *  ATRMultiplier;
plot LowATR = DailyClose - ATR * ATRMultiplier;
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);


def DC = close(period = ”DAY”)[1];
def HighATR_ = DC + ATR *  ATRMultiplier;
def LowATR_ = DC - ATR * ATRMultiplier;
def HighATR2_ = DC + ATR * ATRMultiplier2;
def LowATR2_ = DC - ATR * ATRMultiplier2;

#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);

AddLabel(visible = yes, text = "S2: " + Round(LowATR2_, 2), color = Color.GREEN);
AddLabel(visible = yes, text = "R2: " + Round(HighATR2_, 2), color = Color.RED);
;
 
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);
First of all I love this indicator, especially the DTR, I use it for breakouts, second is there a way to make the label that show the percentage into a watchlist column?
 

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
333 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