ATR Plots For ThinkOrSwim

rlohmeyer

Active member
The recent code for ATR plots on a chart also showing the previous days close to show the relationship of the present move to the actual move. The chart shows the code in action on the chart.
ATR of Amat.jpg


Code:
#Basic Definitions
def c_ = close;
def c = if IsNaN(c_[-1]) then c_ else c[1];


#Atr Plots###################
input agg = AggregationPeriod.DAY;
input AtrLngth = 21;

def tr = TrueRange (high(period = agg), close(period = agg), low(period = agg));
def Atr = Average(TrueRange(high, close, low), 21);
def AtrPct = (atr/close)*100;
input ShowAtr = yes;

#ATR Variables
def ATRH = if ShowAtr and !IsNaN(c_[1] + Atr) and IsNaN(c_[1] + Atr[-1]) then c_[1] + Atr else ATRH[1];
plot ATR_High = if IsNaN(c_[1] + Atr[-400]) then ATRH[-400] else Double.NaN;
ATR_High .SetDefaultColor(Color.YELLOW);
ATR_High .SetPaintingStrategy(PaintingStrategy.DASHES);
ATR_High .SetLineWeight(2);

def ATRL = if ShowAtr and !IsNaN(c_[1] - Atr) and IsNaN(c_[1] - Atr[-1]) then c_[1] - Atr else ATRL[1];
plot ATR_Low = if IsNaN(c_[1] - Atr[-400]) then ATRL[-400] else Double.NaN;
ATR_Low .SetDefaultColor(Color.YELLOW);
ATR_Low .SetPaintingStrategy(PaintingStrategy.DASHES);
ATR_Low .SetLineWeight(2);

# --- Previous Close Line (Mirrored from ATR Logic) ---
input pc_agg = AggregationPeriod.DAY; # Set to DAY for 2/12 vs 2/13 logic

def pc_close = close(period = pc_agg);

# This captures the close of 2/12 by looking back 1 bar from the chart's end
def PC_Stored = if !IsNaN(pc_close) and IsNaN(pc_close[-1])
                then pc_close[1]
                else PC_Stored[1];

# This plots the line 400 bars back and through the expansion area
plot PC_Line = if IsNaN(pc_close[-400])
               then PC_Stored[-400]
               else Double.NaN;

PC_Line.SetDefaultColor(Color.orange);
PC_Line.SetPaintingStrategy(PaintingStrategy.DASHES);
PC_Line.SetLineWeight(2);
#PC_Line.HideBubble();




################Analysis Labels###################
input ShowLabel = yes;
AddLabel(if ShowLabel then yes else no,"ATR" + AtrLngth + "|$" + Round(Atr,2), Color.YELLOW);
 
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
2044 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