ATR-Based Support & Resistance for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Our research showed that securities usually stay in their ATR. It is about 4.8% days when security is goes out of ATR. So we are using this feature in our trading, when security is out of their 70% of ATR we are looking for signals to trade backward. This indicator could show you when bars are close to ATR.
By default, the indicator uses the "DAY" option. However, if you would like to play around with other timeframe aggregation, then you can do so from the indicator's setting. I found it interesting when applying the Monthly or OPT_EXP (aggregation period equal to option expiration) onto the Daily chart.




thinkScript Code

Code:
# ATR Grid (ATR-Based Support & Resistance)
# Assembled by BenTen and @diazlaz at useThinkScript.com
# Converted from https://www.tradingview.com/script/EDN4oFyQ-ATR-0-5-0-7-ranges/

input lvl1 = 0.5;
input lvl2 = 0.7;
input daily_atr_len = 15;

input length = 15;
input AggPeriod = AggregationPeriod.DAY;
input averageType = AverageType.WILDERS;

def h = high(GetSymbol(), period = AggPeriod)[1];
def c = close(GetSymbol(), period = AggPeriod)[1];
def l = low(GetSymbol(), period = AggPeriod)[1];

def atr_func = MovingAverage(averageType, TrueRange(h, c, l), length);
def day_atr = atr_func;
def day_close = c;

plot p1 = day_close + day_atr;
p1.assignValueColor(COLOR.DARK_RED);
p1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot p7 = day_close + day_atr * lvl2;
p7.assignValueColor(COLOR.RED);
AddCloud(p1, p7, COLOR.DARK_RED, COLOR.DARK_RED);
p7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot p5 = day_close + day_atr * lvl1;
p5.assignValueColor(COLOR.RED);
AddCloud(p7, p5, COLOR.RED, COLOR.RED);
p5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot m5 = day_close - day_atr * lvl1;
m5.assignValueColor(COLOR.GREEN);
#AddCloud(p7,p5,COLOR.GREEN, COLOR.GREEN);
m5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot m7 = day_close - day_atr * lvl2;
m7.assignValueColor(COLOR.GREEN);
AddCloud(m7, m5, COLOR.GREEN, COLOR.GREEN);
m7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot m1 = day_close - day_atr;
m1.assignValueColor(COLOR.DARK_GREEN);
AddCloud(m1, m7, COLOR.DARK_GREEN, COLOR.DARK_GREEN);
m1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Last edited:
J

john3

Active member
2019 Donor
@BenTen Is that an ATR multiplier?

input length = 15;
 
BenTen

BenTen

Administrative
Staff
VIP
@john3 Correct. Ignore the input daily_atr_len. That was included by mistake. Use the regular length like you mentioned :)
 
horserider

horserider

Well-known member
VIP
Not a multiplier as far as I can tell. It is the length of the true range moving average.
 
horserider

horserider

Well-known member
VIP
Yes if 15 it would be a 15 period moving average. Red top plot is the close + ATR. Then it plots next lower lines at .7 and then .5 of that first close + ATR plot. Add clouds and that is it. Same for green plots just reversed.
 
J

john3

Active member
2019 Donor
def atr_func = MovingAverage(averageType, TrueRange(h, c, l), length);

That above doesn't seem to be a "real" Wilders ATR, but I'm not a coder, so apologies in advance if I'm wrong.

Does it use a 15-Day Moving Average as a base or is it based on a Daily range, Average True Range? I have a code for daily ATR and it seems to be different.

declare upper;

input ATRLength = 14;
input BasePeriod = AggregationPeriod.DAY;
input Displace = 0;

def dATR = Average(TrueRange(high(period = "DAY"), close(period = "DAY"), low(period = "DAY")));
plot SessionOpen = open(period = BasePeriod)[Displace];
def dATRa = dATR * Sqrt(BasePeriod / AggregationPeriod.DAY );

@horserider So it is based on a Daily ATR moving average (or 15 min ATR Moving Average if selected, etc), but the base isn't an ATR of a Daily range, right? The description, at least to me, sounds like it is based on an ATR of a Daily range.
 
horserider

horserider

Well-known member
VIP
input length = 15;
input averageType = AverageType.WILDERS;
def atr_func = MovingAverage(averageType, TrueRange(h, c, l), length);

ToS ATR below:
input length = 14;
input averageType = AverageType.WILDERS;
plot ATR = MovingAverage(averageType, TrueRange(high, close, low), length);

Looks like the same formula.

ATR is the Average True Range. So this is the wilders average of the True Range over 15 periods
 
D

diazlaz

Well-known member
2019 Donor
VIP
I believe @horserider description is correct, Perhaps we can all spend some time looking at it further and backtest it. I will add it to my backlog and look at this again over the weekend.
 
M

M_g_Carbs

New member
I am using a monthly aggregation period on a daily chart, but am having trouble creating a scan between two. Does anyone know how to create a scan that works on differing aggregation periods and time frames?
 
N

Nick

Active member
2019 Donor
VIP
Thanks @BenTen, this is one of the indicators i am looking for, it plots the Expected Move on weekly or when applying the OPT_EXP on the daily timeframe, it gives us the entire EM...it is really useful.... I am thinking what are the options strategy we can apply with this information provided....
 
T

thebewb

New member
This seems like it works better using the current day open rather than prior day close.
 
Top