This idea came to me after I wrote the post about Co-Integration and pair trading. I wondered if you could use pair trading principles as a way to determine overbought and oversold conditions in a more neutral way than RSI or Stochastics.

The results were promising and this indicator resulted :-)!


COSTAR provides another, more neutral way to determine whether an equity is overbought or oversold.

Instead of relying on the traditional oscillator based ways, such as using RSI, Stochastics and MFI, which can be somewhat biased and narrow sided, COSTAR attempts to take a neutral, unbiased approached to determine overbought and oversold conditions. It does this through using a co-integrated partner, or "pair" that is closely linked to the underlying equity and succeeds on both having a high correlation and a high t-statistic on the ADF test. It then references this underlying, co-integrated partner as the "benchmark" for the co-integration relationship.

How this succeeds as being "unbiased" and "neutral" is because it is responsive to underlying drivers. If there is a market catalyst or just general bullish or bearish momentum in the market, the indicator will be referencing the integrated relationship between the two pairs and referencing that as a baseline. If there is a sustained rally on the integrated partner of the underlying ticker that is holding, but the other ticker is lagging, it will indicate that the other ticker is likely to be under-valued and thus "oversold" because it is underperforming its benchmark partner.

This is in contrast to traditional approaches to determining overbought and oversold conditions, which rely completely on a single ticker, with no external reference to other tickers and no control over whether the move could potentially be a fundamental move based on an industry or sector, or whether it is a fluke or a squeeze.

The control for this giving "false" signals comes from its extent of modelling and assessment of the degree of integration of the relationship. The parameters are set by default to assess over a 1 year period, both the correlation and the integration. Anything that passes this degree of integration is likely to have a solid, co-integrated state and not likely to be a "fluke". Thus, the reliability of the assessment is augmented by the degree of statistical significance found within the relationship. The indicator is not going to prompt you to rely on a relationship that is statistically weak, and will warn you of such.

The indicator will show you all the information you require regarding the relationship and whether it is reliable or not, so you do not need to worry!

How to Use

The first step to use COSTAR is identifying which ticker has a strong relationship with the current ticker. In the main chart, you will see that SPY is overlaid with VIX. There is a strong, negative correlation between the VIX and SPY. When VIX is entered as the paired ticker, the indicator returns the data as stationary, indicating a compatible match.

Now you have 3 ways of viewing this relationship, 2 of which are going to be directly applicable to trading.

You can view them as

  • Price to Price Ratio (Not very useful for trading, but if you are curious)
  • Z-Score: Helpful for trading
  • Co-integration: Helpful for trading

Here is an example of all three:

Example of Z-Score Chart:

Example of Price Ratio:

Example of Co-Integration Pair:

Using for Trading

As stated above, the two best ways to use this for trading is to either use the Z-Score Chart or the Co-Integrated Pair chart.

The Z-Score chart is based off of the price ratio data and provides an assessment of both the independent and dependent data.

The co-integration shows the dependent (the ticker you are trading) in yellow and the independent (the ticker you are referencing) in teal. When teal is above yellow, you will see it is green. This means, based on your benchmark pair, there is still more up room and the ticker you are trading is actually lagging behind.

When the yellow crosses up, it will turn red. This means that your ticker is out-performing the benchmark pair and you likely will see pullback and a "regression to the mean" through re-integration.

The indicator is capable of plotting out entries and exits, which are guided by the z-score:

How Effective is it?

I created a basic strategy in Pinescript, and the back-test results vary. Trading ES1! using NQ1! as the co-integrated pair, results were around 78% effective.
With VIX, results were around 50% effective, but with a net profit.
Generally, the efficacy surpassed that of both stochastics and RSI.

I will be releasing the strategy version of this in the coming days, still just cleaning up that code and making it more "public use" friendly.

Other Applications

If you are a pair trader, you can technically use this for pair trading as well. That's essentially all this is doing :-).


  • If you are trading a ticker such as MSFT, AMD, KO etc., it's best to try to find an ETF or index that has that particular ticker as a large holding and use that as your benchmark. You will see on the indicator whether there is a high correlation and whether the data is indeed stationary.

  • If the indicator returns "Non-stationary", you can attempt to extend your regression range from 252 to 500. If this fixes the issue, ensure that the correlation is still >= 0.5 or <= -0.5. If this does not work still, you will need to find another pair, as its likely the result of incompatibility and an insignificant relationship.

  • To help you identify tickers with strong relationships, consider using a correlation heatmap indicator. I have one available and I think there are a couple of other similar ish ones out there. You want to make sure the relationship is stable over time (a correlation of >= 0.50 or <= -0.5 over the past 252 to 500 days).

  • IMPORTANT: The long and short exits delete the signal after one is signaled. Therefore, when you look back in the chart you will notice there are no signals to exit long or short. That is because they signal as they happen. This is to keep the chart clean.

'Tis all my friends!
Hope you enjoy and let me know your questions and suggestions below!

Side note:
COSTAR stands for Co-integration Statistical Analysis and Regression. ;)

Premium indicators and content have launched! Get access at:

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。