Momentum Keltner Channels for ThinkorSwim

@camerdr Check if this provides the results you wish -

Scanner Code -
Code:
# Momentum Keltner Channels Scan
# Based on the FW_MOBO code by TOS user davidinc (aka Firstwave, aka David Elliott)

input length       =     34;
input factor       =     0.5;
input displace     =     0;
input price        =     close;
input type         =     AverageType.SIMPLE;

def nan      =   double.nan;
def shift    =   factor * MovingAverage(type, TrueRange(high, close, low), length);
def avg      =   MovingAverage(type, price, length);
def line1    =   avg[-displace] - shift[-displace];
def line2    =   avg[-displace] + shift[-displace];
def Chg      =   if(close > line2, 1, if(close < line1, -1, 0));
def Hold     =   CompoundValue(1,if(Hold[1] == Chg or Chg == 0, Hold[1], if(Chg == 1, 1, -1)), 0);

def n1 = Hold[0] == 1;
def n2 = Hold[0] == -1;
def countup = if n1 and !n1[1] then 1 else countup[1]+1;
def countdn = if n2 and !n2[1] then 1 else countdn[1]+1;

plot scan_for_break_up = if n1 then if(countup < 3, 1, 0) else 0;
#plot scan_for_break_down = if n2 then if(countdn < 3, 1, 0) else 0;

#End of code

Also, here is a watchlist column for anyone interested. Figured might as well make one. :)

Watchlist Code -
Code:
# Momentum Keltner Channels Watchlist Column
# Based on the FW_MOBO code by TOS user davidinc (aka Firstwave, aka David Elliott)
# The count displayed in the watchlist shows the number of bars since a break up or break down

input length       =     34;
input factor       =     0.5;
input displace     =     0;
input price        =     close;
input type         =     AverageType.SIMPLE;

def nan      =   double.nan;
def shift    =   factor * MovingAverage(type, TrueRange(high, close, low), length);
def avg      =   MovingAverage(type, price, length);
def line1    =   avg[-displace] - shift[-displace];
def line2    =   avg[-displace] + shift[-displace];
def Chg      =   if(close > line2, 1, if(close < line1, -1, 0));
def Hold     =   CompoundValue(1,if(Hold[1] == Chg or Chg == 0, Hold[1], if(Chg == 1, 1, -1)), 0);

def n1 = Hold[0] == 1;
def n2 = Hold[0] == -1;
def count1 = if n1 and !n1[1] then 1 else count1[1]+1;
def count2 = if n2 and !n2[1] then 1 else count2[1]+1;

plot n = if n1 then count1 else if n2 then count2 else double.nan;
     n.setdefaultcolor(color.black);
assignbackgroundcolor(if n1 and count1 then color.green else color.red);
#End of code
Great job. I’m running out of the custom watchlist variables, could you make a share link of the watchlist script so I can download directly to TOS? Tks
 
I have the momentum scanner installed as well as the momentum study for my charts. Does anyone know if there is a way to get an alert as soon as a candle closes with a green arrow under it (in the chart momentum study)? I would like to make another scanner to notify me of a stock where the arrow has populated. It seems that once a stock comes up on the momentum scanner, it has already had it's run. Thank you.

P.S. - I tried to attach a pic of the momentum scanner I am currently using but I can't attach it for some reason.
 

Thanks Ben, but I think you're not understanding my question. So I used the code at the beginning of this thread to create a "Momentum Scanner" as well as the "Momentum Study" to add to my charts. The chart will show a green arrow underneath the candle once that condition is met, signaling that the stock may begin to rise quickly. I was wanting to create a scanner to scan for this signal.

The "Momentum Scanner" will mainly scan for high relative volume, which is great, but by the time I click on the chart, the stock has already risen rapidly from the green arrow several candles before. Is there a way to create a scanner that scans for this signal? I know how to set it as a watchlist and create alerts to myself when one is added.

I am including a pic of the "Momentum Scanner" settings that I am using. Thank you.

tUIAweY.png
 
Is there anyway to make scan to show the green ARROW as soon as it appears . ?
what do you mean by the number in watchlist ( green box and red box ) .

thank u
p_1884brf9h1.png
p_18848jm1q1.png
 

Attachments

  • p_1884brf9h1.png
    p_1884brf9h1.png
    160.6 KB · Views: 434
Last edited by a moderator:
Is there anyway to make scan to show the green ARROW as soon as it appears . ?
what do you mean by the number in watchlist ( green box and red box ) .

thank u
p_1884brf9h1.png
p_18848jm1q1.png
# The count displayed in the watchlist shows the number of bars since a break up or break down. Just scan for 1 bar count
 

Attachments

  • p_1884brf9h1.png
    p_1884brf9h1.png
    160.6 KB · Views: 430
