so here's a study for horizontal keltner atr lines plotted in the expansion area. i'm trying to get a cloud to appear between any two lines if the price is between them and to move if price should move to be between a different set of lines. i've tried the following code as a for-instance example, without luck, and don't know what to do next.
def var = if between(close,highatr20B,highatr25B) then highatr25B else double.nan;
AddCloud(var,highatr20B,color.yellow,color.yellow);
can anyone help?
p.s. the code below is an abbreviation of the full one and lacks coding for colors and additional ATR levels. it should, however, be sufficient for my question, i hope.
the arrow in the picture shows were the cloud should appear for that stock based on the closing price for that day.
def var = if between(close,highatr20B,highatr25B) then highatr25B else double.nan;
AddCloud(var,highatr20B,color.yellow,color.yellow);
can anyone help?
p.s. the code below is an abbreviation of the full one and lacks coding for colors and additional ATR levels. it should, however, be sufficient for my question, i hope.
the arrow in the picture shows were the cloud should appear for that stock based on the closing price for that day.
Code:
def na = Double.NaN;
input show_lines_only_current_bar = yes;
input ATRperiod = 20;
input averageType = AverageType.EXPONENTIAL;
input BasePeriod = AggregationPeriod.DAY;
input f15 = 1.5;
input f20 = 2.0;
input f25 = 2.5;
input avglength = 20;
# is the current bar in the current day?
def istoday = if GetLastDay() == GetDay() then 1 else 0;
def draw = if (show_lines_only_current_bar and istoday) then 1 else if !show_lines_only_current_bar then 1 else 0;
def DailyClose = close(period = ”DAY”);
def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”), close(period = ”DAY”), low(period = ”DAY”)), ATRperiod);
def avg = MovingAverage(AverageType.EXPONENTIAL, close, length = avglength);
def avg20 = if IsNaN(close) then avg20[1] else if draw then avg else na;
plot avg20b = avg20[1];
#
def HighATR15 = if IsNaN(close) then HighATR15[1] else if draw then (avg + ATR * f15) else na;
plot highatr15B = HighATR15[1];
def LowATR15 = if IsNaN(close) then lowATR15[1] else if draw then (avg - ATR * f15) else na;
plot lowatr15B = LowATR15[1];
def HighATR20 = if IsNaN(close) then HighATR20[1] else if draw then (avg + ATR * f20) else na;
plot highatr20B = HighATR20[1];
def LowATR20 = if IsNaN(close) then lowATR20[1] else if draw then (avg - ATR * f20) else na;
plot lowatr20B = LowATR20[1];
def HighATR25 = if IsNaN(close) then HighATR25[1] else if draw then (avg + ATR * f25) else na;
plot highatr25B = HighATR25[1];
def LowATR25 = if IsNaN(close) then lowATR25[1] else if draw then (avg - ATR * f25) else na;
plot lowatr25B = LowATR25[1];
#def var = if between(close,highatr20B,highatr25B) then highatr25B else double.nan;
AddCloud(var,highatr20B,color.yellow,color.yellow);