Forked from joemccann/asymmetric-coinbase-premium-indicator-tradingview.sh
Created
January 8, 2025 22:14
-
-
Save dwrx/83e1f2aa09cf2599e68a27d70293c31d to your computer and use it in GitHub Desktop.
Revisions
-
joemccann created this gist
Jan 3, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ //@version=5 // // _____ __ .__ // / _ \ _________.__. _____ _____ _____/ |________|__| ____ // / /_\ \ / ___< | |/ \ / \_/ __ \ __\_ __ \ |/ ___\ // / | \\\___ \ \___ | Y Y \ Y Y \ ___/| | | | \/ \ \___ // \____|__ /____ >/ ____|__|_| /__|_| /\___ >__| |__| |__|\___ > // \/ \/ \/ \/ \/ \/ \/ // // Disclaimers: https://t.co/kOsUzy5pCB indicator("Asymmetric Coinbase Premium Histogram with SMA", overlay=false) // Extract the base currency from the current chart (e.g., "BTC" from "BTCUSD") base_asset = syminfo.basecurrency // Construct Coinbase and Binance symbols dynamically coinbase_symbol = "COINBASE:" + base_asset + "USD" binance_symbol = "BINANCE:" + base_asset + "USDT" // Fetch prices from Coinbase and Binance coinbase_price = request.security(coinbase_symbol, timeframe.period, close) binance_price = request.security(binance_symbol, timeframe.period, close) // Calculate the premium (absolute and percentage) premium = coinbase_price - binance_price percent_premium = (premium / binance_price) * 100 // Input to select between notional and percentage premium show_percent = input.bool(false, title="Show Percentage Premium") // Select the value to plot based on user input histogram_value = show_percent ? percent_premium : premium // Define the color based on the premium value bar_color = histogram_value > 0 ? color.green : color.red // Plot the histogram plot(histogram_value, style=plot.style_histogram, color=bar_color, title="Asymmetric Coinbase Premium Histogram") // Input for the moving average length sma_length = input.int(14, title="SMA Length", minval=1) // Calculate the simple moving average (SMA) of the premium sma_premium = ta.sma(histogram_value, sma_length) // Plot the SMA line on the same chart plot(sma_premium, color=color.gray, linewidth=2, title="SMA of Premium")