ADX Trend Long\Short Strategy for ThinkorSwim

Zachc

Member
2019 Donor
This is my first indicator that looks fairly effective. My goal is to reduce choppy trades and elongate hold times. The longer we can stay in the trend the better. This one was fun because it forced me to write and refine a universal trend indicator I can use to enhance already useful trend trading strategies. I will release the trend indicator separate as well so you can copy and paste into your own studies.

Most of my backtesting was done in futures /ES, /RTY, /NQ, /CL, /YM, /GC
Some things I have found while testing: Lower time frames benefit if you change the trend detection to aggressive. The higher time frames work much better with basic or turned off.

I am looking for criticism so I can get better at expressing my ideas into these systems.

Cheers!
-ZachC

The ADX Trend Strategy works pretty well without the enhancement. It should help to identify longer type trends.

jZ9ZzY1.png


Now we can change the settings to Basic

qBLDCht.png


After the basic enhancement, the trend time frame is elongated to capture just a little more alpha.

IbE48xy.png


I would also encourage anyone who can not short in their account to turn off the downtrend and short cover options. If you are in a short trade you could miss out on a long indicator.


Here is the code
Rich (BB code):
#hint:<b>Use ADX as your Long and Short entry points</b>\nEnhanced with trend confirmation strat on entry and exits.

input length = 14;
input lag = 12;
input averageLength = 25;
input trendLevel = 20;
input maxLevel = 42.0;
input critLevel = 22.0;
input mult = 1.8;
input averageType = AverageType.SIMPLE;
input EnhancedLong = {default Off, Basic, Simple, Aggressive};
input EnhancedShort = {default Off, Basic, Simple, Aggressive};

def ma = MovingAverage(averageType, close, averageLength);
def adx = reference ADX(length = length);

plot movingAVG = ma;

# Trend Quality
# Author: ZachC on useThinkscript.com
# You can use the uptrend and downtrend indicators in addition to a positive signal
# OR
# Use the stay long indicator to ride out your bullish trend a little longer
# Use the stay short indicator to ride out your bullish trend a little longer

###
# Basic Trend Level, Crude but effective
##
# Simple Trend
# Bar 1 is greater then bar two or TQ is above 0
# Vice Versa for down trend
##
# Aggressive Trend
# The last 3 bars are in an up trend
# The last 3 bars are in a down trend
###

def trLong;
switch (EnhancedLong) {
case Basic:
    trLong = TrendPeriods() == 1;
case Simple:
    trLong = TrendQuality().TQ[0] > TrendQuality().TQ[1] or TrendQuality().TQ >= 0;
case Aggressive:
    trLong = TrendQuality().TQ[0] > TrendQuality().TQ[1] and TrendQuality().TQ[1] > TrendQuality().TQ[2];
case Off:
    trLong = TrendQuality().TQ;
}

def trShort;
switch (EnhancedShort) {
case Basic:
    trShort = TrendPeriods() == 1;
case Simple:
    trShort = TrendQuality().TQ[0] > TrendQuality().TQ[1] or TrendQuality().TQ >= 0;
case Aggressive:
    trShort = TrendQuality().TQ[0] > TrendQuality().TQ[1] and TrendQuality().TQ[1] > TrendQuality().TQ[2];
case Off:
    trShort = TrendQuality().TQ;
}

# 1st Long Setup ( Strong Uptrend )
# ADX First needs to cross above the Trend Level
# But it must be below the Max Level
# The last closing bar must be above the SMA

AddOrder(OrderType.BUY_TO_OPEN, adx crosses above trendLevel and
    adx < maxLevel and
    close > ma and trLong, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "StrongUptrend");

# 2nd Long Setup ( Typical Uptrend )
# ADX must be less then the Multiplyer times the lowest ADX value in the last 12 bars
# ADX must also cross above the critical level set 22
# The last closing bar must be above the SMA

AddOrder(OrderType.BUY_TO_OPEN, adx > mult * Lowest(adx, lag) and
   adx crosses above critLevel and
   close > ma, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Uptrend");

# 1st Short Setup (Strong Down Trend)
# ADX first must cross above the trendlevel
# ADX must be less than the max level
# The last closing bar must be below the SMA
AddOrder(OrderType.SELL_TO_OPEN, adx crosses above trendLevel and
    adx < maxLevel and
    close < ma and trShort, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "StrongDowntrend");

# 2nd Short Setup ( Typical Downtrend )
# ADX is greater then the multiplyer of 1.8 times the lowest ADX in the last 12 bars
# ADX must cross above the critical level
# The last closing bar must be below the SMA
AddOrder(OrderType.SELL_TO_OPEN, adx > mult * Lowest(adx, lag) and
    adx crosses above critLevel and
    close < ma, tickcolor = GetColor(3), arrowcolor = GetColor(3), name = "Downtrend");

#Covering needs improvement
# Price closes below the SMA and TrendShort period selected above
AddOrder(OrderType.SELL_TO_CLOSE, Average(close) < ma and trLong, tickcolor = GetColor(4), arrowcolor = GetColor(4), name = "LongCover");

# Price closes above the SMA and TrendLong period selected above
AddOrder(OrderType.BUY_TO_CLOSE, Average(close) > ma and trShort, tickcolor = GetColor(5), arrowcolor = GetColor(5), name = "ShortCover");
 

Attachments

  • IbE48xy.png
    IbE48xy.png
    118.8 KB · Views: 305
  • qBLDCht.png
    qBLDCht.png
    44.8 KB · Views: 261
  • jZ9ZzY1.png
    jZ9ZzY1.png
    122.9 KB · Views: 340
Last edited by a moderator:
ADX is not a very noisy indicator so in a new stock like BYND or even the micro futures it really struggles. Still a 2k profit is a win in my book 🤑
 
Using the SMA of 25 in this study might give better results. I overlaid a SMA 25 (white line) and turned on the signals (white arrows).

ZFtDW3M.png
 

Attachments

  • ZFtDW3M.png
    ZFtDW3M.png
    124.7 KB · Views: 264
Hi, horserider thanks for checking out the study. You nailed it the default it is currently set to the 25 SMA. The difference is the addition of the trend enhancement. Turning off the trend enhancement would result in the signals you have displayed but for the exits only. The ADX indicator is used as the entry for both the short and long trades.

In a perfect world where the first long position was stopped out for a small loss would have been a perfect example of a time to hold through the sideways action to allow the trend to continue.

It would be interesting to see whether just using the 25 SMA has more potential that the ADX itself.

I think for the next iteration I am going to add a label at the top left that just displays the current ADX level and the significance of it.
I am also going to plot entry and exit signals to better show how the strategy is working.
 
Look more closely. The white arrows are 25 SMA signals. Or just the price crossing 25 SMA looks better to me.
 
Look more closely. The white arrows are 25 SMA signals. Or just the price crossing 25 SMA looks better to me.

I see what you mean. I did notice that is what prompted me to add the option to turn off the Trend Enhancement. Some securities and ETF's have a better flow and respond better to the moving averages and don't require having the extra helping hand. It's all about preference, IMO.
 
@Zachc Thanks. My opinion is you are working hard on a study you will have a very hard time making it what you desire. The problem is the ADX. I have done a quick chart to give you ideas that may be easier to work into your strategy. That ADX oscillator is in ToS somewhere. Sorry I forgot the name. So take a look and see if it can improve your approach to this strategy.

kTLS8XG.png


The White line on top indicator matches the red/green line of the lower. On the upper the cross of 2 and -2 would be the signals and the parts inbetween can be ignored. The white line of the lower should signal the points or reversal of price when it crosses zero. Some way to avoid excess signals in chop may be needed. Ooops may have missed marking a few places but you get the idea. Good coding to you.
 

Attachments

  • kTLS8XG.png
    kTLS8XG.png
    158.3 KB · Views: 277
Thanks, @horserider , Your analysis will go a long way in helping develop this strategy. Coding in a signal that is simply on or off is much simpler than messing with multiple levels. As soon as I have the new strat coded ill share for your feedback.
 
@UncleTerry Yes I made it long ago. I forget why and why I used that name. As it turns out it is the Detrended Price Oscillator. So I wasted my time. Oh well. Can also find it as FW DPO in ToS
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
245 Online
Create Post

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