Thank you @BenTen and Mr. Ken Rose for sharing the script. Really fun and promising strategy. Made some adjustment to work with 1min chart, added bullish/bearish arrow, added alert, and watchlist scan. Good luck! @cabe1332

s4QF6s3.png


g38qR7K.png
Wonder if you could share your code how you got thumbs to color both red/green? Mine is only coloring for green:

AddLabel(yes, if ArUp then "👍" else if ArDn then "👎" else " ", if ArUp then Color.green else if ArDn then Color.red else Color.red);

3NjuLFa.jpg
 
@Iceman1205us
I do not use this indicator. So I can't say if the logic of your code is sound.
However, this is the code that the author of this study uses for watchlist, scanners and labels, modified to display your 'thumbs'.
Watchlist Column:
b1.png

Ruby:
# Momentum Keltner Channels Watchlist Column
# Based on the FW_MOBO code by TOS user davidinc (aka Firstwave, aka David Elliott)

input length       =     34;
input factor       =     0.5;
input displace     =     0;
input price        =     close;
input type         =     AverageType.SIMPLE;

def nan      =   double.nan;
def shift    =   factor * MovingAverage(type, TrueRange(high, close, low), length);
def avg      =   MovingAverage(type, price, length);
def line1    =   avg[-displace] - shift[-displace];
def line2    =   avg[-displace] + shift[-displace];
def Chg      =   if(close > line2, 1, if(close < line1, -1, 0));
def Hold     =   CompoundValue(1,if(Hold[1] == Chg or Chg == 0, Hold[1], if(Chg == 1, 1, -1)), 0);

def n1 = Hold[0] == 1;
def n2 = Hold[0] == -1;
def count1 = if n1 and !n1[1] then 1 else count1[1]+1;
def count2 = if n2 and !n2[1] then 1 else count2[1]+1;

def n = if n1 then count1 else if n2 then count2 else double.nan;
AddLabel(1,
if n1 then "👍" else "👎",
if n1 then color.green else color.red);
 
#End of code

Label Study:
Screenshot (87).png

Ruby:
# Momentum Keltner Channels Upper Study Label
# Based on the FW_MOBO code by TOS user davidinc (aka Firstwave, aka David Elliott)

input length       =     34;
input factor       =     0.5;
input displace     =     0;
input price        =     close;
input type         =     AverageType.SIMPLE;

def nan      =   double.nan;
def shift    =   factor * MovingAverage(type, TrueRange(high, close, low), length);
def avg      =   MovingAverage(type, price, length);
def line1    =   avg[-displace] - shift[-displace];
def line2    =   avg[-displace] + shift[-displace];
def Chg      =   if(close > line2, 1, if(close < line1, -1, 0));
def Hold     =   CompoundValue(1,if(Hold[1] == Chg or Chg == 0, Hold[1], if(Chg == 1, 1, -1)), 0);

def n1 = Hold[0] == 1;
def n2 = Hold[0] == -1;
def count1 = if n1 and !n1[1] then 1 else count1[1]+1;
def count2 = if n2 and !n2[1] then 1 else count2[1]+1;

def n = if n1 then count1 else if n2 then count2 else double.nan;

AddLabel(1,
if n1 then "👍" else "👎",
if n1 then color.green else color.red);
 
Last edited:
Is there a custom code written on here that gives me an arrow for when the price closes outside the Keltner Channels, something just like the Bollinger Band Crossover?
 
@Iceman1205us
I do not use this indicator. So I can't say if the logic of your code is sound.
However, this is the code that the author of this study uses for watchlist, scanners and labels, modified to display your 'thumbs'.
Watchlist Column:
View attachment 908
Ruby:
# Momentum Keltner Channels Watchlist Column
# Based on the FW_MOBO code by TOS user davidinc (aka Firstwave, aka David Elliott)

input length       =     34;
input factor       =     0.5;
input displace     =     0;
input price        =     close;
input type         =     AverageType.SIMPLE;

def nan      =   double.nan;
def shift    =   factor * MovingAverage(type, TrueRange(high, close, low), length);
def avg      =   MovingAverage(type, price, length);
def line1    =   avg[-displace] - shift[-displace];
def line2    =   avg[-displace] + shift[-displace];
def Chg      =   if(close > line2, 1, if(close < line1, -1, 0));
def Hold     =   CompoundValue(1,if(Hold[1] == Chg or Chg == 0, Hold[1], if(Chg == 1, 1, -1)), 0);

def n1 = Hold[0] == 1;
def n2 = Hold[0] == -1;
def count1 = if n1 and !n1[1] then 1 else count1[1]+1;
def count2 = if n2 and !n2[1] then 1 else count2[1]+1;

def n = if n1 then count1 else if n2 then count2 else double.nan;
AddLabel(1,
if n1 then "👍" else "👎",
if n1 then color.green else color.red);
 
#End of code

Label Study:
View attachment 907
Ruby:
# Momentum Keltner Channels Upper Study Label
# Based on the FW_MOBO code by TOS user davidinc (aka Firstwave, aka David Elliott)

