# ATR
declare once_per_bar;
input ATR_length = 21;
input ATR_multiplier1 = 1.0;
input ATR_multiplier2 = 2.0;
input ATR_multiplier3 = 3.0;
input averageType = AverageType.SIMPLE;
def AP1 = AggregationPeriod.DAY;
def AP = AggregationPeriod.WEEK;
def friday = if GetDayOfWeek(GetYYYYMMDD()) == 5 then 1 else 0;
def average_true_range = if friday then MovingAverage(averageType, TrueRange(Fundamental(FundamentalType.HIGH, period = AP1), Fundamental(FundamentalType.CLOSE, period = AP1), Fundamental(FundamentalType.LOW, period = AP1)), length = ATR_length) else average_true_range[1];
def priorATR = if friday and !friday[1] then average_true_range[1] else priorATR[1];
plot Midline = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] + average_true_range * 0 else Fundamental(FundamentalType.CLOSE, period = AP)[1] + priorATR * 0;
plot UpperChannel;
plot LowerChannel;
plot UpperChannel2;
plot LowerChannel2;
plot UpperChannel3;
plot LowerChannel3;
UpperChannel = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] + average_true_range * ATR_multiplier1 else Fundamental(FundamentalType.CLOSE, period = AP)[1] + priorATR * ATR_multiplier1;
LowerChannel = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] - average_true_range * ATR_multiplier1 else Fundamental(FundamentalType.CLOSE, period = AP)[1] - priorATR * ATR_multiplier1;
UpperChannel2 = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] + average_true_range * ATR_multiplier2 else Fundamental(FundamentalType.CLOSE, period = AP)[1] + priorATR * ATR_multiplier2;
LowerChannel2 = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] - average_true_range * ATR_multiplier2 else Fundamental(FundamentalType.CLOSE, period = AP)[1] - priorATR * ATR_multiplier2;
UpperChannel3 = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] + average_true_range * ATR_multiplier3 else Fundamental(FundamentalType.CLOSE, period = AP)[1] + priorATR * ATR_multiplier3;
LowerChannel3 = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] - average_true_range * ATR_multiplier3 else Fundamental(FundamentalType.CLOSE, period = AP)[1] - priorATR * ATR_multiplier3;
Midline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Midline.SetDefaultColor(Color.WHITE);
UpperChannel.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowerChannel.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
UpperChannel.SetDefaultColor(Color.ORANGE);
LowerChannel.SetDefaultColor(Color.ORANGE);
UpperChannel.SetLineWeight(1);
LowerChannel.SetLineWeight(1);
UpperChannel2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowerChannel2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
UpperChannel2.SetDefaultColor(Color.ORANGE);
LowerChannel2.SetDefaultColor(Color.ORANGE);
UpperChannel2.SetLineWeight(2);
LowerChannel2.SetLineWeight(2);
UpperChannel3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowerChannel3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
UpperChannel3.SetDefaultColor(Color.ORANGE);
LowerChannel3.SetDefaultColor(Color.ORANGE);
UpperChannel3.SetLineWeight(3);
LowerChannel3.SetLineWeight(3);
https://ibb.co/hXXtzvF
HERE IS AN IMAGE OF HOW THE INDICATOR LOOKS ON THE DAILY TIME FRAME.
I WOULD LIKE THE INDICATOR TO SHOW MONTHLY ATR LINES INSTEAD OF WEEKLY
declare once_per_bar;
input ATR_length = 21;
input ATR_multiplier1 = 1.0;
input ATR_multiplier2 = 2.0;
input ATR_multiplier3 = 3.0;
input averageType = AverageType.SIMPLE;
def AP1 = AggregationPeriod.DAY;
def AP = AggregationPeriod.WEEK;
def friday = if GetDayOfWeek(GetYYYYMMDD()) == 5 then 1 else 0;
def average_true_range = if friday then MovingAverage(averageType, TrueRange(Fundamental(FundamentalType.HIGH, period = AP1), Fundamental(FundamentalType.CLOSE, period = AP1), Fundamental(FundamentalType.LOW, period = AP1)), length = ATR_length) else average_true_range[1];
def priorATR = if friday and !friday[1] then average_true_range[1] else priorATR[1];
plot Midline = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] + average_true_range * 0 else Fundamental(FundamentalType.CLOSE, period = AP)[1] + priorATR * 0;
plot UpperChannel;
plot LowerChannel;
plot UpperChannel2;
plot LowerChannel2;
plot UpperChannel3;
plot LowerChannel3;
UpperChannel = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] + average_true_range * ATR_multiplier1 else Fundamental(FundamentalType.CLOSE, period = AP)[1] + priorATR * ATR_multiplier1;
LowerChannel = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] - average_true_range * ATR_multiplier1 else Fundamental(FundamentalType.CLOSE, period = AP)[1] - priorATR * ATR_multiplier1;
UpperChannel2 = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] + average_true_range * ATR_multiplier2 else Fundamental(FundamentalType.CLOSE, period = AP)[1] + priorATR * ATR_multiplier2;
LowerChannel2 = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] - average_true_range * ATR_multiplier2 else Fundamental(FundamentalType.CLOSE, period = AP)[1] - priorATR * ATR_multiplier2;
UpperChannel3 = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] + average_true_range * ATR_multiplier3 else Fundamental(FundamentalType.CLOSE, period = AP)[1] + priorATR * ATR_multiplier3;
LowerChannel3 = if !friday then Fundamental(FundamentalType.CLOSE, period = AP)[1] - average_true_range * ATR_multiplier3 else Fundamental(FundamentalType.CLOSE, period = AP)[1] - priorATR * ATR_multiplier3;
Midline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Midline.SetDefaultColor(Color.WHITE);
UpperChannel.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowerChannel.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
UpperChannel.SetDefaultColor(Color.ORANGE);
LowerChannel.SetDefaultColor(Color.ORANGE);
UpperChannel.SetLineWeight(1);
LowerChannel.SetLineWeight(1);
UpperChannel2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowerChannel2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
UpperChannel2.SetDefaultColor(Color.ORANGE);
LowerChannel2.SetDefaultColor(Color.ORANGE);
UpperChannel2.SetLineWeight(2);
LowerChannel2.SetLineWeight(2);
UpperChannel3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowerChannel3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
UpperChannel3.SetDefaultColor(Color.ORANGE);
LowerChannel3.SetDefaultColor(Color.ORANGE);
UpperChannel3.SetLineWeight(3);
LowerChannel3.SetLineWeight(3);
https://ibb.co/hXXtzvF
HERE IS AN IMAGE OF HOW THE INDICATOR LOOKS ON THE DAILY TIME FRAME.
I WOULD LIKE THE INDICATOR TO SHOW MONTHLY ATR LINES INSTEAD OF WEEKLY
Last edited: