plot x = hl2 + (ATR() * 0.5);
plot y = hl2 - (ATR() * 0.5);
x.setpaintingStrategy(paintingStrategy.HORIZONTAL);
y.setpaintingStrategy(paintingStrategy.HORIZONTAL);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
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));
plot line = CLOSE(period = BasePeriod)[1]- ATR;
line.SetDefaultColor(Color.WHITE);
line.SetStyle(Curve.SHORT_DASH);
line.SetLineWeight(1);
input ATRLength = 14;
input averagetype = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.thirty_MIN;
input showlabel = yes;
Def ATR = (MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength));
plot line = CLOSE(period = BasePeriod)[1]- ATR;
line.SetDefaultColor(Color.WHITE);
line.SetStyle(Curve.SHORT_DASH);
line.SetLineWeight(1);
def barNum = if !IsNaN(BarNumber()) then Barnumber() else Double.NaN;
def numBars = HighestAll(barNum);
def FinalBar= fold c = 0 to numbars while !IsNaN(GetValue(close, -c)) do GetValue(BarNumber(), -c);
def FinalATR = fold a = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -a)) do GetValue(line[-1], -a);
plot DayATR = if FinalATR>1 then FinalATR else Double.NaN;
DayATR.SetStyle(Curve.LONG_DASH);
DayATR.AssignValueColor(Color.LIME);
input price = close;
input length = 20;
input displace = 0;
plot EMA = ExpAverage(price[-displace], length);
plot line = EMA;
EMA.SetDefaultColor(GetColor(1));
def barNum = if !IsNaN(BarNumber()) then Barnumber() else Double.NaN;
def numBars = HighestAll(barNum);
def FinalBar= fold c = 0 to numbars while !IsNaN(GetValue(close, -c)) do GetValue(BarNumber(), -c);
def FinalEMA = fold a = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -a)) do GetValue(line[-1], -a);
plot DayEMA = if FinalEMA>1 then FinalEMA else Double.NaN;
DayEMA.SetDefaultColor(GetColor(1));
@ronviv1
Code:input ATRLength = 14; input averagetype = AverageType.WILDERS; input BasePeriod = AggregationPeriod.thirty_MIN; input showlabel = yes; Def ATR = (MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength)); plot line = CLOSE(period = BasePeriod)[1]- ATR; line.SetDefaultColor(Color.WHITE); line.SetStyle(Curve.SHORT_DASH); line.SetLineWeight(1); def barNum = if !IsNaN(BarNumber()) then Barnumber() else Double.NaN; def numBars = HighestAll(barNum); def FinalBar= fold c = 0 to numbars while !IsNaN(GetValue(close, -c)) do GetValue(BarNumber(), -c); def FinalATR = fold a = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -a)) do GetValue(line[-1], -a); plot DayATR = if FinalATR>1 then FinalATR else Double.NaN; DayATR.SetStyle(Curve.LONG_DASH); DayATR.AssignValueColor(Color.LIME);
Thank you so much for this. I see the horizontal line to the downside, but is it possible to add an additional horizontal line for the upper boundary of ATR?@ronviv1
Code:input ATRLength = 14; input averagetype = AverageType.WILDERS; input BasePeriod = AggregationPeriod.thirty_MIN; input showlabel = yes; Def ATR = (MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength)); plot line = CLOSE(period = BasePeriod)[1]- ATR; line.SetDefaultColor(Color.WHITE); line.SetStyle(Curve.SHORT_DASH); line.SetLineWeight(1); def barNum = if !IsNaN(BarNumber()) then Barnumber() else Double.NaN; def numBars = HighestAll(barNum); def FinalBar= fold c = 0 to numbars while !IsNaN(GetValue(close, -c)) do GetValue(BarNumber(), -c); def FinalATR = fold a = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -a)) do GetValue(line[-1], -a); plot DayATR = if FinalATR>1 then FinalATR else Double.NaN; DayATR.SetStyle(Curve.LONG_DASH); DayATR.AssignValueColor(Color.LIME);
input ATRLength = 14;
input averagetype = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.thirty_MIN;
input showlabel = yes;
Def ATR = (MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength));
plot line = CLOSE(period = BasePeriod)[1]- ATR;
line.SetDefaultColor(Color.WHITE);
line.SetStyle(Curve.SHORT_DASH);
line.SetLineWeight(1);
plot line1 = CLOSE(period = BasePeriod)[1]+ ATR;
line1.SetDefaultColor(Color.WHITE);
line1.SetStyle(Curve.SHORT_DASH);
line1.SetLineWeight(1);
def barNum = if !IsNaN(BarNumber()) then Barnumber() else Double.NaN;
def numBars = HighestAll(barNum);
def FinalBar= fold c = 0 to numbars while !IsNaN(GetValue(close, -c)) do GetValue(BarNumber(), -c);
def FinalATRDn = fold a = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -a)) do GetValue(line[-1], -a);
def FinalATRUp = fold b = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -b)) do GetValue(line1[-1], -b);
plot DayATRDn = if FinalATRDn>1 then FinalATRDn else Double.NaN;
DayATRDn.SetStyle(Curve.LONG_DASH);
DayATRDn.AssignValueColor(Color.LIME);
plot DayATRUp = if FinalATRUp>1 then FinalATRUp else Double.NaN;
DayATRUp.SetStyle(Curve.LONG_DASH);
DayATRUp.AssignValueColor(Color.LIME);
You are an amazingly intelligent, beautiful human being! Thank you!@Wardo21 I assume this is what you're wanting.
Code:input ATRLength = 14; input averagetype = AverageType.WILDERS; input BasePeriod = AggregationPeriod.thirty_MIN; input showlabel = yes; Def ATR = (MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength)); plot line = CLOSE(period = BasePeriod)[1]- ATR; line.SetDefaultColor(Color.WHITE); line.SetStyle(Curve.SHORT_DASH); line.SetLineWeight(1); plot line1 = CLOSE(period = BasePeriod)[1]+ ATR; line1.SetDefaultColor(Color.WHITE); line1.SetStyle(Curve.SHORT_DASH); line1.SetLineWeight(1); def barNum = if !IsNaN(BarNumber()) then Barnumber() else Double.NaN; def numBars = HighestAll(barNum); def FinalBar= fold c = 0 to numbars while !IsNaN(GetValue(close, -c)) do GetValue(BarNumber(), -c); def FinalATRDn = fold a = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -a)) do GetValue(line[-1], -a); def FinalATRUp = fold b = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -b)) do GetValue(line1[-1], -b); plot DayATRDn = if FinalATRDn>1 then FinalATRDn else Double.NaN; DayATRDn.SetStyle(Curve.LONG_DASH); DayATRDn.AssignValueColor(Color.LIME); plot DayATRUp = if FinalATRUp>1 then FinalATRUp else Double.NaN; DayATRUp.SetStyle(Curve.LONG_DASH); DayATRUp.AssignValueColor(Color.LIME);
You are an amazingly intelligent, beautiful human being! Thank you!
I've been struggling to create a scan that will identify when price is greater than or equal to the yellow DayATRUP line. Would you be able to assist me with this?@Wardo21 I assume this is what you're wanting.
Code:input ATRLength = 14; input averagetype = AverageType.WILDERS; input BasePeriod = AggregationPeriod.thirty_MIN; input showlabel = yes; Def ATR = (MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength)); plot line = CLOSE(period = BasePeriod)[1]- ATR; line.SetDefaultColor(Color.WHITE); line.SetStyle(Curve.SHORT_DASH); line.SetLineWeight(1); plot line1 = CLOSE(period = BasePeriod)[1]+ ATR; line1.SetDefaultColor(Color.WHITE); line1.SetStyle(Curve.SHORT_DASH); line1.SetLineWeight(1); def barNum = if !IsNaN(BarNumber()) then Barnumber() else Double.NaN; def numBars = HighestAll(barNum); def FinalBar= fold c = 0 to numbars while !IsNaN(GetValue(close, -c)) do GetValue(BarNumber(), -c); def FinalATRDn = fold a = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -a)) do GetValue(line[-1], -a); def FinalATRUp = fold b = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -b)) do GetValue(line1[-1], -b); plot DayATRDn = if FinalATRDn>1 then FinalATRDn else Double.NaN; DayATRDn.SetStyle(Curve.LONG_DASH); DayATRDn.AssignValueColor(Color.LIME); plot DayATRUp = if FinalATRUp>1 then FinalATRUp else Double.NaN; DayATRUp.SetStyle(Curve.LONG_DASH); DayATRUp.AssignValueColor(Color.LIME);
Great Code Svanoy. I'm looking to plot horizontal lines based on the opening price for the current day for +1 +2 -1 -2 ATR's so I can have potential targets. adding a name for each line would be great too. I currently use the 14-day period ATR. TOS standard I think. Appreciate any input. Thx.@ronviv1
Code:input ATRLength = 14; input averagetype = AverageType.WILDERS; input BasePeriod = AggregationPeriod.thirty_MIN; input showlabel = yes; Def ATR = (MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength)); plot line = CLOSE(period = BasePeriod)[1]- ATR; line.SetDefaultColor(Color.WHITE); line.SetStyle(Curve.SHORT_DASH); line.SetLineWeight(1); def barNum = if !IsNaN(BarNumber()) then Barnumber() else Double.NaN; def numBars = HighestAll(barNum); def FinalBar= fold c = 0 to numbars while !IsNaN(GetValue(close, -c)) do GetValue(BarNumber(), -c); def FinalATR = fold a = 0 to AbsValue(FinalBar) while !IsNaN(GetValue(close, -a)) do GetValue(line[-1], -a); plot DayATR = if FinalATR>1 then FinalATR else Double.NaN; DayATR.SetStyle(Curve.LONG_DASH); DayATR.AssignValueColor(Color.LIME);
input ATRLength = 14;
input averagetype = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.thirty_MIN;
input time = 0930;
def ATR = (MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength));
def DayOpen = if SecondsTillTime(time) == 0 then open(period = BasePeriod) else DayOpen[1];
def ATRLine = if SecondsTillTime(time) == 0 then close(period = BasePeriod) - ATR else ATRLine[1];
plot LineATR = DayOpen;
LineATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LineATR.AssignValueColor(Color.LIME);
def UpLine1 = DayOpen + AbsValue(DayOpen-ATRLine);
plot Line1ATR = UpLine1;
Line1ATR.SetPaintingStrategy(PaintingStrategy.DASHES);
Line1ATR.AssignValueColor(Color.LIME);
def UpLine2 = Line1ATR + AbsValue(DayOpen-ATRLine);
plot Line2ATR = UpLine2;
Line2ATR.SetPaintingStrategy(PaintingStrategy.DASHES);
Line2ATR.AssignValueColor(Color.LIME);
def DnLine1 = DayOpen - AbsValue(DayOpen-ATRLine);
plot Line3ATR = DnLine1;
Line3ATR.SetPaintingStrategy(PaintingStrategy.DASHES);
Line3ATR.AssignValueColor(Color.LIME);
def DnLine2 = Line3ATR - AbsValue(DayOpen-ATRLine);
plot Line4ATR = DnLine2;
Line4ATR.SetPaintingStrategy(PaintingStrategy.DASHES);
Line4ATR.AssignValueColor(Color.LIME);
AddChartBubble(LineATR<>LineATR[1],LineATR,"Day Open",color.LIME);
AddChartBubble(Line1ATR<>Line1ATR[1],Line1ATR,"+1 ATR",color.LIME,yes);
AddChartBubble(Line2ATR<>Line2ATR[1],Line2ATR,"+2 ATR",color.LIME,yes);
AddChartBubble(Line3ATR<>Line3ATR[1],Line3ATR,"-1 ATR",color.LIME,no);
AddChartBubble(Line4ATR<>Line4ATR[1],Line4ATR,"-2 ATR",color.LIME,no);
@jrwlkr not sure if this is what you want, let me know.
Ruby:input ATRLength = 14; input averagetype = AverageType.WILDERS; input BasePeriod = AggregationPeriod.thirty_MIN; input time = 0930; def ATR = (MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength)); def DayOpen = if SecondsTillTime(time) == 0 then open(period = BasePeriod) else DayOpen[1]; def ATRLine = if SecondsTillTime(time) == 0 then close(period = BasePeriod) - ATR else ATRLine[1]; plot LineATR = DayOpen; LineATR.SetPaintingStrategy(PaintingStrategy.DASHES); LineATR.AssignValueColor(Color.LIME); def UpLine1 = DayOpen + AbsValue(DayOpen-ATRLine); plot Line1ATR = UpLine1; Line1ATR.SetPaintingStrategy(PaintingStrategy.DASHES); Line1ATR.AssignValueColor(Color.LIME); def UpLine2 = Line1ATR + AbsValue(DayOpen-ATRLine); plot Line2ATR = UpLine2; Line2ATR.SetPaintingStrategy(PaintingStrategy.DASHES); Line2ATR.AssignValueColor(Color.LIME); def DnLine1 = DayOpen - AbsValue(DayOpen-ATRLine); plot Line3ATR = DnLine1; Line3ATR.SetPaintingStrategy(PaintingStrategy.DASHES); Line3ATR.AssignValueColor(Color.LIME); def DnLine2 = Line3ATR - AbsValue(DayOpen-ATRLine); plot Line4ATR = DnLine2; Line4ATR.SetPaintingStrategy(PaintingStrategy.DASHES); Line4ATR.AssignValueColor(Color.LIME); AddChartBubble(LineATR<>LineATR[1],LineATR,"Day Open",color.LIME); AddChartBubble(Line1ATR<>Line1ATR[1],Line1ATR,"+1 ATR",color.LIME,yes); AddChartBubble(Line2ATR<>Line2ATR[1],Line2ATR,"+2 ATR",color.LIME,yes); AddChartBubble(Line3ATR<>Line3ATR[1],Line3ATR,"-1 ATR",color.LIME,no); AddChartBubble(Line4ATR<>Line4ATR[1],Line4ATR,"-2 ATR",color.LIME,no);
Yes, I modified it to daily. So I'm displaying it on 2min or 5min chart but want to use the daily ATR over a 14day period. I'm thinking it has to do with the calculation of the open, mostly because that's the only thing that is not being plotted, although it could be the "0" line but the bubble isn't on that line, but not sure. If I switch to the day chart, it shows the -1, -2 a little better but shows no +1 +2 at all, but the numbers still don't seem correct. I only want to plot the current day anyway. I've also tried using the ATR study from TOS and that changed it, but still not correct at all.@jrwlkr use imgur to upload pics and put the BB link in your post.
Also, did you adjust the aggregation input to match your chart aggregation?
input ATRLength = 14;
input averagetype = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.thirty_MIN;
input time = 0930;
def today = if (GetDay() == GetLastDay()) and (SecondsFromTime(time) >= 0) then 1 else 0;
def ATR = MovingAverage(averageType, TrueRange(high(period = baseperiod), close(period = baseperiod), low(period = baseperiod)), atrlength);
def DayOpen = if SecondsTillTime(time) == 0 then open else DayOpen[1];
def ATRLine = if SecondsTillTime(time) == 0 then ATR else ATRLine[1];
plot LineATR = if today then DayOpen else Double.NaN;
LineATR.SetPaintingStrategy(PaintingStrategy.DASHES);
LineATR.AssignValueColor(Color.LIME);
def UpLine1 = if today then DayOpen + ATRLine else Double.NaN;
plot Line1ATR = UpLine1;
Line1ATR.SetPaintingStrategy(PaintingStrategy.DASHES);
Line1ATR.AssignValueColor(Color.LIME);
def UpLine2 = if today then Line1ATR + ATRLine else Double.NaN;
plot Line2ATR = UpLine2;
Line2ATR.SetPaintingStrategy(PaintingStrategy.DASHES);
Line2ATR.AssignValueColor(Color.LIME);
def DnLine1 = if today then DayOpen - ATRLine else Double.NaN;
plot Line3ATR = DnLine1;
Line3ATR.SetPaintingStrategy(PaintingStrategy.DASHES);
Line3ATR.AssignValueColor(Color.LIME);
def DnLine2 = if today then Line3ATR - ATRLine else Double.NaN;
plot Line4ATR = DnLine2;
Line4ATR.SetPaintingStrategy(PaintingStrategy.DASHES);
Line4ATR.AssignValueColor(Color.LIME);
AddChartBubble(IsNAN(LineATR[1]) and !IsNaN(LineATR),LineATR,"Day Open",color.LIME);
AddChartBubble(IsNAN(Line1ATR[1]) and !IsNaN(Line1ATR),Line1ATR,"+1 ATR",color.LIME,yes);
AddChartBubble(IsNAN(Line2ATR[1]) and !IsNaN(Line2ATR),Line2ATR,"+2 ATR",color.LIME,yes);
AddChartBubble(IsNAN(Line3ATR[1]) and !IsNaN(Line3ATR),Line3ATR,"-1 ATR",color.LIME,no);
AddChartBubble(IsNAN(Line4ATR[1]) and !IsNaN(Line4ATR),Line4ATR,"-2 ATR",color.LIME,no);
Thanks, really appreciate it. Works perfectly with the Daily ATR, it's exactly what I'm looking for.@jrwlkr Made some changes, yeah, my bad on the math there. Don't know how I got that messed up.
But also using a Daily ATR on a 5 min chart is not going to work, try a 30 min ATR for a 5 min chart.
Ruby:input ATRLength = 14; input averagetype = AverageType.WILDERS; input BasePeriod = AggregationPeriod.thirty_MIN; input time = 0930; def today = if (GetDay() == GetLastDay()) and (SecondsFromTime(time) >= 0) then 1 else 0; def ATR = MovingAverage(averageType, TrueRange(high(period = baseperiod), close(period = baseperiod), low(period = baseperiod)), atrlength); def DayOpen = if SecondsTillTime(time) == 0 then open else DayOpen[1]; def ATRLine = if SecondsTillTime(time) == 0 then ATR else ATRLine[1]; plot LineATR = if today then DayOpen else Double.NaN; LineATR.SetPaintingStrategy(PaintingStrategy.DASHES); LineATR.AssignValueColor(Color.LIME); def UpLine1 = if today then DayOpen + ATRLine else Double.NaN; plot Line1ATR = UpLine1; Line1ATR.SetPaintingStrategy(PaintingStrategy.DASHES); Line1ATR.AssignValueColor(Color.LIME); def UpLine2 = if today then Line1ATR + ATRLine else Double.NaN; plot Line2ATR = UpLine2; Line2ATR.SetPaintingStrategy(PaintingStrategy.DASHES); Line2ATR.AssignValueColor(Color.LIME); def DnLine1 = if today then DayOpen - ATRLine else Double.NaN; plot Line3ATR = DnLine1; Line3ATR.SetPaintingStrategy(PaintingStrategy.DASHES); Line3ATR.AssignValueColor(Color.LIME); def DnLine2 = if today then Line3ATR - ATRLine else Double.NaN; plot Line4ATR = DnLine2; Line4ATR.SetPaintingStrategy(PaintingStrategy.DASHES); Line4ATR.AssignValueColor(Color.LIME); AddChartBubble(IsNAN(LineATR[1]) and !IsNaN(LineATR),LineATR,"Day Open",color.LIME); AddChartBubble(IsNAN(Line1ATR[1]) and !IsNaN(Line1ATR),Line1ATR,"+1 ATR",color.LIME,yes); AddChartBubble(IsNAN(Line2ATR[1]) and !IsNaN(Line2ATR),Line2ATR,"+2 ATR",color.LIME,yes); AddChartBubble(IsNAN(Line3ATR[1]) and !IsNaN(Line3ATR),Line3ATR,"-1 ATR",color.LIME,no); AddChartBubble(IsNAN(Line4ATR[1]) and !IsNaN(Line4ATR),Line4ATR,"-2 ATR",color.LIME,no);
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.