DTR vs ATR Indicator for ThinkorSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Found this interesting indicator which provides basic info...however, there is something wrong with the code. The commented lines are the issue. Can anyone figure out how to correct this?

Code:
#Study:Info
#by thetrader.top
input ATRLength = 14;
input ShowATR = {default “1”, “0”}; #Average True Range
input AvgVolume = {default “1”, “0”}; #Average volume for the last 14 days
input Volume_ = {default “1”, “0”}; #Volume for today
input ATRPlay = {default “1”, “0”}; #How many ATR’s stock moved today
input VolumePlay = {default “1”, “0”}; #How many of its average volumes stock traded for the last 65 days.
def _ATR_D = TrueRange(high(period = “DAY”), close(period = “DAY”), low(period = “DAY”));
def iATR_D = Round(Average(_ATR_D, ATRLength)[1], 2);
AddLabel (!ShowATR, “ATR(“ + ATRLength + ”) “ + iATR_D, Color.GRAY);
def iAvgVolume = Round(Average (volume(period = “DAY”)[1], 65) / 1000, 0);
AddLabel (!AvgVolume, “AvgVol “ + iAvgVolume + “k”, Color.GRAY);
def iVolume = Round(volume(period = “DAY”) / 1000, 0);
AddLabel (!Volume_, “Vol “ + iVolume + “k”, Color.LIGHT_GREEN);
#def iATRPlay = Round((high(period = “DAY”) — low(period = “DAY”)) / iATR_D, 1);
#AddLabel (!ATRPlay, “ATRPlay “ + iATRPlay + “(“ + Round(high(period = “DAY”) — low(period = “DAY”), 2) + “)”, Color.LIGHT_GREEN);
def iVolumePlay = Round(iVolume / iAvgVolume, 2);
AddLabel (!VolumePlay, “VolPlay “ + iVolumePlay, Color.LIGHT_GREEN);
def Gap = Round((open(period = “DAY”) - close(period = “DAY”)[1]) / close(period = “DAY”)[1] * 100, 2);
AddLabel (yes, “Gap “ + Gap + ”%”, Color.LIGHT_GREEN);
def ATRcur = Round (Average(TrueRange(high, close, low)[1], 5));
AddLabel (yes, “ATR(5) “ + ATRcur, if (ATRcur <= 0.20) then Color.GREEN else Color.RED);

This is a description of what the indicator is:

ATR(14) — how much the stock can move per day. Calculated on the average value of 14 days.
AvgVol — average trading volume for a stock over the past 65 days, calculated in thousands.
Vol — how many shares traded today.
ATRPlay — how much today the price has passed relatively from Low to High. It is calculated in dollars and% relative to the average. The screenshot shows that the average price moves $ 5.5, and today the action has already passed 5.53, the one after ATRPlay is 100%. Without unnecessary symbols to save space. According to my strategy, the potential is no longer there, which means that the share has to be taken in the opposite direction.
VolPlay — What is the volume as a percentage now, the trading volume is relative average. An important parameter for an intraday trader, it is considered as a percentage. 104% on the screen. This means that if you looked at the beginning of the day … This is clearly increased volume. If a stock trades 100% in the first hour, a large seller or buyer is guaranteed to sit there.
Gap — % of gap at the opening is purely informational. I do not analyze in any way, but in some strategies traders rely on it when making a decision.
ATR (5) — And the last parameter is the average price spread for the last 5 bars. If you place a stop, it cannot be less than this value in any way. Otherwise, you will simply be carried away by the noise of the market.
 
@dvorakm I don't see anything wrong with the code. I was able to add it to my chart.

PGNeZOd.png
 
Code:
#Study:Info
#by thetrader.top
input ATRLength = 14;
input ShowATR = {default “1”, “0”}; #Average True Range
input AvgVolume = {default “1”, “0”}; #Average volume for the last 14 days
input Volume_ = {default “1”, “0”}; #Volume for today
input ATRPlay = {default “1”, “0”}; #How many ATR’s stock moved today
input VolumePlay = {default “1”, “0”}; #How many of its average volumes stock traded for the last 65 days.
def _ATR_D = TrueRange(high(period = “DAY”), close(period = “DAY”), low(period = “DAY”));
def iATR_D = Round(Average(_ATR_D, ATRLength)[1], 2);
AddLabel (!ShowATR, “ATR(“ + ATRLength + ”) “ + iATR_D, Color.GRAY);
def iAvgVolume = Round(Average (volume(period = “DAY”)[1], 65) / 1000, 0);
AddLabel (!AvgVolume, “AvgVol “ + iAvgVolume + “k”, Color.GRAY);
def iVolume = Round(volume(period = “DAY”) / 1000, 0);
AddLabel (!Volume_, “Vol “ + iVolume + “k”, Color.LIGHT_GREEN);
def iATRPlay = Round((high(period = “DAY”) - low(period = “DAY”) / iATR_D), 1);
AddLabel (!ATRPlay, “ATRPlay “ + iATRPlay + “(“ + Round(high(period = “DAY”) - low(period = “DAY”), 2) + “)”, Color.LIGHT_GREEN);
def iVolumePlay = Round(iVolume / iAvgVolume, 2);
AddLabel (!VolumePlay, “VolPlay “ + iVolumePlay, Color.LIGHT_GREEN);
def Gap = Round((open(period = “DAY”) - close(period = “DAY”)[1]) / close(period = “DAY”)[1] * 100, 2);
AddLabel (yes, “Gap “ + Gap + ”%”, Color.LIGHT_GREEN);
def ATRcur = Round (Average(TrueRange(high, close, low)[1], 5));
AddLabel (yes, “ATR(5) “ + ATRcur, if (ATRcur <= 0.20) then Color.GREEN else Color.RED);


