DTR vs ATR Indicator for ThinkorSwim

Great Script Thank you for this post :)
Excellent tool in the extensive tool chest. As ATR will include gaps within the selected time period, while the daily range is simply High vs Low range: it gives the trader a Vantage point that could give you an Edge while trading, mostly intraday: To elaborate:
: Average True Range (ATR) is the average of true ranges over the specified period. ATR measures volatility, taking into account any gaps in the price movement, as opposed to the Daily Range, which is a function that shows the complete Domain.. By inference, if a a Total Price range is smaller than the ATR it indicates volatility and less linearality, while the opposite would hold true. By watching the DTR vs ATR on a smaller selected time reference you can infer the fractal energy of the price action. Further reference to Fractal Energy on ThinkorSwim advised. Fractal energy tracks periods of linearality vs non-linearality- therein lies a possible Edge : To Summarrize : by Watching Net Movement/Volatility (divided by) as the market orders and price discovery unfolds could give the Trader and Edge, which is the Goal
 
INDICATOR : https://tos.mx/O6FbYwT
################################
#REMASTERED by Cwparker23 #
################################
#-----------------
#DISCLAIMER
#-----------------
#I am not a certified financial advisor. The content of this page/site and tools are for informational purposes only and does not constitute financial or legal advice. Under no circumstances will the author be responsible for errors or use of this tool and site. User assumes all risks.

declare upper;
input higherTimeFrame = AggregationPeriod.day;
input averageType = AverageType.WILDERS;
input AtrAvgLength = 10;

DEF DL = low(period = higherTimeFrame );
DEF DH = high(period = higherTimeFrame );
DEF DC = CLOSE(period = higherTimeFrame );

DEF PREvLOW = low(period = higherTimeFrame )[1];
DEF PREvHIGH = high(period = higherTimeFrame )[1];
DEF PREvCLose = close(period = higherTimeFrame )[1];
PLOT DAY_OPEN = OPEN(period = higherTimeFrame );
DAY_OPEN.SetDefaultColor(Color.WHITE);
DAY_OPEN.SetLineWeight(3);
DAY_OPEN.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DEF ATR = MovingAverage(averageType, TrueRange(PREvHIGH, PREvCLose , PREvLOW), AtrAvgLength);

DEF TodayHigh = MovingAverage(averageType, DH, AtrAvgLength);
DEF TodayLow = MovingAverage(averageType, DL, AtrAvgLength);

DEF HighPV = MovingAverage(averageType, PREvHIGH, AtrAvgLength);
DEF LowPV = MovingAverage(averageType, PREvLOW, AtrAvgLength);

def DTR = HighPV - LowPV;

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

DEF ATR2 = MovingAverage(averageType, TrueRange(DH, DC , DL), AtrAvgLength);
def DTR2 = TodayHigh - TodayLow;
def DTRpct2 = Round((DTR2 / ATR2) * 100,2);


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


PLOT HO = DAY_OPEN + DTR;
PLOT LO = DAY_OPEN - DTR;

def range = HO - LO;

INPUT LEVEL1 = .786;
INPUT LEVEL2 = .618;
INPUT LEVEL3 = .382;
INPUT LEVEL4 = .286;



PLOT LEVEL_1 = LO + (LEVEL1 * range);
PLOT LEVEL_2 = LO + (LEVEL2 * range);
PLOT LEVEL_3 = LO + (LEVEL3 * range);
PLOT LEVEL_4 = LO + (LEVEL4 * range);

Thanks! I need something like this but without using the AggregationPeriod function, so it can work on mobile.
 
@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;

This is a great study that I use every day. Is there a way to modify the code so that it always shows the current DTR percent? Right now it appropriately shows the "peak" percentage range only; in other words if a stock moves to 92% and then reverses, the indicator remains at the 92% (unless it comes back and goes further to 93%, etc).

On the same note, can the code be adjusted to distinguish between upward vs downward movement? Right now if a stock moves 40% up it shows 40%, and if it moves down 40% it still shows 40%, again appropriately so. Could the code be modified to show whether the current DTR percentage is 40% vs -40% (i.e. up or down)?
 
Last edited:
ALERTS. I want to create alerts for when the DTR v ATR crosses a certain percentage. I've looked everywhere, I can't find how to do it. @Joshua maybe can help?

Thanks!
 
Last edited:
This is a great study that I use every day. Is there a way to modify the code so that it always shows the current DTR percent? Right now it appropriately shows the "peak" percentage range only; in other words if a stock moves to 92% and then reverses, the indicator remains at the 92% (unless it comes back and goes further to 93%, etc).

On the same note, can the code be adjusted to distinguish between upward vs downward movement? Right now if a stock moves 40% up it shows 40%, and if it moves down 40% it still shows 40%, again appropriately so. Could the code be modified to show whether the current DTR percentage is 40% vs -40% (i.e. up or down)?

Try this...


declare upper;
input AtrAvgLength = 15;

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

def DTR = High(period = aggregationPeriod.DAY) - low(period = aggregationPeriod.DAY);

def o = open(period = AggregationPeriod.DAY);
def h = high(period = AggregationPeriod.DAY);
def l = low(period = AggregationPeriod.DAY);
def c = close(period = AggregationPeriod.DAY);
def Current = round (c-l, 2);

AddLabel (yes, "TRADING RANGE: Daily " + Round (DTR , 2) + ", 15D Avg " + round (ATR,2) + ", Current " + Current + ", Relative to Daily " + AsPercent(Current/DTR) + ", Relative to Avg " + AsPercent(Current/ATR), (if Current/ATR <= .70 then Color.GREEN else if Current/ATR >= .90 then Color.RED else Color.ORANGE));
 
How would I adjust this to round the percentages shown in the labels to the nearest whole number? Thank you
 
Last edited by a moderator:

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