# This Pine Script trend quality indicator is interesting.

## Метаданные

- **Канал:** The Art of Trading
- **YouTube:** https://www.youtube.com/watch?v=mPnQYyY5YZw
- **Дата:** 04.04.2026
- **Длительность:** 13:21
- **Просмотры:** 4,392

## Описание

This content is educational and demonstrates charting tools and coding techniques only. It is not a recommendation to trade any financial product. Please seek professional guidance if you need it. Any links provided below may be referral links, and I may earn a commission if you use them, at no extra cost to you.

LESSON RESOURCES:
🔷 Hammers & Stars Example Script: https://www.tradingview.com/script/t776tkZv-Hammers-Stars-Strategy/?aff_id=15271
🔷 External Indicator Source Snippet: https://www.tradingview.com/script/nan4KNCW-External-Indicator-Value-Input-Snippet/?aff_id=15271
🔷 Q-Indicator Script: https://www.tradingview.com/script/k3mnaGcQ-Trend-Quality-Indicator/?aff_id=15271

🚩 Socials, Newsletter & More Free Content: https://theartoftrading.com
🚩 FREE Pine Script Basics Course: https://courses.theartoftrading.com/courses/pine-script-basics-course
🚩 Pine Script Mastery Course: https://courses.theartoftrading.com/courses/pine-script-mastery
🚩 My Indicators & Strategies Course (Steal My TradingView Code!): https://courses.theartoftrading.com/courses/my-indicators

🔷 Create your FREE TradingView Account: https://www.tradingview.com/gopro/?offer_id=10&aff_id=15271
----------------------------------------------------

Want to learn trading strategy development and backtesting techniques? Look no further. I have you covered!

This lesson demonstrates how to use the Q-Indicator as a trend quality filter in TradingView scripts by adding it as an external indicator input.

With 16+ years of coding experience and 7+ years of trading experience, I specialize in systematic strategy development and I'm here to pass on everything I've learned about both trading and coding.

MORE RESOURCES:
🔷 My Blog & Socials: https://www.theartoftrading.com
🔷 My Merch Store: https://theartoftrading-shop.fourthwall.com/
🔷 My Free Pine Script Indicators: https://www.tradingview.com/u/ZenAndTheArtOfTrading/?aff_id=15271#published-scripts
🔷 My Favorite Trading Books: https://zenandtheartoftrading.com/top-10-best-trading-books/
🔷 My Favorite Trading Psychology Books: https://zenandtheartoftrading.com/trading-psychology/10-best-trading-psychology-books-of-all-time/
🔷 My Trading Video Library: https://zenandtheartoftrading.com/video-library/

If you want more information about who I am and what I do, head over to https://zenandtheartoftrading.com/about.

Educational Content Disclaimer:

The content provided in our videos, including all code, lessons, and materials, is strictly for educational and informational purposes only. It is not intended as, and should not be interpreted as, financial advice, a recommendation to buy or sell, or an offer of any financial product or service. All strategies, tools, and examples discussed are provided for illustrative purposes to demonstrate coding techniques and the functionality of certain software within a trading context. Any results from strategies or tools provided are hypothetical and past performance is not indicative of future results. Trading and investing involve high risk, including the potential loss of principal, and are not suitable for all persons. Before making any trading decisions, please consult with a qualified professional to understand the risks involved. By using our materials, you acknowledge and agree that any trading decisions are made solely at your discretion and risk.

▼Timestamps▼
00:00 - What is the trend quality Q-Indicator?
08:38 - How to add an external indicator value filter input

#TradingView #PineScript #Coding

## Содержание

### [0:00](https://www.youtube.com/watch?v=mPnQYyY5YZw) What is the trend quality Q-Indicator?

