3 ATR Bands using Keltner Channels for ThinkorSwim

Yes, it works for me.
Capture.jpg
Thanks @SleepyZ!
 
Member request
Bnb5Nfk.png

These are the price levels of the Keltner ATR bands.

This study removes the messy lines and just provides a label.
Label coloring: if close is above the channel green else red.
N6G5sqX.png

Ruby:
# Upper Chart Labels Only
# Indicator that presents ATR 1,2,3 above and below using Keltner channel formula
input displace = 0;
input factor1 = 1.0;
input factor2 = 2.0;
input factor3 = 3.0;
input length = 21;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift1 = factor1 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shift2 = factor2 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shift3 = factor3 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

def average = MovingAverage(averageType, price, length);

def Upper_Band1 = average[-displace] + shift1[-displace];
def Upper_Band2  = average[-displace] + shift2[-displace];
def Upper_Band3 = average[-displace] + shift3[-displace];


def Lower_Band1 = average[-displace] - shift1[-displace];
def Lower_Band2  = average[-displace] - shift2[-displace];
def Lower_Band3 = average[-displace] - shift3[-displace];


AddLabel(yes,"close==" +asdollars(close) +" keltner average==" +asdollars(average),
if close>average then color.green else color.red);

AddLabel(yes," lower3==" +asdollars(Lower_Band3),
if close>Lower_Band3 then color.green else color.red);

AddLabel(yes," lower2==" +asdollars(Lower_Band2),
if close>Lower_Band2 then color.green else color.red);

AddLabel(yes," lower1==" +asdollars(Lower_Band1),
if close>Lower_Band1 then color.green else color.red);

AddLabel(yes," upper1==" +asdollars(Upper_Band1),
if close>Upper_Band1 then color.green else color.red);

AddLabel(yes," upper2==" +asdollars(Upper_Band2),
if close>Upper_Band2 then color.green else color.red);

AddLabel(yes," upper3==" +asdollars(Upper_Band3),
if close>Upper_Band3 then color.green else color.red);
@bsturg
 
Last edited:
Member request
Bnb5Nfk.png

These are the price levels of the Keltner ATR bands.

This study removes the messy lines and just provides a label.
Label coloring: if close is above the channel green else red.
N6G5sqX.png

Ruby:
# Upper Chart Labels Only
# Indicator that presents ATR 1,2,3 above and below using Keltner channel formula
input displace = 0;
input factor1 = 1.0;
input factor2 = 2.0;
input factor3 = 3.0;
input length = 21;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift1 = factor1 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shift2 = factor2 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shift3 = factor3 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

def average = MovingAverage(averageType, price, length);

def Upper_Band1 = average[-displace] + shift1[-displace];
def Upper_Band2  = average[-displace] + shift2[-displace];
def Upper_Band3 = average[-displace] + shift3[-displace];


def Lower_Band1 = average[-displace] - shift1[-displace];
def Lower_Band2  = average[-displace] - shift2[-displace];
def Lower_Band3 = average[-displace] - shift3[-displace];


AddLabel(yes,"close==" +asdollars(close) +" keltner average==" +asdollars(average),
if close>average then color.green else color.red);

AddLabel(yes," lower3==" +asdollars(Lower_Band3),
if close>Lower_Band3 then color.green else color.red);

AddLabel(yes," lower2==" +asdollars(Lower_Band2),
if close>Lower_Band2 then color.green else color.red);

AddLabel(yes," lower1==" +asdollars(Lower_Band1),
if close>Lower_Band1 then color.green else color.red);

AddLabel(yes," upper1==" +asdollars(Upper_Band1),
if close>Upper_Band1 then color.green else color.red);

AddLabel(yes," upper2==" +asdollars(Upper_Band2),
if close>Upper_Band2 then color.green else color.red);

AddLabel(yes," upper3==" +asdollars(Upper_Band3),
if close>Upper_Band3 then color.green else color.red);
@bsturg
This is great. I'm just wondering if we could make it 1 label instead of 3 labels. The one label would change pending on where price is relative to the channels?
 
This is great. I'm just wondering if we could make it 1 label instead of 3 labels. The one label would change pending on where price is relative to the channels?

Here is one way to have 1 label: If close is above/below a level then either a green/red label will appear with the close price, a " > or < ", and the level (average or upper/lower bands 1/2/3)

The image shows the lines for comparison purposes only.
Screenshot 2024-09-03 142849.jpg
Code:
# Upper Chart Labels Only
# Indicator that presents ATR 1,2,3 above and below using Keltner channel formula
input displace = 0;
input factor1 = 1.0;
input factor2 = 2.0;
input factor3 = 3.0;
input length = 21;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift1 = factor1 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shift2 = factor2 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shift3 = factor3 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

def average = MovingAverage(averageType, price, length);

def Upper_Band1 = average[-displace] + shift1[-displace];
def Upper_Band2  = average[-displace] + shift2[-displace];
def Upper_Band3 = average[-displace] + shift3[-displace];


def Lower_Band1 = average[-displace] - shift1[-displace];
def Lower_Band2  = average[-displace] - shift2[-displace];
def Lower_Band3 = average[-displace] - shift3[-displace];


AddLabel(Between(close, Lower_Band1, Upper_Band1), "close==" + AsDollars(close) + (if close < average then " < " else " > ") + " keltner average==" + AsDollars(average),
if close > average then Color.LIGHT_GREEN else Color.LIGHT_RED);

AddLabel(close < Lower_Band3, "close==" + AsDollars(close) + " < lower3==" + AsDollars(Lower_Band3),
Color.LIGHT_RED);

AddLabel(Between(close, Lower_Band3, Lower_Band2), "close==" + AsDollars(close) + " < lower2==" + AsDollars(Lower_Band2),
Color.LIGHT_RED);

AddLabel(Between(close, Lower_Band2, Lower_Band1), "close==" + AsDollars(close) + " < lower1==" + AsDollars(Lower_Band1),
Color.LIGHT_RED);

AddLabel(Between(close, Upper_Band1, Upper_Band2), "close==" + AsDollars(close) + " > upper1==" + AsDollars(Upper_Band1),
Color.LIGHT_GREEN);

AddLabel(Between(close, Upper_Band2, Upper_Band3), "close==" + AsDollars(close) + " > upper2=="   + AsDollars(Upper_Band2),
Color.LIGHT_GREEN);

AddLabel(close > Upper_Band3, "close==" + AsDollars(close) + " > upper3=="  +  AsDollars(Upper_Band3),
Color.LIGHT_GREEN);

#
 
Here is one way to have 1 label: If close is above/below a level then either a green/red label will appear with the close price, a " > or < ", and the level (average or upper/lower bands 1/2/3)

The image shows the lines for comparison purposes only.

This has more options, but is still one label or bubble.
The input label_option has more, less or bubble as the options.
The more is the label (eg:
Screenshot 2024-09-04 130632.jpg
, less is
Screenshot 2024-09-04 131003.jpg
and the bubble is the less label view floating with the close in the right expansion.
The bubble can be moved sideways at the input bubblemover;

The image shows the bubble with the lines added for comparion

Screenshot 2024-09-04 125953.jpg
Code:
# Upper Chart Labels Only
# Indicator that presents ATR 1,2,3 above and below using Keltner channel formula
input label_option = {default More, Less, Bubble};
input displace = 0;
input factor1  = 1.0;
input factor2  = 2.0;
input factor3  = 3.0;
input length = 21;
input price  = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift1 = factor1 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shift2 = factor2 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shift3 = factor3 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

def average = MovingAverage(averageType, price, length);

def Upper_Band1 = average[-displace] + shift1[-displace];
def Upper_Band2  = average[-displace] + shift2[-displace];
def Upper_Band3 = average[-displace] + shift3[-displace];


def Lower_Band1 = average[-displace] - shift1[-displace];
def Lower_Band2  = average[-displace] - shift2[-displace];
def Lower_Band3 = average[-displace] - shift3[-displace];


AddLabel(if label_option==label_option.bubble then double.nan else Between(close, Lower_Band1, Upper_Band1), if label_option==label_option.less then "AVG" else "close==" + AsDollars(close) + (if close < average then " < " else " > ") + " keltner average==" + AsDollars(average),
if close > average then Color.LIGHT_GREEN else Color.LIGHT_RED);

AddLabel(if label_option==label_option.bubble then double.nan else close < Lower_Band3, if label_option==label_option.less then "L-3" else "close==" + AsDollars(close) + " < lower3==" + AsDollars(Lower_Band3),
Color.LIGHT_RED);

AddLabel(if label_option==label_option.bubble then double.nan else Between(close, Lower_Band3, Lower_Band2), if label_option==label_option.less then "L-2" else "close==" + AsDollars(close) + " < lower2==" + AsDollars(Lower_Band2),
Color.LIGHT_RED);

AddLabel(if label_option==label_option.bubble then double.nan else Between(close, Lower_Band2, Lower_Band1), if label_option==label_option.less then "L-1" else "close==" + AsDollars(close) + " < lower1==" + AsDollars(Lower_Band1),
Color.LIGHT_RED);

AddLabel(if label_option==label_option.bubble then double.nan else Between(close, Upper_Band1, Upper_Band2), if label_option==label_option.less then "U-1" else "close==" + AsDollars(close) + " > upper1==" + AsDollars(Upper_Band1),
Color.LIGHT_GREEN);

AddLabel(if label_option==label_option.bubble then double.nan else Between(close, Upper_Band2, Upper_Band3), if label_option==label_option.less then "U-2" else "close==" + AsDollars(close) + " > upper2=="   + AsDollars(Upper_Band2),
Color.LIGHT_GREEN);

AddLabel(if label_option==label_option.bubble then double.nan else close > Upper_Band3, if label_option==label_option.less then "U-3" else "close==" + AsDollars(close) + " > upper3=="  +  AsDollars(Upper_Band3),
Color.LIGHT_GREEN);

#----------------------------
#Bubble option
input bubblemover = 2;
def b  = bubblemover;
def b1 = b + 1;

addchartbubble(close[b1]>= Average[b1] and label_option==label_option.bubble and isnan(close[b]) and !isnan(close[b1]), close[b1],
if Between(close[b1], Lower_Band1[b1], Upper_Band1[b1]) then "AVG" else if close[b1]>Upper_Band3[b1] then "U-3" else if Between(close[b1], Upper_Band2[b1], Upper_Band3[b1]) then "U-2" else "U-1", color.green);

addchartbubble(close[b1]< Average[b1] and label_option==label_option.bubble and isnan(close[b]) and !isnan(close[b1]), close[b1],
if Between(close[b1], Lower_Band1[b1], Upper_Band1[b1]) then "AVG" else if close[b1]<Lower_Band3[b1] then "L-3" else if Between(close[b1], Lower_Band3[b1], Lower_Band2[b1]) then "L-2" else "L-1", color.light_red);
#
 

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
335 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