How To Add ATR Bands to Baseline Indicators For ThinkOrSwim

PennyRoyal

New member
I'm looking for a way to add ATR bands to baseline indicators such as the Hull MA, only for convenience so I can see whether price has moved beyond the ATR once it has crossed my baseline and not have to physically measure the distance. I've seen the Hull MA Bands in this forum, but they don't accurately reflect the ATR.

Is there a standard code I can insert into any chosen baseline that will provide ATR bands?

Thanks in advance!
 
Last edited:

TTs_MikeC

New member
@PennyRoyal
Would this be the same as switching Keltner channels to HULL type MA? I think the code itself would be slightly different depending on what indicators you are trying to add it to but Keltner would be my go to
 

PennyRoyal

New member
@PennyRoyal
Would this be the same as switching Keltner channels to HULL type MA? I think the code itself would be slightly different depending on what indicators you are trying to add it to but Keltner would be my go to
That's essentially what I'm looking for. I'll take that clue and see what I can do with it.

Thanks!
 

PennyRoyal

New member
@PennyRoyal
Would this be the same as switching Keltner channels to HULL type MA? I think the code itself would be slightly different depending on what indicators you are trying to add it to but Keltner would be my go to
That did the trick. I just copied and pasted the relevant Keltner code, made a few adjustments, and now have accurate (and adjustable) ATR bands around my baseline.

Thanks again for the clue! 🤘
 

hockeycoachdoug

Active member
2019 Donor
VIP
@PennyRoyal- Congrats on your expanding coding skills. I unfortunately don't possess such skills. Can you show your code and what you did. I would like to add ATR bands around a couple indicators too. Thanks in advance.
 

PennyRoyal

New member
@PennyRoyal- Congrats on your expanding coding skills. I unfortunately don't possess such skills. Can you show your code and what you did. I would like to add ATR bands around a couple indicators too. Thanks in advance.
I'd be happy to! I experimented with the Donchian Channel indicator, as it's middle band appears to be useful as a baseline indicator for forex trading. The reason I want the ATR bands is because of a condition in my trading algorithm which give a "FALSE" signal if price has closed too far beyond my baseline in relation to the ATR.

I pulled up the following code for ATR Bands and copy/pasted it to the bottom of the Donchian Channel code:

Code:
#ATR_Bands
declare upper;

# Inputs
input atrPeriod = 14;
input srcUpper = close;
input srcLower = close;
input atrMultiplierUpper =  2.5;
input atrMultiplierLower  = 2.5;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), atrPeriod);

plot UpperATR = srcUpper + (ATR * atrMultiplierUpper);
 UpperATR.setDefaultColor(Color.GREEN);
plot LowerATR = srcLower - (ATR * atrMultiplierLower);
 LowerATR.setDefaultColor(Color.RED);

You'll see below "#AddCloud....." where I pasted this.

I noticed that "input srcUpper = close" and the next code line were the references for the ATR band plots, so I turned them off (#) and changed the last two plots in the code from "srcUpper" and "srcLower" to "middleband". That way, the ATR bands would be plotted from the middle band of the Donchian Channel, not the closing price of the candle.


Code:
#Name:             DonchianChannel
#Programmed By:    Chris Ball ([email protected]) on 10/23/08
#Posted At:        http://chartingwithchris.blogspot.com
#Description:      This is a channel system that is used frequently for trend trading.  Google the term "turtle trader" for more information.
#Modified 2020-06-10 by rad14733 to utilize AddCloud()

input length = 20;

plot upperBand = Highest(high[1], length);
plot lowerBand = Lowest(low[1], length);
plot middleBand = (upperBand + lowerBand) / 2;

upperBand.SetDefaultColor(Color.DARK_GRAY);
lowerBand.SetDefaultColor(Color.DARK_GRAY);
middleBand.SetDefaultColor(Color.Orange);

#AddCloud(upperBand, lowerBand, Color.DARK_GRAY, Color.WHITE);

input atrPeriod = 14;
input atrMultiplierUpper =  2.5;
input atrMultiplierLower  = 2.5;
input averageType = AverageType.WILDERS;
#input srcUpper = close;
#input srcLower = close;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), atrPeriod);

plot UpperATR = middleBand + (ATR * atrMultiplierUpper);
 UpperATR.setDefaultColor(Color.GREEN);
plot LowerATR = middleBand - (ATR * atrMultiplierLower);
 LowerATR.setDefaultColor(Color.RED);

And this is the result:

15JjyaV.png


Now whenever price crosses and closes above or below the yellow Donchian middle band, all I have to do is glance at the chart to see if it has gone too far, instead of having to go through all the measuring and math. Really streamlines the watchlist scanning!
 

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.
Top