Multiple Keltner Channel Lines For ThinkOrSwim

RS Trader

New member
VIP
I would like to have the inputs of the Keltner Channel indicator changed to include multiple factor settings so multiple ATR lines can be displayed. I accomplished this in a study setting by having 4 Keltner Channels included in the study. After saving the study, it won't hold together when applying the study to a different chart. Just a single (standard) factor ATR line is shown. Here is what I'm looking for. These factor input settings are 1.5, 2.5, 3.5, 4.5. I would like to have the option of setting the factor input to any multiple. Thanks

dyKkd1J.png
 
Code:
# Indicator that presents ATR 1,2,3,4 above and below using Keltner channel formula
input displace = 0;
input factor1 = 1.0;
input factor2 = 2.0;
input factor3 = 3.0;
input factor4 = 4.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 shift4 = factor4 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

plot average = MovingAverage(averageType, price, length);
average.SetDefaultColor(GetColor(4));

plot Upper_Band1 = average[-displace] + shift1[-displace];
Upper_Band1 .SetDefaultColor(GetColor(6));
plot Upper_Band2  = average[-displace] + shift2[-displace];
Upper_Band2 .SetDefaultColor(GetColor(0));
plot Upper_Band3 = average[-displace] + shift3[-displace];
Upper_Band3.SetDefaultColor(GetColor(5));
plot Upper_Band4 = average[-displace] + shift4[-displace];
Upper_Band4.SetDefaultColor(GetColor(8));

plot Lower_Band1 = average[-displace] - shift1[-displace];
Lower_Band1 .SetDefaultColor(GetColor(6));
plot Lower_Band2  = average[-displace] - shift2[-displace];
Lower_Band2 .SetDefaultColor(GetColor(0));
plot Lower_Band3 = average[-displace] - shift3[-displace];
Lower_Band3.SetDefaultColor(GetColor(5));
plot Lower_Band4 = average[-displace] - shift4[-displace];
Lower_Band4.SetDefaultColor(GetColor(8));

AddCloud(Upper_Band1, Lower_Band1, Color.LIME, CreateColor(175, 250, 175), no);
AddCloud(Upper_Band3, Upper_Band2, Color.PINK, CreateColor(175, 250, 175), no);
AddCloud(Lower_Band2, Lower_Band3, Color.PINK, CreateColor(175, 250, 175), no);
 
Code:
# Indicator that presents ATR 1,2,3,4 above and below using Keltner channel formula
input displace = 0;
input factor1 = 1.0;
input factor2 = 2.0;
input factor3 = 3.0;
input factor4 = 4.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 shift4 = factor4 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

plot average = MovingAverage(averageType, price, length);
average.SetDefaultColor(GetColor(4));

plot Upper_Band1 = average[-displace] + shift1[-displace];
Upper_Band1 .SetDefaultColor(GetColor(6));
plot Upper_Band2  = average[-displace] + shift2[-displace];
Upper_Band2 .SetDefaultColor(GetColor(0));
plot Upper_Band3 = average[-displace] + shift3[-displace];
Upper_Band3.SetDefaultColor(GetColor(5));
plot Upper_Band4 = average[-displace] + shift4[-displace];
Upper_Band4.SetDefaultColor(GetColor(8));

plot Lower_Band1 = average[-displace] - shift1[-displace];
Lower_Band1 .SetDefaultColor(GetColor(6));
plot Lower_Band2  = average[-displace] - shift2[-displace];
Lower_Band2 .SetDefaultColor(GetColor(0));
plot Lower_Band3 = average[-displace] - shift3[-displace];
Lower_Band3.SetDefaultColor(GetColor(5));
plot Lower_Band4 = average[-displace] - shift4[-displace];
Lower_Band4.SetDefaultColor(GetColor(8));

AddCloud(Upper_Band1, Lower_Band1, Color.LIME, CreateColor(175, 250, 175), no);
AddCloud(Upper_Band3, Upper_Band2, Color.PINK, CreateColor(175, 250, 175), no);
AddCloud(Lower_Band2, Lower_Band3, Color.PINK, CreateColor(175, 250, 175), no);
Fantastic Henry1224. Looks like just what I was looking for. You just made my Holiday Merrier. The best to you and your family. Thanks
 

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