ATR Label For ThinkOrSwim

qinking127

New member
I try to add a label to show daily ATR on 1 min chart. but it only shows 1 min ATR. is there a way to change time period?

def atr = atr();
 

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

You can only reference a larger aggregation, and well, it doesn't get much smaller than one minute... So even though I don't entirely understand what you're asking, I am going to take a guess and say, no, its not possible. You're going to have to be more clear with your question.
 
You can only reference a larger aggregation, and well, it doesn't get much smaller than one minute... So even though I don't entirely understand what you're asking, I am going to take a guess and say, no, its not possible. You're going to have to be more clear with your question.


I am using 1 min chart to trade. I want to add a label on the 1 min chart to show the daily ATR. If I use this code to get ATR. it will give me the ATR based on the 1 min candles. but I want to get the ATR based on the daily candle. Is there way to do it? Hopefully this is a little bit more clear.

def atr = atr();
 
I am using 1 min chart to trade. I want to add a label on the 1 min chart to show the daily ATR. If I use this code to get ATR. it will give me the ATR based on the 1 min candles. but I want to get the ATR based on the daily candle. Is there way to do it? Hopefully this is a little bit more clear.

def atr = atr();

Try this

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2014-2021
#

#declare lower;

input length = 14;
input averageType = AverageType.WILDERS;
input agg = AggregationPeriod.DAY;
def h = high(period = agg);
def c = close(period = agg);
def l = low(period = agg);

def ATR = MovingAverage(averageType, TrueRange(h, c, l), length);
#ATR.SetDefaultColor(GetColor(8));
addlabel(1,"Daily ATR: " + astext(ATR), color.yellow);
 
This should fix that issue.

Whenever that happens, try the fix to the def pcClose close(symbol = "$PCALL") as shown in the code below
1) By having any missing periods in def pcClose, shown as isnan(close(symbol = "$PCALL")) ,
filled by referencing those to the prior value of pcClose, shown as pcClose[1]
2) otherwise pcClose will use the actual value of close(symbol = "$PCALL").

Hey SleepyZ, I was wondering if you could help me out with this one: So I have an ATR label that has the same issue as the last P/C label you helped me out with. It's only being displayed on certain time frames but not all. I was trying out what you had mentioned above with the closing command code but still having issues. The label does not display on higher time frames and I'm trying to figure out how to get it to be displayed across all time frames. Thank you for your time and help greatly appreciated. Here is the code:

input length = 14;
input averageType = AverageType.WILDERS;
input agg1 = AggregationPeriod.DAY;
input agg2 = AggregationPeriod.WEEK;
input agg3 = AggregationPeriod.MONTH;
def h1 = high(period = agg1);
def c1 = close(period = agg1);
def l1 = low(period = agg1);
def h2 = high(period = agg2);
def c2 = close(period = agg2);
def l2 = low(period = agg2);
def h3 = high(period = agg3);
def c3 = close(period = agg3);
def l3 = low(period = agg3);

def ATR1 = MovingAverage(averageType, TrueRange(h1, c1, l1), length);
def ATR2 = MovingAverage(averageType, TrueRange(h2, c2, l2), length);
def ATR3 = MovingAverage(averageType, TrueRange(h3, c3, l3), length);

AddLabel(1, "ATR D: " + AsText(ATR1) + " W: " + AsText(ATR2) + " M: " + AsText(ATR3), CreateColor(255, 255, 255));
 
Hey SleepyZ, I was wondering if you could help me out with this one: So I have an ATR label that has the same issue as the last P/C label you helped me out with. It's only being displayed on certain time frames but not all. I was trying out what you had mentioned above with the closing command code but still having issues. The label does not display on higher time frames and I'm trying to figure out how to get it to be displayed across all time frames. Thank you for your time and help greatly appreciated. Here is the code:

input length = 14;
input averageType = AverageType.WILDERS;
input agg1 = AggregationPeriod.DAY;
input agg2 = AggregationPeriod.WEEK;
input agg3 = AggregationPeriod.MONTH;
def h1 = high(period = agg1);
def c1 = close(period = agg1);
def l1 = low(period = agg1);
def h2 = high(period = agg2);
def c2 = close(period = agg2);
def l2 = low(period = agg2);
def h3 = high(period = agg3);
def c3 = close(period = agg3);
def l3 = low(period = agg3);

def ATR1 = MovingAverage(averageType, TrueRange(h1, c1, l1), length);
def ATR2 = MovingAverage(averageType, TrueRange(h2, c2, l2), length);
def ATR3 = MovingAverage(averageType, TrueRange(h3, c3, l3), length);

AddLabel(1, "ATR D: " + AsText(ATR1) + " W: " + AsText(ATR2) + " M: " + AsText(ATR3), CreateColor(255, 255, 255));

Similar process

Ruby:
input length = 14;
input averageType = AverageType.WILDERS;
input agg1 = AggregationPeriod.DAY;
input agg2 = AggregationPeriod.WEEK;
input agg3 = AggregationPeriod.MONTH;
def h1 = high(period = agg1);
def c1 = close(period = agg1);
def l1 = low(period = agg1);
def h2 = high(period = agg2);
def c2 = close(period = agg2);
def l2 = low(period = agg2);
def h3 = high(period = agg3);
def c3 = close(period = agg3);
def l3 = low(period = agg3);

def ATR1 = if IsNaN(MovingAverage(averageType, TrueRange(h1, c1, l1), length))
           then ATR1[1]
           else MovingAverage(averageType, TrueRange(h1, c1, l1), length);
def ATR2 = if IsNaN(MovingAverage(averageType, TrueRange(h2, c2, l2), length))
           then ATR1[1]
           else MovingAverage(averageType, TrueRange(h2, c2, l2), length);
def ATR3 = if IsNaN(MovingAverage(averageType, TrueRange(h3, c3, l3), length))
           then ATR1[1]
           else MovingAverage(averageType, TrueRange(h3, c3, l3), length);

AddLabel(1, "ATR D: " + AsText(ATR1) + " W: " + AsText(ATR2) + " M: " + AsText(ATR3), CreateColor(255, 255, 255));
 
Any of the above or this one:
Code:
##### TS ATR
##### Made By Leonard
##### Version 1
##### 4/23/2015

declare upper;

input ATRLength = 14;
input averagetype = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input showlabel = yes;

def ATR = MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength);

def Today_High = Highest(high(period = baseperiod)[0], 1);
def Today_Low = Lowest(low(period =baseperiod)[0], 1);


AddLabel(showlabel,  "ATR:" +round(ATR,2));
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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