Trend Quality Indicator (With Alert) For ThinkOrSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
This is a Trend Quality Indicator for ThinkorSwim shared by Anupam Bagchi who is a data scientist. This indicator is useful for showing buying, selling, and sideways action.
  • Green = buying pressure
  • Red = selling pressure
  • Yellow = sideways
The Trend Quality Indicator (TQI) is an important tool used by traders to gauge the strength and reliability of a trend.

When the TQI is greater than 3, it indicates a robust green bull trend. It is similar to seeing a car climbing steadily up the mountain.
Conversely, a yellow plot, with values between 3 and -3, signifies a weaker or less reliable trend. It's like driving on a winding road with some obstacles ahead – indicating a weaker trend that might not be as dependable.
Values below -3, strong red bear trend. The car is making a bee-line down the mountain.

Trend Quality Indicator:
  • measures established TRENDs
  • can be used on timeframes of 5min and higher.
  • works best on timeframes of 30min or higher.
  • The threshold of 3 should be appropriate for most instruments. It can be modified in chart settings to adapt to your strategy.
Remember, the Trend Quality Stock Indicator is not a crystal ball; it doesn't predict the future. Instead, it helps traders assess the strength of the current trend, giving them a better understanding of the market conditions to make more informed trading choices.


hzUhBIW.png


thinkScript Code

Rich (BB code):
declare lower;

input fastLength = 7;
input slowLength = 15;
input trendLength = 4;
input noiseType = {default linear, squared};
input noiseLength = 250;
input correctionFactor = 2;
input ThresholdValue = 3;
input AlertEnabled = {true, default false};

def smf = 2 / (1 + trendLength);

def reversal = TrendPeriods(fastLength, slowLength);

rec cpc = if isNaN(reversal[1]) then 0 else if reversal[1] != reversal then 0 else cpc[1] + close - close[1];

rec trend = if isNaN(reversal[1]) then 0 else if reversal[1] != reversal then 0 else trend[1] * (1 - smf) + cpc * smf;

def noise;
def diff = AbsValue(cpc - trend);
switch(noiseType) {
case linear:
    noise = correctionFactor * Average(diff, noiseLength);
case squared:
    noise = correctionFactor * Sqrt(Average(diff*diff, noiseLength));
}

plot TQ = if noise == 0 then 0 else trend / noise;
plot ZeroLine = 0;

TQ.SetPaintingStrategy(PaintingStrategy.Histogram);
TQ.SetLineWeight(3);
TQ.DefineColor("Positive", Color.UPTICK);
TQ.DefineColor("Negative", Color.DOWNTICK);
TQ.DefineColor("Neutral", Color.YELLOW);
TQ.AssignValueColor(if TQ > ThresholdValue then TQ.color("Positive") else if TQ < -ThresholdValue then TQ.color("Negative") else TQ.color("Neutral"));
ZeroLine.SetDefaultColor(GetColor(5));

def crossthresholdup = TQ > ThresholdValue && TQ[1] <= ThresholdValue && AlertEnabled;
def crossthresholddown = TQ < -ThresholdValue && TQ[1] >= -ThresholdValue && AlertEnabled;
alert(crossthresholdup, "Trend Quality just crossed above threshold", Alert.BAR, Sound.DING);
alert(crossthresholddown, "Trend Quality just crossed below threshold", Alert.BAR, Sound.DING);

Shareable Link

Original: https://tos.mx/Drcgp5

Modified: https://tos.mx/wbZ5TC
 
Last edited by a moderator:
Hello Ben - just wanted to say I've been using this indicator and I've been really impressed by it! Helps me stay in trades longer on upswings. Thank you for posting it.
 
@BenTen - question, any chance you could edit/adjust the code to remove the selling pressure (red), only leaving the yellow and green (sideways and buying). I have been trying to do it on my own for a few hours but I am failing miserably.
 
I've been tinkering with this indicator for a bit, and I've noticed that it occasionally comes up blank. Why is that?
 
This is an overall interesting thread as I myself have been looking at the Trend Quality indicator (no access to the code), but found that it has a lag on the reset with no way to modify the code...so I left it alone. With @BenTen posting the code above, I am hopeful to improve on the reset feature of this indicator above. But before doing so, has anyone here attempted to improve the reset of this indicator so that it resets right before the high point and right before the low point as illustrated on this screenshot? (The screenshot was taken from my Tradestation Platform using a specialized indicator....no access to the source code). If you've noticed the Trend Quality Indicator resets several bars after the trend is over. This is not good as it causes severe draw downs! I've illustrated below with vertical dashed-lined how it should reset. Any thoughts on how to improve the TQI would be appreciated.
NQ1-M-Reset.jpg
 
Based on initial testing, I find MTF Trend Quality is a good indicator to confirm the direction of the trend, if multiple timeframe agree, generally provides forecast of potential direction. I been looking at it in a intermediate timeframe (days to weeks) to confirm cycle analysis. I haven't had change to observe this indicator series in lower time frames yet.
 
@horserider , YES!, like the lower indicator with the 3, 9, 21, squared, 21, 1 settings u show there. Those histograms reset nicely! Is that one of your creations?
 
@madeinnyc Nope. Just trying to help with your question. Played with all the setting until something more like what you showed appeared. Play around maybe you can make it exactly what you want. I have never used this study and most likely will not.
 
I believe the Trend Quality Indicator here is Digital Signal filter that John Ehler introduced years ago. I embrace his work, which uses as an underlying empirical emphasis on the cyclical and fractal (simply put-markets cycle and they have repeatable patterns as they cycle) His work is just outstanding . A real engineering gifted mind. I have personally only scratched the surface with displaying some of his work on an intraday chart. Since I was wandering around, I see Ben posted this contribtution, I wanted to humbly share some very small addition that caught my attention when I looked at the code in this thread: The user might want to change the threshold value of fast moving intraday reverse to 2 from 3, and add the very useful derivative function in TOS called the TrendNoise Indicator (settings for RMS- root mean squares) and overlay it on the lower signal panel for additional visual confirmation). It works like the Polarized Fractal Efficiency indicator, but with sharper demarcation. The whole idea being to make it both a leading indicator of a reversal, and to make it a more responsive so as to place a stop for protection of possible gains if you take the signal along with other fractal volume weigthed moves. Price x volume with streamlined fractal energy-quick and decisive. Best wishes , a greatful visitor
 

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