TradingView
danarm
Oct 18, 2020 3:23 PM

Capitalization of BTC vs. Top 5 US Corporations 

Bitcoin / U.S. dollarBitstamp

Description

This script displays the capitalization of Bitcoin as a percentage of the capitalization of 5 large US corporations: Apple, Microsoft, Amazon, Google, Facebook. According to tradingview.com/markets/stocks-usa/market-movers-large-cap/ these are (at the current time) the largest US companies.
Comments
stratanic
thx, can you help me, there is no variable for market cap ? market cap in Millions
i show your code: mc(t)=>
nz(financial(t, "TOTAL_SHARES_OUTSTANDING", "FQ"))*nz(security(t, timeframe.period, close))/billion
danarm
mc(t)=> // define the function
nz(financial(t, "TOTAL_SHARES_OUTSTANDING", "FQ"))*nz(security(t, timeframe.period, close))/billion

The value of the last expression is returned by the function. If you want to, you can also put it into a variable, like this:

mc(t)=> // define the function
market_cap=nz(financial(t, "TOTAL_SHARES_OUTSTANDING", "FQ"))*nz(security(t, timeframe.period, close))/billion

Keep in mind that the variable market_cap defined above is local to the function, and you must do something with it in the function's scope. If you want to put the result in a variable in the global scope, you do something like this:

mc(t)=> // define the function
nz(financial(t, "TOTAL_SHARES_OUTSTANDING", "FQ"))*nz(security(t, timeframe.period, close))/billion

// Get capitalization of ICE which is listed at NYSE
ice_market_cap=mc("nyse:ICE")

In other words, you call the function, passing it the ticker you want (must be prefixed by exchange - in our case - NYSE).

If you need the capitalization of the current ticker, use syminfo.tickerid as a parameter, like this:

// Get capitalization of current ticker
ice_market_cap=mc(syminfo.tickerid)

The above works for stocks. For crypto, you have to use security() to request market cap symbols. For example:

bnb_market_cap=security("CRYPTOCAP:BNB", timeframe.period, close)

... and you get the capitalization of BNB, in dollars.
stratanic
@danarm,
thx great, for syminfo.tickerid , i don't need to search now :)

I have another issue : i want just one number of decimals after the floating point

my code

study(title="Market cap", overlay=true, precision=1)

Million=1000000

// returns market cap of ticker T, in Millions
mc(t)=>
nz(financial(t, "TOTAL_SHARES_OUTSTANDING", "FQ"))*nz(security(t, timeframe.period, close))/Million

var label myLabel = label.new(x=bar_index, y=high + tr,
textcolor=color.black, color=color.white)

// On the last bar, show the chart's bar count
if (barstate.islast)
// Set the label content
label.set_text(id=myLabel, text="Market Cap:\n" +
tostring(mc(syminfo.tickerid)))

// Update the label's location
label.set_x(id=myLabel, x=bar_index)
label.set_y(id=myLabel, y=high + (high / 15) )
stratanic
@stratanic, ok I find

// truncate() truncates a given number
// to a certain number of decimals
truncate(number, decimals) =>
factor = pow(10, decimals)
int(number * factor) / factor
More