Trend Enhancer Indicator for ThinkorSwim

Zachc

Member
2019 Donor
I wrote this little bit of code for another indicator when I realized that I could try to synthetically assist the indicator to extend the trend if it is available.
I looked around for some trend indicators that I could leverage and I found two. I like to use the KISS method so I do not over complicate my strategies. The more simple the more effective in my eyes.

1. Trend Periods is a very simple 1 for long trend and -1 for short trend this is the Basic Setting but don't take the name for granted it can dramatically help keep you out of an early short cover or a late long entry.
2. Trend Quality this indicator is painted as a histogram which gives us the ability to do a little analysis on the direction of the trend. I leverage this enhancement with Simple and Aggressive options.

I find that the Trend periods helps with longer time frames on the daily, weekly, and monthly time frames
TrendQuality really shines on lower time frames 1 hour and less. You can also use it on Tick, Range and Renko charts.

This is purely for integrating into your existing Strategy or Study it is not an indicator or to be used to trade with outright. If you want to write a study or strategy around the code go for it!

Code:
# Trend Quality
# 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

input EnhancedLong = {default Off, Basic, Simple, Aggressive};
input EnhancedShort = {default Off, Basic, Simple, Aggressive};

###
# 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;
}
 
I wrote this little bit of code for another indicator when I realized that I could try to synthetically assist the indicator to extend the trend if it is available.
I looked around for some trend indicators that I could leverage and I found two. I like to use the KISS method so I do not over complicate my strategies. The more simple the more effective in my eyes.

1. Trend Periods is a very simple 1 for long trend and -1 for short trend this is the Basic Setting but don't take the name for granted it can dramatically help keep you out of an early short cover or a late long entry.
2. Trend Quality this indicator is painted as a histogram which gives us the ability to do a little analysis on the direction of the trend. I leverage this enhancement with Simple and Aggressive options.

I find that the Trend periods helps with longer time frames on the daily, weekly, and monthly time frames
TrendQuality really shines on lower time frames 1 hour and less. You can also use it on Tick, Range and Renko charts.

This is purely for integrating into your existing Strategy or Study it is not an indicator or to be used to trade with outright. If you want to write a study or strategy around the code go for it!

Code:
# Trend Quality
# 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

input EnhancedLong = {default Off, Basic, Simple, Aggressive};
input EnhancedShort = {default Off, Basic, Simple, Aggressive};

###
# 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;
}

Interesting the input fields should show up in your strategy settings. Then you can add the trLong and trShort variables as an and statement to your entry and exit statements. When I get home later I can double check.
 

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