#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);
#