Hi,
Can someone please assist on a TOS code to draw a horizontal line of 3 ATR (average true range) moves above and below the 21EMA
#ATR_horz_lines
#https://usethinkscript.com/threads/horizontal-atr.22497/
#Horizontal ATR
#opeyemiajoje 7/4
#Can someone please assist on a TOS code to draw a horizontal line of 3 ATR (average true range) moves above and below the 21EMA
def na = double.nan;
def bn = barnumber();
# x is true during a...
input emaLength = 21;
input atrLength = 14;
input atrMult = 3;
input atrAvgType = AverageType.WILDERS;
# 21 EMA of close
plot ema21 = ExpAverage(close, emaLength);
EMA21.SetDefaultColor(Color.CYAN);
EMA21.SetLineWeight(2);
# ATR based on Wilder's average of TrueRange
def tr = TrueRange(high, close, low);
def atr = MovingAverage(atrAvgType, tr, atrLength);
# Levels: 3 ATR above and below the 21 EMA
plot upperATR = ema21 + atrMult * atr;
plot lowerATR = ema21 - atrMult * atr;
upperATR.SetDefaultColor(Color.GREEN);
lowerATR.SetDefaultColor(Color.RED);
upperATR.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lowerATR.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
upperATR.SetLineWeight(2);
lowerATR.SetLineWeight(2);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Code:input emaLength = 21; input atrLength = 14; input atrMult = 3; input atrAvgType = AverageType.WILDERS; # 21 EMA of close plot ema21 = ExpAverage(close, emaLength); EMA21.SetDefaultColor(Color.CYAN); EMA21.SetLineWeight(2); # ATR based on Wilder's average of TrueRange def tr = TrueRange(high, close, low); def atr = MovingAverage(atrAvgType, tr, atrLength); # Levels: 3 ATR above and below the 21 EMA plot upperATR = ema21 + atrMult * atr; plot lowerATR = ema21 - atrMult * atr; upperATR.SetDefaultColor(Color.GREEN); lowerATR.SetDefaultColor(Color.RED); upperATR.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); lowerATR.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); upperATR.SetLineWeight(2); lowerATR.SetLineWeight(2);
Hi,
Can someone please assist on a TOS code to draw a horizontal line of 3 ATR (average true range) moves above and below the 21EMA
#ATR_horz_lines
#https://usethinkscript.com/threads/horizontal-atr.22497/
#Horizontal ATR
#opeyemiajoje 7/4
#Can someone please assist on a TOS code to draw a horizontal line of 3 ATR (average true range) moves above and below the 21EMA
def na = double.nan;
def bn = barnumber();
# x is true during a group of bars, ending at the last bar
input last_bars = 8;
def z = !isnan(close[ (-(last_bars-1)) ]) and isnan(close[-last_bars]);
#addverticalline(z, "-", color.cyan);
input ema_length = 21;
input atr_length = 14;
input atr_mult = 3.0;
input atrAvgType = AverageType.WILDERS;
plot ema = ExpAverage(close, ema_length);
EMA.SetDefaultColor(Color.CYAN);
EMA.SetLineWeight(2);
def tr = TrueRange(high, close, low);
def atr = MovingAverage(atrAvgType, tr, atr_length);
def upperATR = ema + atr_mult * atr;
def lowerATR = ema - atr_mult * atr;
#plot u1 = upperatr;
#plot l1 = loweratr;
# define horz lines
def upper;
def lower;
if bn == 1 then {
upper = na;
lower = na;
} else if z then {
upper = getvalue(upperATR, -(last_bars-1));
lower = getvalue(lowerATR, -(last_bars-1));
} else {
upper = upper[1];
lower = lower[1];
}
plot ua = upper;
plot la = lower;
ua.SetDefaultColor(Color.GREEN);
ua.SetStyle(Curve.MEDIUM_DASH);
# ua.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ua.SetLineWeight(2);
la.SetDefaultColor(Color.RED);
la.SetStyle(Curve.MEDIUM_DASH);
#la.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
la.SetLineWeight(2);
#
Thank youhere you go
draw horizontal ATR lines , x bars back, from last bar, based on prices on last bar.
you can pick how many bars back to start the lines.
i modified mc01439 code.
enable these lines to see continuous lines that follow the ema line.
#plot u1 = upperatr;
#plot l1 = loweratr;
Code:#ATR_horz_lines #https://usethinkscript.com/threads/horizontal-atr.22497/ #Horizontal ATR #opeyemiajoje 7/4 #Can someone please assist on a TOS code to draw a horizontal line of 3 ATR (average true range) moves above and below the 21EMA def na = double.nan; def bn = barnumber(); # x is true during a group of bars, ending at the last bar input last_bars = 8; def z = !isnan(close[ (-(last_bars-1)) ]) and isnan(close[-last_bars]); #addverticalline(z, "-", color.cyan); input ema_length = 21; input atr_length = 14; input atr_mult = 3.0; input atrAvgType = AverageType.WILDERS; plot ema = ExpAverage(close, ema_length); EMA.SetDefaultColor(Color.CYAN); EMA.SetLineWeight(2); def tr = TrueRange(high, close, low); def atr = MovingAverage(atrAvgType, tr, atr_length); def upperATR = ema + atr_mult * atr; def lowerATR = ema - atr_mult * atr; #plot u1 = upperatr; #plot l1 = loweratr; # define horz lines def upper; def lower; if bn == 1 then { upper = na; lower = na; } else if z then { upper = getvalue(upperATR, -(last_bars-1)); lower = getvalue(lowerATR, -(last_bars-1)); } else { upper = upper[1]; lower = lower[1]; } plot ua = upper; plot la = lower; ua.SetDefaultColor(Color.GREEN); ua.SetStyle(Curve.MEDIUM_DASH); # ua.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); ua.SetLineWeight(2); la.SetDefaultColor(Color.RED); la.SetStyle(Curve.MEDIUM_DASH); #la.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); la.SetLineWeight(2); #
| Thread starter | Similar threads | Forum | Replies | Date |
|---|---|---|---|---|
| F | Adding cloud to horizontal ATR lines? Possible? | Questions | 2 | |
| S | How to plot a horizontal line at the ATR level? | Questions | 19 | |
| J | ATR Horizontal line | Questions | 2 | |
| A | Auto plot horizontal lines on close and open based on RelativeVolumeStDev | Questions | 1 | |
| J | Plot horizontal lines based on latest Mark price | Questions | 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.