Bitcoin Halving Rainbow + S2F Model PriceOverview
The rainbow price line:
This script creates a colorful view of Bitcoin's price action, where different colors indicate the time until the next halving date. The color scale in the top right highlights what each main color group represents in terms of days until the next halving. Using historical data, the simple indication of days until the next halving has somewhat accurately predicted potential bottoms and tops of market cycles. Comparing current colors to previous cycles provides a rough view of where BTC is in its current cycle and what to expect going forward until the next halving date.
In addition to the colored price action, I have incorporated the stock-to-flow model price for Bitcoin.
The stock-to-flow (S2F) model price:
The stock-to-flow ratio is a calculation that aims to estimate how many years are required to produce the current stock of an asset, based on the current production rate. When applied to Bitcoin, we simply divide the total amount of bitcoins in circulation by the amount of bitcoins mined in a certain timeframe. Once we have this value, we can calculate a model price based on the stock-to-flow ratio. This S2F model price uses a 463-day moving average. Preston Pysh came up with this number as he believed Bitcoin cycles happen in three phases: bull run, correction, and a reversion to the mean. He estimated there are about 200,000 blocks per cycle, three phases per cycle, and ~144 blocks per day. Dividing all three gets us 463. I have removed 1,000,000 coins from this calculation to account for Satoshi's coins.
The process I took to plot this model price (credit to PlanB for originally creating this calculation):
-Declare constant variables for the halving period, starting block reward, and the number of coins Satoshi owns.
-Fetch the block index by using the request.security() function.
-Determine the number of halvings that have occurred by dividing the block index by the halving period.
-Calculate the current block reward by multiplying the initial block reward by 0.5 raised to the power of the number of halvings.
-Calculate the number of blocks mined per period (day or week) and derive the stock (total bitcoins in circulation minus Satoshi's coins) and flow (annual block rewards) from it.
-Calculate the S2F ratio by dividing the stock by the flow.
-Calculate the S2F model price by applying a mathematical formula (ModelPrice = exp(-1.84) * S2F to the power of 3.36) along with a 463-day moving average.
** Please note, due to the use of the 463-day MA, the first ~400 days of the S2F model price is not entirely accurate.
In addition to the above, I have added vertical lines on each halving date, along with labels that have a tooltip if you hover over them, which will show more information about that particular halving.
Important tips:
-This script has been designed to work on the 1-Day timeframe but can also work on the 1-Week timeframe. Any other timeframe will not accurately plot all the information due to the way I have developed the script.
-This script is best used on the ticker I have posted this on, "INDEX:BTCUSD". It can also work on "BLX" or "BITSTAMP:BTCUSD".
-Hide candles when using the script to just show the halving rainbow (hover over the symbol name in the top left and press the eye icon).
-Right-click the price scale and select "Scale price chart only" to get a better view of the plots.
-Right-click the price scale and select "Logarithmic."
-I will update the script as time goes on to show future halvings along with adjusting the next halving date as we get closer (if it changes).
Settings Menu:
Tooltips are included explaining what the settings do, but here's a quick summary:
-'Show Vertical Halving Lines?': Default is true. This allows the user to remove the vertical lines shown on each halving date.
-'Show Halving Labels?': Default is true. This allows the user to remove the info labels shown on each halving date.
-'Halving Line and Label Color': Default is white. This allows the user to change the color of the halving lines and labels to better fit their chart layout.
-'Show Stock to Flow Model Price?': Default is true. This allows the user to remove the S2F model price.
-'Stock to Flow Model Price Color': Default is white. This allows the user to change the color of the S2F model price to better fit their chart layout.
-'Draw Color Table?': Default is true. This allows the user to remove the color table in the top right of the chart.
-'Distance rainbow is away from actual price action': Default is 0 (Plots over candles). This allows the user to adjust where the halving rainbow is plotted if they would like to also see candles on the chart. (Use any value under 0.9)
Feel free to message me or comment on the post with any questions or issues!
Much more to come!
Thanks for reading, enjoy!
S2f
{Gunzo} Stock to Flow (Gold, Silver, Dollar, Bitcoin)This indicator displays the Stock to Flow (S2F) ratio for popular commodities (Gold, Silver, Dollar, Euro, Bitcoin, Ethereum) in order to
compare them and determine which ones could be a good Store of Value (SoV).
OVERVIEW :
Stock to Flow is a popular indicator used to predict commodities scarcity. It evaluates the total stock of a commodity against the total amount that can be produced during a year. This model supposes that if scarcity is increasing, the price is going to increase.
This model has been used over the last years on Bitcoin to determine if the asset was undervalued or overvalued, and even make prediction models on the future price.
This script is going to focus on the Stock to Flow ratio (total stock/amount produced) to compare the following assets over time :
Mining resources (mined) for Gold and Silver
Cryptos assets (mined) for Bitcoin and Ethereum
FIAT currencies (banknotes printed) for Dollar and Euro
CALCULATION :
The calculation of the Stock to Flow ratio evaluates the total stock of a commodity produced against the production made for a specific year. The data is calculated on a yearly basis, then interpolated to get monthly or daily values.
DATA ORIGIN :
The main information needed to calculate the Stock to Flow ratio is the "yearly production" of a commodity. I tried to retrieve that information from the most reliable sources :
for Gold from research on www.gold.org
for Silver from research on www.silverinstitute.org
for Ethereum from research on etherscan.io
for Bitcoin from data source "QUANDL:BCHAIN/TOTBC" from www.quandl.com
for Dollar from research on www.federalreserve.gov
for Euro from research on www.ecb.europa.eu
SETTINGS :
Smoothing for interpolated data : Smoothing factor for assets that are calculated yearly and then interpolated (Gold, Silver, Dollar, Euro, and Ethereum)
Smoothing for non interpolated data : Smoothing factor for assets that are calculated daily and not interpolated (Bitcoin)
Display asset names : Display assets names in a colored rectangle on the right side of the chart
Display asset values : Display assets Stock to Flow ratio in a colored rectangle on the right side of the chart
Display key events for assets : Display important events for the assets at the bottom of the chart using the same color as the assets lines (for example Orange diamond is a Bitcoin halving). Please refer to the script code for the details of all events.
USAGE :
This script can be used on any asset available on TradingView as the data used is either static or external.
However I recommend using it the Gold asset from currency.com as the depth of the chart will be bigger (since 1980s).
It is recommended to used this script on the monthly timeframe as the chart data is calculated yearly and then interpolated.
S2F Price LevelsThis is the indicator that plots Bitcoin's Stock to Flow model price and its significant levels.
Grey: S2F price
Green: S2F bottom (S2F multiple of 0.5)
Blue: S2F mode (S2F multiple of 0.67)
Red: S2F top