ByzantiumScripts

Aggregated Perpetuals Basis

CONCEPT

The aggregated perpetuals basis compares the prices of perpetual swap contracts in crypto (or "perps" for short) with the price of the spot market.
The idea behind this is that it can help you analyse whether the derivatives market is being overly bullish or bearish.

When the indicator shows positive values (grey colouring by default) it means that perps are trading at higher prices than spot.
Generally speaking we say this is bearish or at least not an ideal scenario to long yourself because most of the time this means that derivatives market participants are too aggressive (overbought territory).
Vice versa when the indicator shows negative values (green colouring by default) it means that there's a spot premium which is considered bullish.
A spot driven market is a healthy market. There could also be a spot premium because market participants that are trading perps are aggressively shorting which puts them at risk of getting short squeezed (again, bullish).


FEATURES

The indicator works for both BTC and ETH.


It's aggregated because it looks at the prices of multiple contracts and it's also volume weighted so that more important markets have a bigger impact.

There are three different types of premiums you can select: coin margin, dollar margin or the combined version.


In crypto there are two types of perpetual swap contracts. Contracts that work with coin margin and contracts that work with dollar margin, which is mostly USDT although FTX for example also accepts other collateral. Sometimes these contracts trade at slightly different prices and you'll notice that there's also a shift in bullishness and importance between these contracts from time to time.
However most of the time the values will be very similar for coin margin and dollar margin.

Markets used for the coin margin perps:
  • Binance
  • Bybit
  • Deribit

Markets used for dollar margin perps:
  • Binance
  • Bybit
  • FTX

The combined premium combines them all.

The spot indices used are:
  • BXBT (for BTC)
  • BETH (for ETH)

By default it uses "close" as candle source which means it looks at the premium as if the candle were to close right now.
If you're looking at higher timeframes I suggest using "ohlc4" because there's a lot that happens within one daily candle for example so you might want to use an average candle price (ohlc4 = open+high+low+close/4)

There's a "clamp" feature which puts a cap on extreme values.
Sometimes during capitulation events there's a massive spot premium which dwarfs all the other values and that makes the indicator unreadable.


In such cases the clamp helps to make the indicator useful again.
As you can see I created support and resistance zones (which you can turn off) that max out at 0.4% for bitcoin because by looking at historical data it seems that the premium almost never moves outside of those thresholds (except for those few exceptions during liquidation cascades).


There's also an option to smooth out the values.



TRADING

As discussed earlier, a spot premium is generally speaking considered bullish and a derivatives premium is considered bearish.
It doesn't give buy an sell signals, but it helps you with establishing a bias and gauging general market sentiment.
This in turn can help you with deciding what side of the trade to take and it shows if the conditions are still favourable for you to take the trade you want, because a spot premium for example usually leads to negative funding which makes it interesting to go long.


Send me a private message if you want access so we can discuss it.
Cheers.
Release Notes:
I've changed the spot indices used to create the premium.

Previously I used weighted indices from Bitmex but that data has been acting strange recently (possible data feed issue or Bitmex issue) and it seriously affected the indicator, especially for ETH.
So I've created my own spot indices based on prices from Coinbase (USD), Bitfinex (USD) and Binance (USDT).

My own indices gave much more accurate results.

Also cleaned up code a bit, but nothing else changes.
Release Notes:
Change made to the spot index.

This indicator compares perpetual swap contract prices to a spot index I made myself which consists of prices of the following markets: Coinbase, Bitfinex, Binance.

The problem however is that a bunch of spot markets often have down time during periods of very high volatility.
Because of this the data that the indicator shows is sometimes all messed up because the price of one spot exchange is stuck.

So I've added an option that allows you to use a custom ticker as a spot "index". So if either Coinbase, Bitfinex or Binance is down you can select in the drop down menu "custom ticker" and then look up a different exchange in the custom ticker field (which is by default set on Coinbase).
This way the indicator still works. Also all other functions like the clamp and the smoothing will still work even if you use a custom ticker.

Don't forget that if you set the indicator to "ETH" and you're still using a custom bitcoin ticker you'll have to change it to an ETH market of course.

Cheers.
Release Notes:
For good measure I added one more exchange to the premade spot index: the FTX USDT market.

So now the spot index consists of 2 USD markets and 2 USDT markets.
  • Coinbase USD
  • Bitfinex USD
  • Binance USDT
  • FTX USDT

I wanted to use Huobi or Okex first because those USDT spot markets have more volume, but Huobi and Okex often give data issues with indicators so FTX was the next best thing.

You can still also use a custom ticker as a spot index!
Release Notes:
Big update with a lot of changes.


FTX shut down so I replaced that data with Binance BUSD markets.

I changed the weighting of the indices so that very actively traded markets have a bigger impact.

The choice between coin margin and dollar margin contracts is now gone. Most dollar margin contracts now accept a plethora of collateral so the distinction between these two types of perps has faded, no real point in separating them anymore.

The threshold of the clamp and the shading zones has been increased a little bit.

I also cleaned up and made the code a bit more efficient so the indicator should load faster than it used to.

Enjoy.

Send me a private message for access to my invite only indicators.
Invite-only script

Access to this script is restricted to users authorized by the author and usually requires payment. You can add it to your favorites, but you will only be able to use it after requesting permission and obtaining it from its author. Contact ByzantiumScripts for more information, or follow the author's instructions below.

TradingView does not suggest paying for a script and using it unless you 100% trust its author and understand how the script works. In many cases you can find a good open-source alternative for free in our Community Scripts.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Author's instructions

Send me a private message for access so we can discuss it.

Want to use this script on a chart?

Warning: please read before requesting access.