I got the errors but corrected in above code. Seemed problem was here. Shown in bold.
def iATRPlay = Round((high(period = “DAY”)low(period = “DAY”)) / iATR_D, 1);
AddLabel (!ATRPlay, “ATRPlay “ + iATRPlay + “(“ + Round(high(period = “DAY”)low(period = “DAY”), 2) + “)”, Color.LIGHT_GREEN);
 
Code:
#Study:Info
#by thetrader.top
input ATRLength = 14;
input ShowATR = {default “1”, “0”}; #Average True Range
input AvgVolume = {default “1”, “0”}; #Average volume for the last 14 days
input Volume_ = {default “1”, “0”}; #Volume for today
input ATRPlay = {default “1”, “0”}; #How many ATR’s stock moved today
input VolumePlay = {default “1”, “0”}; #How many of its average volumes stock traded for the last 65 days.
def _ATR_D = TrueRange(high(period = “DAY”), close(period = “DAY”), low(period = “DAY”));
def iATR_D = Round(Average(_ATR_D, ATRLength)[1], 2);
AddLabel (!ShowATR, “ATR(“ + ATRLength + ”) “ + iATR_D, Color.GRAY);
def iAvgVolume = Round(Average (volume(period = “DAY”)[1], 65) / 1000, 0);
AddLabel (!AvgVolume, “AvgVol “ + iAvgVolume + “k”, Color.GRAY);
def iVolume = Round(volume(period = “DAY”) / 1000, 0);
AddLabel (!Volume_, “Vol “ + iVolume + “k”, Color.LIGHT_GREEN);
def iATRPlay = Round((high(period = “DAY”) - low(period = “DAY”) / iATR_D), 1);
AddLabel (!ATRPlay, “ATRPlay “ + iATRPlay + “(“ + Round(high(period = “DAY”) - low(period = “DAY”), 2) + “)”, Color.LIGHT_GREEN);
def iVolumePlay = Round(iVolume / iAvgVolume, 2);
AddLabel (!VolumePlay, “VolPlay “ + iVolumePlay, Color.LIGHT_GREEN);
def Gap = Round((open(period = “DAY”) - close(period = “DAY”)[1]) / close(period = “DAY”)[1] * 100, 2);
AddLabel (yes, “Gap “ + Gap + ”%”, Color.LIGHT_GREEN);
def ATRcur = Round (Average(TrueRange(high, close, low)[1], 5));
AddLabel (yes, “ATR(5) “ + ATRcur, if (ATRcur <= 0.20) then Color.GREEN else Color.RED);


I got the errors but corrected in above code. Seemed problem was here. Shown in bold.
def iATRPlay = Round((high(period = “DAY”)low(period = “DAY”)) / iATR_D, 1);
AddLabel (!ATRPlay, “ATRPlay “ + iATRPlay + “(“ + Round(high(period = “DAY”)low(period = “DAY”), 2) + “)”, Color.LIGHT_GREEN);
Thank you! You da man!
 
Is this measuring the current range abasing the ATR on a daily basis, Periods being days? Can a version be created where it displays the ATR ÷ Current Price of the security to show the ATR % and compare with similar securities?
 
@chada456 I'm looking for a similar scan to check for any equities that have a DTR <= 1 ATR. I could not get yours work (maybe because I don't know how to call out the 1 ATR in the scan. Any suggestions?
 
I love this. However, I'm not getting the ATRplay. As I look at @BenTen pic, his doesn't have it either. Ben, are we missing something? @horserider you know anything about this? I'm not getting the ATRplay label.... Thanks!
 
Last edited:
I'm trying to find the DTR (Daily Trading Range) on the App. Is the only way to do it, to manually subtract the day's low from the day's high?
 
@Ninja Bull Here you go:

Code:
# Custom ATR Plot by 7of9 for BRT
# edited 3/20/19
# Modified by BenTen to plot DTR as a watchlist column

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);
plot Data = DTRpct;
 
Code:
# ATRLabel

#

# Displays Average True Range over the last 40 periods and the current period

#

input ATRLength = 40;

# historical ATR

def ATRValue = Average(TrueRange(high, close, low), ATRLength);

def ATRPercent = ATRValue / close * 100;

# current period range

def ATRLastBar = TrueRange(high, close, low);

AddLabel(yes, ATRLength + " Period ATR = $" + Round(ATRValue, 2) + " (" + Round(ATRPercent, 2) + "%), Current Period Range = $" + Round(ATRLastBar, 2) + " (" + Round(ATRLastBar / close * 100, 2) + "%)", CreateColor(153, 153, 0));


Would like to get a color on this label something like the below. Tried to code this but still have to work through my basic coding.

If the atr is =< 25% of 40 atr color orange

If the atr is =< 50% of 40 atr color red

Else atr is => 50% of 40 atr color green
 
@JohnWick4 Replace your createcolor code and it should be what you're looking for.

Code:
if ATRLastBar <= .25 * ATRValue then color.orange else if ATRLastBar <= .5 * ATRValue then color.red else color.green
[/CODE]
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
435 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