# ATR Grid (ATR-Based Support & Resistance)
# Assembled by BenTen and @diazlaz at useThinkScript.com
# Converted from https://www.tradingview.com/script/EDN4oFyQ-ATR-0-5-0-7-ranges/
input lvl1 = 0.5;
input lvl2 = 0.7;
input daily_atr_len = 15;
input length = 15;
input AggPeriod = AggregationPeriod.DAY;
input averageType = AverageType.WILDERS;
def h = high(GetSymbol(), period = AggPeriod)[1];
def c = close(GetSymbol(), period = AggPeriod)[1];
def l = low(GetSymbol(), period = AggPeriod)[1];
def atr_func = MovingAverage(averageType, TrueRange(h, c, l), length);
def day_atr = atr_func;
def day_close = c;
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("VBullish", Color.DARK_GREEN);
DefineGlobalColor("Bearish", Color.light_RED);
DefineGlobalColor("VBearish", Color.DARK_RED);
plot p1 = day_close + day_atr;
p1.assignValueColor(COLOR.DARK_RED);
p1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot p7 = day_close + day_atr * lvl2;
p7.assignValueColor(COLOR.RED);
AddCloud(p1, p7, GlobalColor("VBearish"), GlobalColor("VBearish"));
p7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot p5 = day_close + day_atr * lvl1;
p5.assignValueColor(COLOR.RED);
AddCloud(p7, p5, GlobalColor("Bearish"), GlobalColor("Bearish"));
p5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot m5 = day_close - day_atr * lvl1;
m5.assignValueColor(COLOR.GREEN);
#AddCloud(p7,p5,COLOR.GREEN, COLOR.GREEN);
m5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot m7 = day_close - day_atr * lvl2;
m7.assignValueColor(COLOR.GREEN);
AddCloud(m7, m5, GlobalColor("Bullish"), GlobalColor("Bullish"));
m7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot m1 = day_close - day_atr;
m1.assignValueColor(COLOR.DARK_GREEN);
AddCloud(m1, m7, GlobalColor("VBullish"), GlobalColor("VBullish"));
m1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);