Bitcoin OnChain & Other Metrics
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LucasVivien

//@version=5
indicator("Bitcoin OnChain & Other Metrics", shorttitle="BTC Metrics", overlay=false, precision=1)

//==============================================================================
//==============================   USER INPUT   ================================
//==============================================================================

c_MKPRU = input.color(                                                       defval=#ff3333, inline="1", group="", title="") 
u_MKPRU = input.bool(title="Bitcoin Market Price USD"                      , defval=true   , inline="1", group="", tooltip="Average USD market price across major bitcoin exchanges.")
c_TRVOU = input.color(                                                       defval=#ff6633, inline="2", group="", title="")
u_TRVOU = input.bool(title="USD Exchange Trade Volume"                     , defval=false  , inline="2", group="", tooltip="The total USD value of trading volume on major bitcoin exchanges.")
c_DIFF  = input.color(                                                       defval=#ff9933, inline="3", group="", title="")
u_DIFF  = input.bool(title="Difficulty"                                    , defval=false  , inline="3", group="", tooltip="A relative measure of how difficult it is to find a new block. The difficulty is adjusted periodically as a function of how much hashing power has been deployed by the network of miners.")
c_MWNUS = input.color(                                                       defval=#ffcc33, inline="4", group="", title="")
u_MWNUS = input.bool(title="My Wallet Number of Users"                     , defval=false  , inline="4", group="", tooltip="Number of wallets hosts using Blockchain.com Service.")
c_AVBLS = input.color(                                                       defval=#ffff33, inline="5", group="", title="")
u_AVBLS = input.bool(title="Average Block Size"                            , defval=false  , inline="5", group="", tooltip="The average block size in MB.")
c_BLCHS = input.color(                                                       defval=#ccff33, inline="6", group="", title="")
u_BLCHS = input.bool(title="API.blockchain Size"                           , defval=false  , inline="6", group="", tooltip="The total size of all block headers and transactions. Not including database indexes.")
c_ATRCT = input.color(                                                       defval=#99ff33, inline="7", group="", title="")
u_ATRCT = input.bool(title="Median Transaction Confirmation Time"          , defval=false  , inline="7", group="", tooltip="The median time for a transaction to be accepted into a mined block and added to the public ledger (note: only includes transactions with miner fees).")
c_MIREV = input.color(                                                       defval=#66ff33, inline="8", group="", title="")
u_MIREV = input.bool(title="Miners Revenue"                                , defval=false  , inline="8", group="", tooltip="Total value of coinbase block rewards and transaction fees paid to miners.")
c_HRATE = input.color(                                                       defval=#33ff33, inline="9", group="", title="")
u_HRATE = input.bool(title="Hash Rate"                                     , defval=false  , inline="9", group="", tooltip="The estimated number of tera hashes per second (trillions of hashes per second) the Bitcoin network is performing.")
c_CPTRA = input.color(                                                       defval=#33ff66, inline="10", group="", title="")
u_CPTRA = input.bool(title="Cost Per Transaction"                          , defval=false  , inline="10", group="", tooltip="A chart showing miners revenue divided by the number of transactions.")
c_CPTRV = input.color(                                                       defval=#33ff99, inline="11", group="", title="")
u_CPTRV = input.bool(title="Cost % of Transaction Volume"                  , defval=false  , inline="11", group="", tooltip="A chart showing miners revenue as percentage of the transaction volume.")
c_ETRVU = input.color(                                                       defval=#33ffcc, inline="12", group="", title="")
u_ETRVU = input.bool(title="Estimated Transaction Volume USD"              , defval=false  , inline="12", group="", tooltip="The Estimated Transaction Value in USD value.")
c_ETRAV = input.color(                                                       defval=#33ffff, inline="13", group="", title="")
u_ETRAV = input.bool(title="Estimated Transaction Volume"                  , defval=false  , inline="13", group="", tooltip="The total estimated value of transactions on the Bitcoin blockchain (does not include coins returned to sender as change).")
c_TOUTV = input.color(                                                       defval=#33ccff, inline="14", group="", title="")
u_TOUTV = input.bool(title="Total Output Volume"                           , defval=false  , inline="14", group="", tooltip="The total value of all transaction outputs per day (includes coins returned to the sender as change).")
c_NTRBL = input.color(                                                       defval=#3399ff, inline="15", group="", title="")
u_NTRBL = input.bool(title="Number of Transaction per Block"               , defval=false  , inline="15", group="", tooltip="The average number of transactions per block.")
c_NADDU = input.color(                                                       defval=#3366ff, inline="16", group="", title="")
u_NADDU = input.bool(title="Number of Unique Bitcoin Addresses Used"       , defval=false  , inline="16", group="", tooltip="The total number of unique addresses used on the Bitcoin blockchain.")
c_NTREP = input.color(                                                       defval=#3333ff, inline="17", group="", title="")
u_NTREP = input.bool(title="Number of Transac. Excl. Popular Addresses"    , defval=false  , inline="17", group="", tooltip="The total number of Bitcoin transactions, excluding those involving any of the network's 100 most popular addresses.")
c_NTRAT = input.color(                                                       defval=#6633ff, inline="18", group="", title="")
u_NTRAT = input.bool(title="Total Number of Transactions"                  , defval=false  , inline="18", group="", tooltip="Total Number of transactions")
c_NTRAN = input.color(                                                       defval=#9933ff, inline="19", group="", title="")
u_NTRAN = input.bool(title="Number of Transactions"                        , defval=false  , inline="19", group="", tooltip="The number of daily confirmed Bitcoin transactions.")
c_TRFUS = input.color(                                                       defval=#cc33ff, inline="20", group="", title="")
u_TRFUS = input.bool(title="Total Transaction Fees USD"                    , defval=false  , inline="20", group="", tooltip="The total value of all transaction fees paid to miners (not including the coinbase value of block rewards).")
c_TRFEE = input.color(                                                       defval=#ff33ff, inline="21", group="", title="")
u_TRFEE = input.bool(title="Total Transaction Fees"                        , defval=false  , inline="21", group="", tooltip="The total value of all transaction fees paid to miners (not including the coinbase value of block rewards).")
c_MKTCP = input.color(                                                       defval=#ff33cc, inline="22", group="", title="")
u_MKTCP = input.bool(title="Market Capitalization"                         , defval=false  , inline="22", group="", tooltip="The total USD value of bitcoin supply in circulation, as calculated by the daily average market price across major exchanges.")
c_TOTBC = input.color(                                                       defval=#ff3399, inline="23", group="", title="")
u_TOTBC = input.bool(title="Total Bitcoins"                                , defval=false  , inline="23", group="", tooltip="The total number of bitcoins that have already been mined; in other words, the current supply of bitcoins on the network.")
c_MWNTD = input.color(                                                       defval=#ff3366, inline="24", group="", title="")
u_MWNTD = input.bool(title="My Wallet Number of Transaction Per Day"       , defval=false  , inline="24", group="", tooltip="Number of transactions made by My Wallet Users per day.")
c_MWTRV = input.color(                                                       defval=#ff3333, inline="25", group="", title="")
u_MWTRV = input.bool(title="My Wallet Transaction Volume"                  , defval=false  , inline="25", group="", tooltip="24hr Transaction Volume of our web wallet service.")


//==============================================================================
//===============================   GET DATA   =================================
//==============================================================================

req_MKPRU = request.quandl("BCHAIN/MKPRU", barmerge.gaps_off, 0)
req_TRVOU = request.quandl("BCHAIN/TRVOU", barmerge.gaps_off, 0)
req_DIFF  = request.quandl("BCHAIN/DIFF" , barmerge.gaps_off, 0)
req_MWNUS = request.quandl("BCHAIN/MWNUS", barmerge.gaps_off, 0)
req_AVBLS = request.quandl("BCHAIN/AVBLS", barmerge.gaps_off, 0)
req_BLCHS = request.quandl("BCHAIN/BLCHS", barmerge.gaps_off, 0)
req_ATRCT = request.quandl("BCHAIN/ATRCT", barmerge.gaps_off, 0)
req_MIREV = request.quandl("BCHAIN/MIREV", barmerge.gaps_off, 0)
req_HRATE = request.quandl("BCHAIN/HRATE", barmerge.gaps_off, 0)
req_CPTRA = request.quandl("BCHAIN/CPTRA", barmerge.gaps_off, 0)
req_CPTRV = request.quandl("BCHAIN/CPTRV", barmerge.gaps_off, 0)
req_ETRVU = request.quandl("BCHAIN/ETRVU", barmerge.gaps_off, 0)
req_ETRAV = request.quandl("BCHAIN/ETRAV", barmerge.gaps_off, 0)
req_TOUTV = request.quandl("BCHAIN/TOUTV", barmerge.gaps_off, 0)
req_NTRBL = request.quandl("BCHAIN/NTRBL", barmerge.gaps_off, 0)
req_NADDU = request.quandl("BCHAIN/NADDU", barmerge.gaps_off, 0)
req_NTREP = request.quandl("BCHAIN/NTREP", barmerge.gaps_off, 0)
req_NTRAT = request.quandl("BCHAIN/NTRAT", barmerge.gaps_off, 0)
req_NTRAN = request.quandl("BCHAIN/NTRAN", barmerge.gaps_off, 0)
req_TRFUS = request.quandl("BCHAIN/TRFUS", barmerge.gaps_off, 0)
req_TRFEE = request.quandl("BCHAIN/TRFEE", barmerge.gaps_off, 0)
req_MKTCP = request.quandl("BCHAIN/MKTCP", barmerge.gaps_off, 0)
req_TOTBC = request.quandl("BCHAIN/TOTBC", barmerge.gaps_off, 0)
req_MWNTD = request.quandl("BCHAIN/MWNTD", barmerge.gaps_off, 0)
req_MWTRV = request.quandl("BCHAIN/MWTRV", barmerge.gaps_off, 0)


//==============================================================================
//=================================   PLOTS   ==================================
//==============================================================================

plot(u_MKPRU ? req_MKPRU : na, title="", color=c_MKPRU, style=plot.style_linebr)
plot(u_TRVOU ? req_TRVOU : na, title="", color=c_TRVOU, style=plot.style_linebr)
plot(u_DIFF  ? req_DIFF  : na, title="", color=c_DIFF , style=plot.style_linebr)
plot(u_MWNUS ? req_MWNUS : na, title="", color=c_MWNUS, style=plot.style_linebr)
plot(u_AVBLS ? req_AVBLS : na, title="", color=c_AVBLS, style=plot.style_linebr)
plot(u_BLCHS ? req_BLCHS : na, title="", color=c_BLCHS, style=plot.style_linebr)
plot(u_ATRCT ? req_ATRCT : na, title="", color=c_ATRCT, style=plot.style_linebr)
plot(u_MIREV ? req_MIREV : na, title="", color=c_MIREV, style=plot.style_linebr)
plot(u_HRATE ? req_HRATE : na, title="", color=c_HRATE, style=plot.style_linebr)
plot(u_CPTRA ? req_CPTRA : na, title="", color=c_CPTRA, style=plot.style_linebr)
plot(u_CPTRV ? req_CPTRV : na, title="", color=c_CPTRV, style=plot.style_linebr)
plot(u_TRVOU ? req_TRVOU : na, title="", color=c_TRVOU, style=plot.style_linebr)
plot(u_ETRVU ? req_ETRVU : na, title="", color=c_ETRVU, style=plot.style_linebr)
plot(u_ETRAV ? req_ETRAV : na, title="", color=c_ETRAV, style=plot.style_linebr)
plot(u_TOUTV ? req_TOUTV : na, title="", color=c_TOUTV, style=plot.style_linebr)
plot(u_NTRBL ? req_NTRBL : na, title="", color=c_NTRBL, style=plot.style_linebr)
plot(u_NADDU ? req_NADDU : na, title="", color=c_NADDU, style=plot.style_linebr)
plot(u_NTREP ? req_NTREP : na, title="", color=c_NTREP, style=plot.style_linebr)
plot(u_NTRAT ? req_NTRAT : na, title="", color=c_NTRAT, style=plot.style_linebr)
plot(u_NTRAN ? req_NTRAN : na, title="", color=c_NTRAN, style=plot.style_linebr)
plot(u_TRFUS ? req_TRFUS : na, title="", color=c_TRFUS, style=plot.style_linebr)
plot(u_TRFEE ? req_TRFEE : na, title="", color=c_TRFEE, style=plot.style_linebr)
plot(u_MKTCP ? req_MKTCP : na, title="", color=c_MKTCP, style=plot.style_linebr)
plot(u_TOTBC ? req_TOTBC : na, title="", color=c_TOTBC, style=plot.style_linebr)
plot(u_MWNTD ? req_MWNTD : na, title="", color=c_MWNTD, style=plot.style_linebr)
plot(u_MWTRV ? req_MWTRV : na, title="", color=c_MWTRV, style=plot.style_linebr)