Anchored Momentum [LazyBear] For ThinkOrSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Interesting indicator

I left all the original code in the translation so that if I made a mistake, it's simpler for folks to find.

enjoy

-mashume
Code:
declare lower;
# //
# // @author LazyBear 
# // List of all my indicators: 
# // https://docs.google.com/document/d/15AGCufJZ8CIUvwFJ9W-IKns88gkWOKBCvByMEvm5MLo/edit?usp=sharing
# // 
# study("Anchored Momentum [LazyBear]", shorttitle="AMOM_LB")

# thinkscript conversion by mashume 2022.10

# src=close
input src = close;

# l=input(10, title="Momentum Period")
input MomentumPeriod = 10;
def l = MomentumPeriod;

# sl=input(8, title="Signal Period")
input SignalPeriod = 8;
def sl = SignalPeriod;

# sm=input(false, title="Smooth Momentum")
input SmoothMomentum = no;
def sm = SmoothMomentum;

# smp=input(7, title="Smoothing Period")
input SmoothingPeriod = 7;
def smp = SmoothingPeriod;

# sh=input(false, title="Show Histogram")
input ShowHistogram = yes;
def sh = ShowHistogram;

# eb=input(false, title="Enable Barcolors")
input EnableBarcolors = yes;
def eb = EnableBarcolors;

# p=2*l+1
def p = 2 * l + 1;

# amom=100*(((sm?ema(src,smp):src)/(sma(src,p)) - 1))
def t_amom = if sm == yes then ExpAverage(src, smp) else src;
def amom = 100 * ( (t_amom / ( Average(src, p)) - 1));

# amoms=sma(amom, sl)
def amoms = Average(amom, sl);

# hline(0, title="ZeroLine")
plot ZeroLine = 0;

# hl=sh ? amoms<0 and amom<0 ? max(amoms, amom) : amoms>0 and amom>0 ? min(amoms, amom) : 0 : na
def hl = 
    if amoms < 0 and amom < 0 then Max(amoms, amom) 
    else
        if amoms > 0 and amom > 0 then Min(amoms, amom) 
        else 0 
#     else double.nan
;
plot histogram = if sh == yes then hl else Double.NaN;

# hlc=(amom>amoms)?(amom<0?orange:green):(amom<0?red:orange)
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if amom > amoms then if amom < 0 then Color.ORANGE else Color.GREEN else if amom < 0 then Color.RED else Color.ORANGE);

# plot(sh?hl:na, style=histogram, color=hlc, linewidth=2)
# plot(amom, color=red, linewidth=2, title="Momentum")
plot Momentum = amom;
Momentum.SetDefaultColor(Color.RED);
Momentum.SetLineWeight(2);

# plot(amoms, color=green, linewidth=2, title="Signal")
plot signal = amoms;
signal.SetDefaultColor(Color.GREEN);
signal.SetLineWeight(2);

# barcolor(eb?hlc:na)
AssignPriceColor(if eb == yes then if amom > amoms then if amom < 0 then Color.ORANGE else Color.GREEN else if amom < 0 then Color.RED else Color.ORANGE else color.current);
 
Last edited:
Is it possible to add a label, the same as the color of the barcolor. So this way, we can kind of still keep the actual bar color and will then just refer to the label that shows on top of the chart. I found this indicator very useful. Thank you so much in advance.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
432 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