Indicator · Pine Script v5 · Own pane

FTX Premium Indicator

by blenessy

The FTX Premium Indicator calculates and plots the relative price spread between cryptocurrency futures and spot contracts in a separate pane.

View on GitHub

GitHub stars4on the repository
Pine versionv5runs as is
Lines of code84
Settings8inputs
LicenceMIT
Last update4 years ago22 Sep 2022

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

84 lines of Pine Script v5 from indicators/ftx_premium.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

ftx_premium.pine
//@version=5
// Copyright © Zalan Blenessy 2021
indicator('FTX Premium Indicator', 'PREM', overlay=false, precision=4)

// Inputs
tickersInput = input.string("PERP/USD", "Tickers:", options=["PERP/USD","0325/USD","0325/PERP","0624/USD","0624/PERP","0624/0325"], inline="Ticker")
tickerSourceInput = input.string("close", "Source:", options=["open","close","oc2","occ3","occc4"], inline="Ticker")
smoothingTypeInput = input.string("SMA", "Smoothing:", options=["ALMA", "EMA", "HMA", "RMA", "SMA", "VWMA", "WMA"], inline="MA")
smoothingLengthInput = input.int(20, "Length:", minval=2, inline="MA")
almaOffsetInput = input.float(0.85, "ALMA offset:", step=0.01, minval=0.0, inline="ALMA")
almaSigmaInput = input.float(6, "Sigma:", minval=1, inline="ALMA")
bandsFactorInput = input.float(2.0, "Bollinger Band Factor:", minval=0.1, step=0.1, inline="BB")
apyEnabledInput = input.bool(true, "APY normalization enabled")


// MA Chooser function
movingAverage(source, length) =>
    switch smoothingTypeInput
        "ALMA" => ta.alma(source, length, almaOffsetInput, almaSigmaInput)
        "EMA" => ta.ema(source, length)
        "HMA" => ta.ema(source, length)
        "RMA" => ta.rma(source, length)
        "SMA" => ta.sma(source, length)
        "VWMA" => ta.vwma(source, length)
        "WMA" => ta.wma(source, length)
        => na


// Calculate number of millis until the given date in the future
futureTime(now, mo, d, h, mi) =>
    (month(now) * 100 + dayofmonth(now)) < (100 * mo + d) ?
     timestamp(year(now), 3, 25, 3, 0) :
     timestamp(year(now) + 1, 3, 25, 3, 0)


oneJulianYearInMillis = 31557600000.0 // 365.25 * 24 * 60 * 60 * 1000
oneJulianYearInHours = oneJulianYearInMillis / 3600000
apyFactor(now) =>
    switch tickersInput
        "0325/USD" => apyEnabledInput ? oneJulianYearInMillis / (futureTime(now, 3, 25, 3, 0) - now) : 1
        "0325/PERP" => apyEnabledInput ? oneJulianYearInMillis / (futureTime(now, 3, 25, 3, 0) - now) : 1
        "0624/USD" => apyEnabledInput ? oneJulianYearInMillis / (futureTime(now, 6, 24, 3, 0) - now) : 1
        "0624/PERP" => apyEnabledInput ? oneJulianYearInMillis / (futureTime(now, 6, 24, 3, 0) - now) : 1
        "0624/0325" => apyEnabledInput ? oneJulianYearInMillis / (futureTime(now, 6, 24, 3, 0) - futureTime(now, 3, 25, 3, 0)) : 1
        "PERP/USD" => (apyEnabledInput ? oneJulianYearInHours : 1) / 24
        => 1.0

// Calculate the fractional premium
calcPremium(spo, spc, fpo, fpc) =>
    switch tickerSourceInput
        "open" => fpo / spo - 1
        "close" => fpc / spc - 1
        "oc2" => (fpo / spo + fpc / spc) / 2 - 1
        "occ3" => (fpo / spo + 2 * fpc / spc) / 3 - 1
        "occc4" => (fpo / spo + 3 * fpc / spc) / 4 - 1
        => na

// Setup Tickers
tickerPrefix = syminfo.prefix + ':' + syminfo.basecurrency
futureTickerSuffix = str.match(tickersInput, "^\\w+") // BTC/USD => BTC
futureTicker = tickerPrefix + futureTickerSuffix
spotTickerSuffix = str.match(tickersInput, "\\w+$") // BTC/USD => USD
spotTicker = tickerPrefix + str.match(tickersInput, "\\w+$")

// Calculate the price here
[spo, spc] = request.security(spotTicker, timeframe.period, [open, close])
[fpo, fpc] = request.security(futureTicker, timeframe.period, [open, close])

// Fractional Premium
premium = calcPremium(spo, spc, fpo, fpc) * apyFactor(time)
smoothPremium = movingAverage(premium, smoothingLengthInput)

// BB Bands
bandDelta = bandsFactorInput * ta.stdev(premium, smoothingLengthInput)
upperBand = smoothPremium + bandDelta
lowerBand = smoothPremium - bandDelta

// plot the ratio, with a zero line for reference
plot(100 * premium, 'Premium', color.new(premium >= 0 ? color.yellow : color.red, 0), style=plot.style_cross)
p0 = plot(100 * smoothPremium, 'Smooth Premium', color.new(color.blue, 0), style=plot.style_line)
p1 = plot(100 * lowerBand, 'Lower Band', color.new(color.blue, 0))
p2 = plot(100 * upperBand, 'Upper Band', color.new(color.blue, 0))
fill(p0, p2, color=color.new(color.blue, 80))
fill(p0, p1, color=color.new(color.blue, 80))

Overview

FTX Premium Indicator compares perpetual or dated contracts against spot markets and can normalize the difference into an annualized percentage yield. Users can select the price source, apply various moving averages such as SMA, EMA, or ALMA for smoothing, and plot standard deviation volatility bands around the baseline. Note that the script relies on specific FTX exchange ticker conventions and expiration schedules.

Details

Published by

blenessy on GitHub

Draws

Separate pane below the chart

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Tickers:stringPERP/USDtickersInput
Source:stringclosetickerSourceInput
Smoothing:stringSMAsmoothingTypeInput
Length:int20smoothingLengthInput
ALMA offset:float0.85almaOffsetInput
Sigma:float6almaSigmaInput
Bollinger Band Factor:float2.0bandsFactorInput
APY normalization enabledbooltrueapyEnabledInput
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

318 stars

Calculates and plots moving averages on selected VIX volatility terms (VIX9D, VIX, VIX3M, or VIX6M) in a separate pane. The script computes user-defined short and long moving averages using EMA or SMA. It shades the background red when the short-term moving av

Indicator v5 Volatility & bandsMoving averages
Updated 2 months ago · MIT GitHub repository of [TVT] VIX Short Term Danger

MACD-V

by harryguiacorn
220 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

The AMFM indicator decomposes price movements into amplitude and frequency components using Ehlers' digital signal processing methods. It whitens the derivative as close minus open, then computes AM as the smoothed envelope of the absolute difference over 4 pe

Indicator v6 Volatility & bandsMoving averages
Updated 4 weeks ago · Apache-2.0 GitHub repository of AMFM - Ehlers AM Detector / FM Demodulator

PPO ATR Bands

by cryptorife
75 stars

PPO ATR Bands plots a percentage price oscillator in a separate pane. It compares a Hull average of typical price with a volume-weighted exponential average of Parabolic SAR, then scales three true-range bands around the slow average into matching oscillator l

Indicator v4 Oscillators & momentumMoving averages
Updated 3 years ago · GPL-3.0 GitHub repository of PPO ATR Bands

More Moving averages scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers