Keltner Ribbons

I_howard

New member
Hello, hopefully someone can help me with this. I really don't have any experience with writing indicators/studies but have been reviewing lots of codes trying to get a handle on it. I am trying to create an Keltner Channel "Ribbon". to have 4-5 different ATR's on one indicator, but am stuck on how to do this. Below is what I have so far. I would greatly appreciate any feedback or help with this.


declare weak_volume_dependency;

input displace = 0;
input factor = 1.5;
input length = 1;
input price = close;
input averageType = AverageType.EXPONENTIAL;
input trueRangeAverageType = AverageType.EXPONENTIAL;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

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

plot Avg = average[-displace];
Avg.SetDefaultColor(GetColor(1));

plot Upper_Band = average[-displace] + shift[-displace];
Upper_Band.SetDefaultColor(GetColor(8));

plot Lower_Band = average[-displace] - shift[-displace];
Lower_Band.SetDefaultColor(GetColor(5));

plot ATR1;
plot ATR2;
plot ATR3;
plot ATR4;
plot ATR5;


if (factor == 1.5)
then {
ATR1 = KeltnerChannels(price, Length);
ATR2 = KeltnerChannels(price, Length + .5
ATR3 = KeltnerChannels(price, Length + 1
ATR4 = KeltnerChannels(price, Length + 1.5
ATR5 = KeltnerChannels(price, Length + 2

} else {
ATR1 = KeltnerChannels(price, Length);
ATR2 = KeltnerChannels(price, Length * Power(incrementOrMultiplier, .5));
ATR3 = KeltnerChannels(price, Length * Power(incrementOrMultiplier, 1));
ATR4 = KeltnerChannels(price, Length * Power(incrementOrMultiplier, 1.5));
ATR5 = KeltnerChannels(price, Length * Power(incrementOrMultiplier, 2));

}

ATR1.SetDefaultColor(CreateColor(255, 65, 0));
ATR2.SetDefaultColor(CreateColor(255, 90, 0));
ATR3.SetDefaultColor(CreateColor(255, 115, 0));
ATR4.SetDefaultColor(CreateColor(255, 140, 0));
ATR5.SetDefaultColor(CreateColor(255, 150, 0));

What is being flagged is;
if
ATR2 = KeltnerChannels(price, Length + .5
ATR3 = KeltnerChannels(price, Length + 1
ATR4 = KeltnerChannels(price, Length + 1.5
ATR5 = KeltnerChannels(price, Length + 2

} else {
ATR1 = KeltnerChannels(price, Length);
 
Solution
Hello, hopefully someone can help me with this. I really don't have any experience with writing indicators/studies but have been reviewing lots of codes trying to get a handle on it. I am trying to create an Keltner Channel "Ribbon". to have 4-5 different ATR's on one indicator, but am stuck on how to do this. Below is what I have so far. I would greatly appreciate any feedback or help with this.


declare weak_volume_dependency;

input displace = 0;
input factor = 1.5;
input length = 1;
input price = close;
input averageType = AverageType.EXPONENTIAL;
input trueRangeAverageType = AverageType.EXPONENTIAL;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

def average =...
Hello, hopefully someone can help me with this. I really don't have any experience with writing indicators/studies but have been reviewing lots of codes trying to get a handle on it. I am trying to create an Keltner Channel "Ribbon". to have 4-5 different ATR's on one indicator, but am stuck on how to do this. Below is what I have so far. I would greatly appreciate any feedback or help with this.


declare weak_volume_dependency;

input displace = 0;
input factor = 1.5;
input length = 1;
input price = close;
input averageType = AverageType.EXPONENTIAL;
input trueRangeAverageType = AverageType.EXPONENTIAL;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

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

plot Avg = average[-displace];
Avg.SetDefaultColor(GetColor(1));

plot Upper_Band = average[-displace] + shift[-displace];
Upper_Band.SetDefaultColor(GetColor(8));

plot Lower_Band = average[-displace] - shift[-displace];
Lower_Band.SetDefaultColor(GetColor(5));

plot ATR1;
plot ATR2;
plot ATR3;
plot ATR4;
plot ATR5;


if (factor == 1.5)
then {
ATR1 = KeltnerChannels(price, Length);
ATR2 = KeltnerChannels(price, Length + .5
ATR3 = KeltnerChannels(price, Length + 1
ATR4 = KeltnerChannels(price, Length + 1.5
ATR5 = KeltnerChannels(price, Length + 2

} else {
ATR1 = KeltnerChannels(price, Length);
ATR2 = KeltnerChannels(price, Length * Power(incrementOrMultiplier, .5));
ATR3 = KeltnerChannels(price, Length * Power(incrementOrMultiplier, 1));
ATR4 = KeltnerChannels(price, Length * Power(incrementOrMultiplier, 1.5));
ATR5 = KeltnerChannels(price, Length * Power(incrementOrMultiplier, 2));

}

ATR1.SetDefaultColor(CreateColor(255, 65, 0));
ATR2.SetDefaultColor(CreateColor(255, 90, 0));
ATR3.SetDefaultColor(CreateColor(255, 115, 0));
ATR4.SetDefaultColor(CreateColor(255, 140, 0));
ATR5.SetDefaultColor(CreateColor(255, 150, 0));

What is being flagged is;
if
ATR2 = KeltnerChannels(price, Length + .5
ATR3 = KeltnerChannels(price, Length + 1
ATR4 = KeltnerChannels(price, Length + 1.5
ATR5 = KeltnerChannels(price, Length + 2

} else {
ATR1 = KeltnerChannels(price, Length);


3 main things are wrong
---------------------

several code lines are missing ) and a ;
ATR2 = KeltnerChannels(price, Length + .5

------------------------

if you look up KeltnerChannels , you will see what the input parameters are and what order they belong in.
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/G-L/KeltnerChannels

KeltnerChannels( displace, factor, length, price, average type, true range average type )


you are only supplying 2 parameters , price and length.
and they are in the wrong location, 1st and 2nd.
price is the 4th parameter, length is the 3rd parameter.

one way to fix this would be to provide the first 4 parameters, in the correct sequence.

if you don't want to provide the first 4 parameters, you can include the parameter name along with the data. then the order or quantity doesn't matter.

ATR2 = KeltnerChannels(price = price, length = (Length + .5) );

----------------------------

this variable isn't defined, incrementOrMultiplier.
i created the following formula to define it. i have no idea if 2 is a good number.
def incrementOrMultiplier = 2;

it is used in a power function, as the number parameter.
Power(number, power)

----------------------------

i never used this,
declare weak_volume_dependency;
https://tlc.thinkorswim.com/center/reference/thinkScript/Declarations

so i have no comment on it, other than to say, experiment with it and other declares.

-------------------------

here is a patched study, that draws lines.


Code:
# keltner_atr_bands_00

#https://usethinkscript.com/threads/keltner-ribbons.14224/
#Keltner Ribbons

declare weak_volume_dependency;

input displace = 0;
input factor = 1.5;
input length = 1;
input price = close;
input averageType = AverageType.EXPONENTIAL;
input trueRangeAverageType = AverageType.EXPONENTIAL;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

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

plot Avg = average[-displace];
Avg.SetDefaultColor(GetColor(1));

plot Upper_Band = average[-displace] + shift[-displace];
Upper_Band.SetDefaultColor(GetColor(8));

plot Lower_Band = average[-displace] - shift[-displace];
Lower_Band.SetDefaultColor(GetColor(5));


# Power(number, power);    
def incrementOrMultiplier = 2;

plot ATR1;
plot ATR2;
plot ATR3;
plot ATR4;
plot ATR5;

if (factor == 1.5) then {
  ATR1 = KeltnerChannels(price = price, length = length);
  ATR2 = KeltnerChannels(price = price, length = Length + .5);
  ATR3 = KeltnerChannels(price = price, length = Length + 1);
  ATR4 = KeltnerChannels(price = price, length = Length + 1.5);
  ATR5 = KeltnerChannels(price = price, length = Length + 2);
} else {
  ATR1 = KeltnerChannels(price = price, length = Length);
  ATR2 = KeltnerChannels(price = price, length = (length * Power(incrementOrMultiplier, .5)));
  ATR3 = KeltnerChannels(price = price, length = (length * Power(incrementOrMultiplier, 1)));
  ATR4 = KeltnerChannels(price = price, length = (length * Power(incrementOrMultiplier, 1.5)));
  ATR5 = KeltnerChannels(price = price, length = (length * Power(incrementOrMultiplier, 2)));
}

ATR1.SetDefaultColor(CreateColor(255, 65, 0));
ATR2.SetDefaultColor(CreateColor(255, 90, 0));
ATR3.SetDefaultColor(CreateColor(255, 115, 0));
ATR4.SetDefaultColor(CreateColor(255, 140, 0));
ATR5.SetDefaultColor(CreateColor(255, 150, 0));


#  KeltnerChannels(displace, factor, length, price, average type, true range average type )
#
 
Solution
3 main things are wrong
---------------------

several code lines are missing ) and a ;
ATR2 = KeltnerChannels(price, Length + .5

------------------------

if you look up KeltnerChannels , you will see what the input parameters are and what order they belong in.
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/G-L/KeltnerChannels

KeltnerChannels( displace, factor, length, price, average type, true range average type )


you are only supplying 2 parameters , price and length.
and they are in the wrong location, 1st and 2nd.
price is the 4th parameter, length is the 3rd parameter.

one way to fix this would be to provide the first 4 parameters, in the correct sequence.

if you don't want to provide the first 4 parameters, you can include the parameter name along with the data. then the order or quantity doesn't matter.

ATR2 = KeltnerChannels(price = price, length = (Length + .5) );

----------------------------

this variable isn't defined, incrementOrMultiplier.
i created the following formula to define it. i have no idea if 2 is a good number.
def incrementOrMultiplier = 2;

it is used in a power function, as the number parameter.
Power(number, power)

----------------------------

i never used this,
declare weak_volume_dependency;
https://tlc.thinkorswim.com/center/reference/thinkScript/Declarations

so i have no comment on it, other than to say, experiment with it and other declares.

-------------------------

here is a patched study, that draws lines.


Code:
# keltner_atr_bands_00

#https://usethinkscript.com/threads/keltner-ribbons.14224/
#Keltner Ribbons

declare weak_volume_dependency;

input displace = 0;
input factor = 1.5;
input length = 1;
input price = close;
input averageType = AverageType.EXPONENTIAL;
input trueRangeAverageType = AverageType.EXPONENTIAL;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

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

plot Avg = average[-displace];
Avg.SetDefaultColor(GetColor(1));

plot Upper_Band = average[-displace] + shift[-displace];
Upper_Band.SetDefaultColor(GetColor(8));

plot Lower_Band = average[-displace] - shift[-displace];
Lower_Band.SetDefaultColor(GetColor(5));


# Power(number, power);   
def incrementOrMultiplier = 2;

plot ATR1;
plot ATR2;
plot ATR3;
plot ATR4;
plot ATR5;

if (factor == 1.5) then {
  ATR1 = KeltnerChannels(price = price, length = length);
  ATR2 = KeltnerChannels(price = price, length = Length + .5);
  ATR3 = KeltnerChannels(price = price, length = Length + 1);
  ATR4 = KeltnerChannels(price = price, length = Length + 1.5);
  ATR5 = KeltnerChannels(price = price, length = Length + 2);
} else {
  ATR1 = KeltnerChannels(price = price, length = Length);
  ATR2 = KeltnerChannels(price = price, length = (length * Power(incrementOrMultiplier, .5)));
  ATR3 = KeltnerChannels(price = price, length = (length * Power(incrementOrMultiplier, 1)));
  ATR4 = KeltnerChannels(price = price, length = (length * Power(incrementOrMultiplier, 1.5)));
  ATR5 = KeltnerChannels(price = price, length = (length * Power(incrementOrMultiplier, 2)));
}

ATR1.SetDefaultColor(CreateColor(255, 65, 0));
ATR2.SetDefaultColor(CreateColor(255, 90, 0));
ATR3.SetDefaultColor(CreateColor(255, 115, 0));
ATR4.SetDefaultColor(CreateColor(255, 140, 0));
ATR5.SetDefaultColor(CreateColor(255, 150, 0));


#  KeltnerChannels(displace, factor, length, price, average type, true range average type )
#
Thank you for this.
 

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