Hey traders, hope you doing well. Today, I wanted to have a chat about a new indicator I've been experimenting with called the Q indicator or trend quality indicator. This is a tool that I've been experimenting with in my own strategy development process and I've found it to be quite interesting when used in conjunction with obviously trend following strategies, but also momentum strategies as a directional filter or setup filter. And as you can see down here, this sort of histogram oscillator type indicator is showing the bullish and bearish trend quality. And when it's sort of hugging the zero line, it indicates a choppy market. Now, as always, this is not financial advice. This is just something for you guys to go and research in your own trading process and backtesting process. I'm just going to show you how to get this on your chart on TradingView and most interestingly, how to add it as a filter input to existing strategy scripts. So, if you have a script that you've been working on, I'll show you a couple of lines of code which allow you to select any indicator from TradingView, not just this Q indicator, but you can select any indicator output value to use as a filter. So, as you can see here, I have a script here. It's an example strategy script that I made many years ago that is on TradingView. It's completely open source. It's a hammer and shooting star strategy. So, basically, it looks for candles like this to go long and short. It's just a example script for showing you how to detect candlestick patterns in Pine Script. And it's not particularly impressive. In fact, it doesn't even work on this particular chart, but if I turn on this trend quality filter so that the script is only taking long trades when the Q value is above two and only taking short trades when it's below -2, we can see the impact on this strategy. So, right here, it's basically useless, but we throw on this very simple trend quality indicator value and suddenly that changes the strategy behavior entirely. So, before we get into the video, as always, this is not financial advice. It's just showing you some coding concepts and ideas for you to go and experiment with and research in your own time. If you're not an experienced trader, make sure to seek professional guidance before you engage in trading at all. And if you're new to Pine Script and you want to learn how to make your own TradingView scripts and backtest scripts for the TradingView strategy tester, check out my course pinescriptmastery. com where I teach you how to code in Pine Script. With all that said, let's have a look at some code today. So, first things first, what is the Q indicator? It is a tool which measures trend strength by dividing trend activity by market noise. So, in other words, it's a signal-to-noise ratio indicator. So, what it does is it gives you a reading on how well a market is trending or a price chart is trending versus how much it is being erratic or volatile, choppy, whatever word you want to use. And if I bring over this open source script from TradingView, which I'll link to below in the video description and pin comment, and just to disclaim any links below to third-party resources like TradingView may be affiliate links where I earn a commission at no extra cost to you if you click on them, just to be aware of that. But if we scroll down here, there's some information on where this indicator came from. So, it originated through the work of David Sepiashvili in this publication here. And there's a lot of writing here, but to give you a sort of too long, didn't read version, this is the full source code to this indicator. And basically, what it's doing is it's detecting a moving average crossover, so a seven period over a 15 period. When that moving average crosses, the indicator then begins calculating the signal-to-noise ratio. So, the trend quality indicator is a trend detection and estimation tool that is based on a two-step filtering technique. It measures cumulative price changes over term-oriented semi-cycles. So, there's a lot of jargon here and relates them to noise. Basically, what it does is it detects a semi-cycle, which is another word for a leg in price action. So, once a chart starts to trend, that is determined to be a semi-cycle and this is determined through moving average crosses. So, when a short-term and long-term EMA cross, the indicator begins calculating the cumulative price change, which is the amount the price has changed from the starting point, the starting point being the moving average cross. The indicator then calculates a moving average of that cumulative price change since the cross. And then the noise is calculated using something very similar to standard deviation. So, basically, we get a moving average cross in price action. And then once that Let me change the color. Once this cross occurs, the indicator then calculates a moving average of the cumulative price change from this cross, which is just adding up all the gains and losses since that cross occurred. And then it calculates basically a very something very similar to a conventional standard deviation of that price change by summing the squares of the difference between CPC and trend over each of the preceding endpoint periods, dividing the sum by n, and calculating the square root of the result. Now, look, I did not do very well at math in school, so I don't fully understand the math behind this indicator, but what you get after all of this is a very clean visual indication of the signal-to-noise ratio of a trend, which obviously makes this quite interesting to experiment with as a trend filter or a momentum filter. So, as I said, there'll be links to these scripts below. I will also link to my hammers and stars strategy script source code, which I'm using to demonstrate this Q indicator as an input filter. It's completely free and open source. If you want to learn how I made this script and detailed breakdown of the source code to the strategy and what all this code does, if you're new to Pine, check out my courses at pinescriptmastery. com. There's a free basics course there as well if you're brand new to Pine. So, anyway, with that explanation of the Q indicator out of the way, let's look at this example script where I've added the Q indicator as a input to my script inputs. As I said, this approach applies to any indicator value out there. This isn't specific to the Q indicator and that's what makes this particular lesson quite interesting, I think, for you guys is that what I'm teaching you here isn't specific to the Q indicator. You can use this approach to add any TradingView indicator value as a filter to your existing scripts, including closed source scripts. So, there's an indicator out there that you really like the look of, but you can't get access to the source code, so that which means you can't add the code to your actual script, you can still get the output of that indicator and apply it as a filter. So, let's zoom in here. So, here the script is detecting hammer candles um and shooting star candles, which are just candles or bars where the body is in the upper third, the open and close third of the candle or in the lower third of the candle. It's a pretty rudimentary definition of a hammer and shooting star candle, but this is purely to demonstrate the concept and I needed an entry reason of some kind. But what's cool about this script is it's just super simple. That's literally the only entry criteria other than adding in this trend quality filter. So, if you look down here, this ribbon down here is black or gray if the Q indicator is below two or above -2, that means we're sort of in the middle of nowhere. We're in sort of a choppy area where the trend is not clearly defined. And once this indicator value gets above two, then my ribbon turns green and that means my script is looking for potential long setups. And when it falls below -2, it turns red and it's looking for potential bearish setups. And the way it calculates that is through this code here. So, here I have this external

