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();
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();
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));
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));
##### 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));
def atr = ATR();
AddLabel(yes, " ATR: " + Round(atr, 2) + " ", if atr > atr[1] then Color.UPTICK else if atr < atr[1] then Color.DOWNTICK else Color.WHITE);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
O | ATR + Volume Spikes For ThinkOrSwim | Custom | 5 | |
![]() |
Radial Basis Kernal ATR [BackQuant] for ThinkOrSwim | Custom | 3 | |
![]() |
ORB with ATR Trailing SL [Bluechip Algos] for ThinkOrSwim | Custom | 9 | |
E | Repaints ATR Fib Levels For ThinkOrSwim | Custom | 1 | |
![]() |
ATR Based Trendlines - JD For ThinkOrSwim | Custom | 1 |
Start a new thread and receive assistance from our community.
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.
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.