Adding cloud to horizontal ATR lines? Possible?

floydddd

Active member
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.

MF69BwA[1].png



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);
 
here it is, also: is it possible to add more space between the prices and the lines?


Code:
#keltnerlonglines
#by ffffloyd, sleepyz, halcyonguy & someone smarter than me whose name i don't know.
#V2 6/27/25

def na = Double.NaN;

input show_lines_only_current_bar = yes;

input ATRperiod = 20;
input averageType = AverageType.EXPONENTIAL;
input BasePeriod = AggregationPeriod.DAY;

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

input f05 = .50;
input f10 = 1.0;
input f15 = 1.5;

input f20 = 2.0;
input f25 = 2.5;
input f30 = 3.0;

input avglength = 20;
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];

#####

# EXAMPLE def HighATRa = if IsNaN(close) then HighATRa[1] else if draw then (avg + ATR * factor) else na;
#plot highatr = HighATRa[1];

#

def HighATR05 = if IsNaN(close) then HighATR05[1] else if draw then (avg + ATR * f05) else na;
plot highatr05B = HighATR05[1];

def LowATR05 = if IsNaN(close) then lowATR05[1] else if draw then (avg - ATR * f05) else na;
plot lowatr05B = LowATR05[1];

def HighATR10 = if IsNaN(close) then HighATR10[1] else if draw then (avg + ATR * f10) else na;
plot highatr10B = HighATR10[1];

def LowATR10 = if IsNaN(close) then lowATR10[1] else if draw then (avg - ATR * f10) else na;
plot lowatr10B = LowATR10[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 HighATR30 = if IsNaN(close) then highATR30[1] else if draw then (avg + ATR * f30) else na;
plot highatr30B = HighATR30[1];

def LowATR30 =  if IsNaN(close) then lowATR30[1] else if draw then (avg - ATR * f30) else na;
plot lowatr30B = LowATR30[1];

#############

avg20b.SetDefaultColor(Color.yellow);
   avg20b.setlineweight (5);
highatr05B.SetDefaultColor(color = Color.VIOLET); #.5
highatr10B.SetDefaultColor(color = Color.green);   #1
highatr15B.SetDefaultColor(color = Color.white);  # 1.5
  highatr15B.setlineweight (4);
highatr20B.SetDefaultColor(color = Color.MAGENTA); #2
highatr25B.SetDefaultColor(color = Color.WHITE); # 2.5
highatr30B.SetDefaultColor(color = Color.YELLOW);  # 3

lowatr05B.SetDefaultColor(color = Color.VIOLET);
lowatr10B.SetDefaultColor(color = Color.GREEN);
lowatr15B.SetDefaultColor (color = Color.white);
lowatr20B.SetDefaultColor(color = Color.MAGENTA);
lowatr25B.SetDefaultColor(color = Color.WHITE);
lowatr30B.SetDefaultColor (color = Color.YELLOW);


#####

avg20b.SetPaintingStrategy(PaintingStrategy.LINE);

highatr05B.SetPaintingStrategy(PaintingStrategy.LINE);
highatr10B.SetPaintingStrategy(PaintingStrategy.LINE);
highatr15B.SetPaintingStrategy(PaintingStrategy.LINE);
highatr20B.SetPaintingStrategy(PaintingStrategy.LINE);
highatr25B.SetPaintingStrategy(PaintingStrategy.LINE);
highatr30B.SetPaintingStrategy(PaintingStrategy.LINE);

lowatr05B.SetPaintingStrategy(PaintingStrategy.LINE);
lowatr10B.SetPaintingStrategy(PaintingStrategy.LINE);
lowatr15B.SetPaintingStrategy(PaintingStrategy.LINE);
lowatr20B.SetPaintingStrategy(PaintingStrategy.LINE);
lowatr25B.SetPaintingStrategy(PaintingStrategy.LINE);
lowatr30B.SetPaintingStrategy(PaintingStrategy.LINE);

 addcloud (highatr15b, avg20b, color.LIGHT_GRay,color.light_gray);
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
413 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top