Trend Enhancer Indicator for ThinkorSwim

Zachc

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

Shinthus

Member
2019 Donor
I implemented it and I don't see either of the two indicators.
 
Zachc

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

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.
 

Similar threads

Top