# of days above and below Keltner Channels

chrislid33

New member
How would I code the following:

Count the number of daily bars in the last 3 years that closed above the Keltner Channel upper band with KC settings as factor 4, length 50 and exponential moving average. Would like this number as a column in a scan.

Same thing as above but closes below lower KC band.
 
Last edited by a moderator:
Solution
How would I code the following:

Count the number of daily bars in the last 3 years that closed above the Keltner Channel upper band with KC settings as factor 4, length 50 and exponential moving average. Would like this number as a column in a scan.

Same thing as above but closes below lower KC band.

this might be close to what you want
it uses 252 for quantity of days in a year

counts the times close is above upper band and below lower band. display both numbers. colors the text based on which is bigger.

column study

Code:
#zkeltupdwn
# daily column

# keltner_3years_levels

#https://usethinkscript.com/threads/of-days-closed-above-and-below-keltner-channels-in-past-3-years.18487/
# of days closed above and below Keltner...
How would I code the following:

Count the number of daily bars in the last 3 years that closed above the Keltner Channel upper band with KC settings as factor 4, length 50 and exponential moving average. Would like this number as a column in a scan.

Same thing as above but closes below lower KC band.

this might be close to what you want
it uses 252 for quantity of days in a year

counts the times close is above upper band and below lower band. display both numbers. colors the text based on which is bigger.

column study

Code:
#zkeltupdwn
# daily column

# keltner_3years_levels

#https://usethinkscript.com/threads/of-days-closed-above-and-below-keltner-channels-in-past-3-years.18487/
# of days closed above and below Keltner Channels in past 3 years

# keltnerch
# declare weak_volume_dependency;

#declare lower;

input displace = 0;
#input factor = 1.5;
input factor = 4.0;
#input length = 20;
input length = 50;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

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

def Avg = average[-displace];
#Avg.SetDefaultColor(GetColor(1));
def Upper_Band = average[-displace] + shift[-displace];
#Upper_Band.SetDefaultColor(GetColor(8));
def Lower_Band = average[-displace] - shift[-displace];
#Lower_Band.SetDefaultColor(GetColor(5));


# about 252 days in a year
def years3 = 756;

def dayabove = (close > upper_band);
def daybelow = (close < lower_band);

def abovecnt = sum(dayabove,years3);
def belowcnt = sum(daybelow,years3);

#addlabel(1,abovecnt, color.yellow);
#addlabel(1,belowcnt, color.yellow);

addlabel(1, (abovecnt + " / " + belowcnt), (if abovecnt > belowcnt then color.green else color.red));
#


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

this is a lower study to test with

[code]
# keltner_3years_levels

#https://usethinkscript.com/threads/of-days-closed-above-and-below-keltner-channels-in-past-3-years.18487/
# of days closed above and below Keltner Channels in past 3 years
# keltnerch
# declare weak_volume_dependency;

declare lower;

input displace = 0;
#input factor = 1.5;
input factor = 4.0;
#input length = 20;
input length = 50;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

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

def Avg = average[-displace];
#Avg.SetDefaultColor(GetColor(1));
def Upper_Band = average[-displace] + shift[-displace];
#Upper_Band.SetDefaultColor(GetColor(8));
def Lower_Band = average[-displace] - shift[-displace];
#Lower_Band.SetDefaultColor(GetColor(5));


# about 252 days in a year
def years3 = 756;

def dayabove = (close > upper_band);
def daybelow = (close < lower_band);

def abovecnt = sum(dayabove,years3);
def belowcnt = sum(daybelow,years3);

addlabel(1,abovecnt, color.yellow);
addlabel(1,belowcnt, color.yellow);

addlabel(1, (abovecnt + " / " + belowcnt), color.yellow);
#
 

Attachments

  • col-img1.JPG
    col-img1.JPG
    36.9 KB · Views: 80
Solution

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