Adaptive Moving Average ATR Bands for ThinkOrSwim

chewie76

Well-known member
VIP
VIP Enthusiast
Adaptive Moving Average ATR Bands (AMAAB) is a volatility-based, trend-following indicator that builds ATR bands around three different moving averages and combines them into a single outer envelope.

SMA, RMA and LSMA are calculated from the same source and length. Each moving average receives its own ATR bands, and the highest upper band and lowest lower band are used as the final bands.

Since the three moving averages react to price at different speeds, the envelope adapts its width to the distance between them, requiring a stronger move before the active condition changes.

Original concept: https://www.tradingview.com/script/u82khjne-Adaptive-Moving-Average-ATR-Bands-NJ/
Modified original by adding gray full bands and center line, which can be turned on/off in the settings.

This is an example of /NQ on a 10 minute chart.
1791034209879.png


Code:
# Adaptive Moving Average ATR Bands  (AMAAB)
# Original Concept: https://www.tradingview.com/script/u82khjne-Adaptive-Moving-Average-ATR-Bands-NJ/
# Converted by Chewie on 10/3/2026

declare upper;

# ===== INPUTS =====
input colorMode = {default Colored, Neutral};
input dispCandles = yes;
input full = yes;
input maSrc = close;
input maLen = 28;
input atrLen = 6;
input atrMulti = 0.75;

DefineGlobalColor("LongCol", CreateColor(0, 136, 100));
DefineGlobalColor("ShortCol", CreateColor(120, 0, 32));
DefineGlobalColor("LongNeutral", CreateColor(179, 179, 179));
DefineGlobalColor("ShortNeutral", CreateColor(60, 60, 60));

# ===== CALCULATION =====
# Three MAs: SMA, RMA (Wilder), and linear regression endpoint (linreg offset 0)
def smaMA = Average(maSrc, maLen);
def rmaMA = WildersAverage(maSrc, maLen);
def lsmaMA = Inertia(maSrc, maLen);

# ATR (Wilder / RMA, same as Pine ta.atr)
def atrVal = WildersAverage(TrueRange(high, close, low), atrLen);

def bandOff = atrVal * atrMulti;

# Farthest bands from price
def upperBandV = Max(Max(smaMA + bandOff, rmaMA + bandOff), lsmaMA + bandOff);
def lowerBandV = Min(Min(smaMA - bandOff, rmaMA - bandOff), lsmaMA - bandOff);

# ===== FINAL SIGNAL (Pine "var int NJ") =====
def NJ = CompoundValue(1,
    if close > upperBandV then 1
    else if close < lowerBandV then -1
    else NJ[1],
    0);

# ===== PLOTS =====
def isColored = colorMode == colorMode.Colored;

plot UpperBand = if NJ == -1 then upperBandV else Double.NaN;
UpperBand.SetLineWeight(3);
UpperBand.SetPaintingStrategy(PaintingStrategy.LINE);
UpperBand.AssignValueColor(if isColored then GlobalColor("ShortCol") else GlobalColor("ShortNeutral"));

plot LowerBand = if NJ == 1 then lowerBandV else Double.NaN;
LowerBand.SetLineWeight(3);
LowerBand.SetPaintingStrategy(PaintingStrategy.LINE);
LowerBand.AssignValueColor(if isColored then GlobalColor("LongCol") else GlobalColor("LongNeutral"));

plot U = if full then upperbandv else double.nan;
U.setdefaultColor(color.dark_gray);
plot D = if full then lowerbandv else double.nan;
D.setdefaultColor(color.dark_gray);
plot M = if full then (U - D)/2 + D else double.nan;
M.setdefaultColor(color.dark_gray);

# Color candles
AssignPriceColor(
    if !dispCandles then Color.CURRENT
    else if NJ == 1 then (if isColored then GlobalColor("LongCol") else GlobalColor("LongNeutral"))
    else if NJ == -1 then (if isColored then GlobalColor("ShortCol") else GlobalColor("ShortNeutral"))
    else Color.CURRENT
);
 
Thank you for sharing! If you haven't already, you may wish to have a look at this video from a person who tweaked the pinescript version for scalping:
 

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