Donchian Channel Trend For ThinkOrSwim

Jman831

Member
This is a simple indicator I've created to help determine whether a trend is up or down. It plots the difference between the upper and lower channels of two Donchian Channels. The lengths of the two Donchian Channels are adjustable. The difference between the lower channels is plotted as a positive number, as a green histogram while the difference between the upper channels is plotted as a negative number, as a red histogram. More green and little to no red means uptrend, while more red and little to no green means downtrend. As I like to do with most of my indicators, I've included exponential smoothing which can be toggled on or off. The smoothing factor is also adjustable. Code below:

Update: As requested by another member, I've updated the code here for this indicator to include an option that allows you to see the DC Trend of a different security than the security loaded on the price chart. By default, it is toggled on and shows the DC Trend of the SPY security. If you want to see the DC Trend of the charted security, simply toggle "show different security" to "no".
Code:
declare lower;

input DCFastLength = 9;
input DCSlowLength = 27;
input ExponentialSmoothing = yes;
input SmoothingFactor = 3;
input ShowDifferentSecuirty = yes;
input Security = "SPY";

def dcfasthigh = if ShowDifferentSecuirty == yes then highest(high(Security), DCFastLength) else highest(high, DCFastLength);
def dcfastlow = if ShowDifferentSecuirty == yes then lowest(low(Security), DCFastLength) else lowest(low, DCFastLength);
def dcslowhigh = if ShowDifferentSecuirty == yes then highest(high(Security), DCSlowLength) else highest(high, DCSlowLength);
def dcslowlow = if ShowDifferentSecuirty == yes then lowest(low(Security), DCSlowLength) else lowest(low, DCSlowLength);
def lowdiff = if ExponentialSmoothing == yes then ExpAverage(ExpAverage(ExpAverage(dcfastlow - dcslowlow, SmoothingFactor), SmoothingFactor), SmoothingFactor) else dcfastlow - dcslowlow;
def highdiff = if ExponentialSmoothing == yes then ExpAverage(ExpAverage(ExpAverage(dcfasthigh - dcslowhigh, SmoothingFactor), SmoothingFactor), SmoothingFactor) else dcfasthigh - dcslowhigh;

plot Zero = 0;
plot LowDifference = lowdiff;
plot HighDifference = highdiff;

LowDifference.setPaintingStrategy(paintingStrategy.HISTOGRAM);
LowDifference.setDefaultColor(color.GREEN);
HighDifference.setPaintingStrategy(paintingStrategy.HISTOGRAM);
HighDifference.setDefaultColor(color.RED);

A screenshot of the indicator below a chart of the SPY:
Donchian-Channel-Trend.png
 
Last edited:
I use every indicator that you have published. You and @mashume are my idols.
I had need of a simple trend indicator to use to filter my potential candidates for trade.
Turns out your invention is very similar to what I use:
Here is your indicator (which is superior because it has more customizing options) compared to what I have been using:
ToS reference MAD() Moving Average Difference
LNBKkA3.png
 
I use every indicator that you have published. You and @mashume are my idols.
I had need of a simple trend indicator to use to filter my potential candidates for trade.
Turns out your invention is very similar to what I use:
Here is your indicator (which is superior because it has more customizing options) compared to what I have been using:
ToS reference MAD() Moving Average Difference
LNBKkA3.png
That means a lot, especially coming from you, thank you! =-)
 
https://usethinkscript.com/threads/donchian-channel-trend-for-thinkorswim.11848/
This is a simple indicator I've created to help determine whether a trend is up or down. It plots the difference between the upper and lower channels of two Donchian Channels. The lengths of the two Donchian Channels are adjustable. The difference between the lower channels is plotted as a positive number, as a green histogram while the difference between the upper channels is plotted as a negative number, as a red histogram. More green and little to no red means uptrend, while more red and little to no green means downtrend. As I like to do with most of my indicators, I've included exponential smoothing which can be toggled on or off. The smoothing factor is also adjustable. Code below:
Code:
declare lower;

input DCFastLength = 9;
input DCSlowLength = 27;
input ExponentialSmoothing = yes;
input SmoothingFactor = 3;

def dcfasthigh = highest(high, DCFastLength);
def dcfastlow = lowest(low, DCFastLength);
def dcslowhigh = highest(high, DCSlowLength);
def dcslowlow = lowest(low, DCSlowLength);
def lowdiff = if ExponentialSmoothing == yes then ExpAverage(ExpAverage(ExpAverage(dcfastlow - dcslowlow, SmoothingFactor), SmoothingFactor), SmoothingFactor) else dcfastlow - dcslowlow;
def highdiff = if ExponentialSmoothing == yes then ExpAverage(ExpAverage(ExpAverage(dcfasthigh - dcslowhigh, SmoothingFactor), SmoothingFactor), SmoothingFactor) else dcfasthigh - dcslowhigh;

plot Zero = 0;
plot LowDifference = lowdiff;
plot HighDifference = highdiff;

LowDifference.setPaintingStrategy(paintingStrategy.HISTOGRAM);
LowDifference.setDefaultColor(color.GREEN);
HighDifference.setPaintingStrategy(paintingStrategy.HISTOGRAM);
HighDifference.setDefaultColor(color.RED);
Can this code be converted to be able add any symbol?
For example, if I'm viewing AApl chart, and I want spy data in the indicator.
 
Last edited by a moderator:

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