### [8:38](https://www.youtube.com/watch?v=mPnQYyY5YZw&t=518s) How to add an external indicator value filter input

filter settings. We have four settings: use the external filter, get the external filter source, which is the indicator value we want to use as a filter, and then the minimum external filter value for longs and shorts. And then if I scroll down here, here are the external filters. Now, because the source value needs to have a default input, it can't be blank. By default, it starts with the indicator value of the closing price. So, what I need to do is check if my indicator source is not the closing price, that means we have selected something else from this list, then we check is our external filter source, the external indicator value that we have selected, above the minimum value for long trades or below short trades? Then these boolean values will be set to true or false based on that criteria. Now, this is structured around an indicator value that can go negative, but if the indicator value was something like the ADX, for example, which only ever exhibits a positive value even for bearish trends, then you would just set this to the same value for bearish or long trades and you might have to add some extra checks into the code to determine a directional bias. And then we just add this external filter check onto my combined Boolean value checks for long and short backtest setups. And that's it. Super simple. Like I said, there's only a few lines of code here. We get our external inputs. We check their values. And by the way, if the use external filter is turned off, then this whole thing will return true. So, that's how I make it possible to be able to simply just click this button to turn that off. So, anyway, that's it for this particular lesson. I just thought this was a really cool demonstration of how to add a third-party closed source or open source script, it doesn't matter. We're just getting an output value from someone else's indicator, plugging it into our script's source code as a directional filter. And obviously, if we go to Editor's Picks, let's have a look through the Editor's Picks indicators, and let's see if we can find something that we could throw in as an alternative indicator filter. Let's see what this range oscillator does. Here we go. Perfect. Um so, I have no idea what this indicator does, but let's say that if it's above one, looks like what's that? 100? If it's above 100, we're looking for longs. If it's below -100, we're looking for shorts. So, let's change our value here to And in order to know which output to choose, you can just open up the settings of the script and go to style. So, in this particular case, these are the fixed line plots, as you can see there. What we're looking for is this line here, range oscillator. So, if I go to my settings, go to inputs, click on this and go to range oscillator, and change this to 100 and -100. Click okay. There you go. Now you can see that the indicator is my ribbon on my indicator is turning red or green based on whatever this indicator is doing. So, as I mentioned, the full source code to this Hamish and Stars strategy will be below, but I will also link to the code snippet to this, basically. These few lines of code. This is all you need to add an external indicator value as a filter into your scripts. So, this snippet will be linked below as well somewhere. With that said, I hope you found this video interesting. If you did, make sure to subscribe, like the video, all of that YouTuber stuff, and uh check out my courses at theartoftrading. com or pinescriptmastery. com. In the next video, I want to explore this new Pine Screener feature that TradingView have added to the platform in beta, I believe. Um it's only available to premium subscribers, and it allows you to run Pine Script through the Screener feature of TradingView based on Pine Script code, which is really cool. I've been waiting for this for a long time. So, make sure to subscribe, stay tuned if you want to see a breakdown on how to use the Pine Screener in a future video. Take care. Good luck out there. Be safe. I love you guys. I'll speak with you soon.

---
*Источник: https://ekstraktznaniy.ru/video/45833*