Average Daily Range Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
This indicator displays the Average Daily Range for the last 5 days. Could potentially be useful for finding hidden support and resistance levels on intraday chart.



Notes:
  • The blue line = high of average daily range
  • The pink line = low of average daily range

thinkScript Code

Rich (BB code):
#Hint: Average Daily Range

def len = 2;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).dailyhigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;

def ADR_high = (dayHigh + dayHigh[1] + dayHigh[2] + dayHigh[3] + dayHigh[4]) / 5;
def ADR_low = (dayLow + dayLow[1] + dayLow[2] + dayLow[3] + dayLow[4]) / 5;

plot ADR_H = ADR_high;
plot ADR_L = ADR_low;

Shareable Link

https://tos.mx/1yaAuM

Credit:
 
Last edited:
markos

markos

Well-known member
VIP
@BenTen one of those IV scripts from last week also plots like the indicator you have above.

 
Last edited:
I

Ian_Tai

New member
That's pretty useful. What would I use to plot a percentage of that? Say I want to plot 70% of the range?
 
J

jdstrader

New member
Hello,

I'm trying to build a screener that would find stocks that are at 100% or more of their Average True Range (ATR) on the day but I don't think it's possible with the default screener options on TOS. Does anyone know how to code something like that? Thank you so much!
 
wtf_dude

wtf_dude

Active member
you just mean a scan of stocks where the range of the day is at least twice the ATR?
 
J

jdstrader

New member
Yes exactly. It's probably easy to set it up but I'm a little lost. Thanks for your help.
 
A

autolox

New member
Here's another angle:

@jdstrader Here's how you can see any percentage you desire in a scan.

Code:
# Code for Average Range Scan - User selects Percentage of Range covered by changing the ScanRange

# The number of days you'd like average
input RangePeriod = 5;

# ScanRange = .25 (25%) .50 (50%) .75 (75%) 1 (100%)
input ScanRange = 1;

def DayRange = high-low;
def AvgRange = average(DayRange,RangePeriod);

# How to address seeing what % of daily range has been achieved
def TodayAgainstAvgRange = (high-low)/AvgRange;

Add This line for a scan:

Code:
plot scanyes = TodayAgainstAvgRange is greater than ScanRange;

Add This line for a custom watchlist column:

Code:
AddLabel(yes,"AVR: "+todayagainstavgrange*100+"%",color.yellow);

Different colors can be used for different amounts of range also if desired.
 
Last edited:
K

K_O_Trader

Member
Doesnt work, def RangePeriod = 14; is highlighted red
 
A

autolox

New member
@K_O_Trader

I scratched that out while mobile. Try making rangeperiod rangelength instead. Rangeperiod in the avgrange statement will need to change as well.

Still mobile...tag me here if that doesn't solve it. My guess is "period" being a constant is why the error is happening.
 
K

K_O_Trader

Member
@K_O_Trader

I scratched that out while mobile. Try making rangeperiod rangelength instead. Rangeperiod in the avgrange statement will need to change as well.

Still mobile...tag me here if that doesn't solve it. My guess is "period" being a constant is why the error is happening.
Its solved the problem when it came to any red highlights, but i still cant press OK and implement the scan into my system
 
A

autolox

New member
@K_O_Trader

Did you add the "plot scanyes" line into your scan code?

Code:
plot scanyes = TodayAgainstAvgRange is greater than ScanRange;

That's likely why you weren't able to click OK - no plot....

Apologies for that duplication of the rangeperiod variable...That's why you got the error you did initially.

I wrote the "core" of the code in the original reply then added two possibilities:

One for a scan, and the other for a watchlist custom column if you desire.
 
J

jdstrader

New member
Thanks for the script @autolox I added it to my watchlist. I have another indicator on my chart that shows me the DTR vs ATR of the stock I'm watching on a little bubble. For some reason the percentage doesn't match with the one shown on the watchlist using your script. I'm attaching a screenshot so you see what I mean.



Here's the code of the indicator I'm using.

Code:
# Custom ATR Plot by 7of9 for BRT
# edited 3/20/19

declare upper;

input AtrAvgLength = 14;

def ATR = WildersAverage(TrueRange(high(period = aggregationPeriod.DAY), close(period = aggregationPeriod.DAY), low(period = aggregationPeriod.DAY)), AtrAvgLength);

def TodayHigh = Highest(high(period = aggregationPeriod.DAY), 1);
def TodayLow = Lowest(low(period = aggregationPeriod.DAY), 1);

def DTR = TodayHigh - TodayLow;

def DTRpct = Round((DTR / ATR) * 100, 0);

AddLabel (yes, "DTR " + Round (DTR , 2) + " vs ATR " + round (ATR,2)+ "  " + round (DTRpct,0) + "%", (if DTRpct <= 70 then Color.GREEN else if DTRpct >= 90 then Color.RED else Color.ORANGE));

I can't figure out why I'm getting different values of the DTR. Thanks again for your help.
 
A

autolox

New member
@jdstrader

Assuming you loaded the script I shared with no adjustments, that script was written for 5 periods.

It looks like your code is written for 14.

The other part that is probably causing some variant is the use of "WildersAverage()" in your code. (I have zero proficiency with WildersAverage...)

In lieu of trying to squeeze answers out of this WildersAverage turnip, Here's some information on the function itself directly from TD and "The Learning Center":

Think Or Swim Learning Center - WildersAverage() function

It looks like your code is also averaging together the HIGH, LOW, and CLOSE while I'm simply applying the difference between high and low.

(Just thinking out loud - what does CLOSE have to do with TRUE RANGE? - I'm really not trying to be as snarky as that question may read, I'm just honestly curious....)
 
J

jdstrader

New member
Yes, sorry I forgot to mention that I did change your code to 14 periods so it must be the WildersAverage part that is giving different percentages. I'll look into it further. Thanks for your help.
 
lowtrade

lowtrade

Member
VIP
The concept looks cool.

@autolox Would you mind to share your complete code?

@jdstrader were you able to fix the issue?
 
T

trader57

New member
Need help with a slight variation of this indicator where it uses previous close as well to account for overnight changes in price. Thanks.
 

Similar threads

Top