input length       =     34;
input factor       =     0.5;
input displace     =     0;
input price        =     close;
input type         =     AverageType.SIMPLE;

def nan      =   double.nan;
def shift    =   factor * MovingAverage(type, TrueRange(high, close, low), length);
def avg      =   MovingAverage(type, price, length);
def line1    =   avg[-displace] - shift[-displace];
def line2    =   avg[-displace] + shift[-displace];
def Chg      =   if(close > line2, 1, if(close < line1, -1, 0));
def Hold     =   CompoundValue(1,if(Hold[1] == Chg or Chg == 0, Hold[1], if(Chg == 1, 1, -1)), 0);

def n1 = Hold[0] == 1;
def n2 = Hold[0] == -1;
def count1 = if n1 and !n1[1] then 1 else count1[1]+1;
def count2 = if n2 and !n2[1] then 1 else count2[1]+1;

def n = if n1 then count1 else if n2 then count2 else double.nan;

AddLabel(1,
if n1 then "👍" else "👎",
if n1 then color.green else color.red);
Hello, post #74 has 2 codes is there any difference?
 
I made this indicator some time ago based on the FW_MOBO code. After doing a few changes recently, I thought I might share it here. :) It is similar to Raghee Horner's GRaB indicator, but uses keltner channels instead of offset 34 EMAs. I feel it is best for showing trends in the market.

Code:
# MomentumKeltnerChannels
# Pensar
# 06/06/2020
# Based on the FW_MOBO code by TOS user davidinc (aka Firstwave, aka David Elliott)
# Modified code to use Keltner Channels, changed code structure.
# Added colored price and user-adjustable global colors.

#Inputs
input length       =     34;
input factor       =     0.5;
input displace     =     0;
input price        =     close;
input type         =     AverageType.SIMPLE;
input pricecolor   =     yes;
input fill         =     yes;
input arrows       =     yes;
input alerts       =     yes;
input sound        =     {default "Ding", "Bell", "Chimes", "NoSound", "Ring"};

#Variables
def nan      =   double.nan;
def shift    =   factor * MovingAverage(type, TrueRange(high, close, low), length);
def avg      =   MovingAverage(type, price, length);
def line1    =   avg[-displace] - shift[-displace];
def line2    =   avg[-displace] + shift[-displace];
def Chg      =   if(close > line2, 1, if(close < line1, -1, 0));
def Hold     =   CompoundValue(1,if(Hold[1] == Chg or Chg == 0, Hold[1], if(Chg == 1, 1, -1)), 0);
def ArUp     =   if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == 1 then line1 else nan;
def ArDn     =   if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == -1 then line2 else nan;
def LBUp     =   if fill and Hold[0] == 1 then line2 else nan;
def UBUp     =   if fill and Hold[0] == 1 then line1 else nan;
def LBDn     =   if fill and Hold[0] == -1 then line2 else nan;
def UBDn     =   if fill and Hold[0] == -1 then line1 else nan;
def AlertUp  =   alerts and Hold[1] ==  1 and (Hold[1] <> Hold[2]);
def AlertDn  =   alerts and Hold[1] == -1 and (Hold[1] <> Hold[2]);

#Colors
DefineGlobalColor("Cloud Up", color.dark_green);
DefineGlobalColor("Cloud Dn", color.dark_red);
DefineGlobalColor("Channel Up", color.green);
DefineGlobalColor("Channel Down", color.red);
DefineGlobalColor("Price Up", color.green);
DefineGlobalColor("Price Neutral", color.gray);
DefineGlobalColor("Price Down", color.red);

#Plots
plot UB = line1;
     UB.SetLineWeight(1);
     UB.AssignValueColor(if Hold[0] == 1 then GlobalColor("Channel Up")
                         else GlobalColor("Channel Down"));
plot LB = line2;
     LB.SetLineWeight(1);
     LB.AssignValueColor(if Hold[0] == 1 then GlobalColor("Channel Up")
                         else GlobalColor("Channel Down"));
plot BOA = ArUp;
     BOA.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
     BOA.SetDefaultColor(color.green);
     BOA.SetLineWeight(2);
plot BDA = ArDn;
     BDA.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
     BDA.SetDefaultColor(color.red);
     BDA.SetLineWeight(2);

#Clouds
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));

#Price Color
AssignPriceColor(if pricecolor then if close > line2 then GlobalColor("Price Up")
                 else if close < line1 then GlobalColor("Price Down")
                 else GlobalColor("Price Neutral")
                 else color.current);

#Alerts
Alert(AlertUp, "BREAKOUT!",  Alert.Bar, Sound);
Alert(AlertDn, "BREAKDOWN!", Alert.Bar, Sound);

# --- End code ---

fqIN3pb.png
Hello,
Do you tell if this Keltner is based on ema? 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
266 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