Với tinh thần của TradingView, tác giả đã xuất bản tập lệnh theo mã nguồn mở, vì thế trader có thể dễ dàng hiểu và tùy chỉnh được. Bạn có thể sử dụng miễn phí, hoặc tùy chỉnh lại mã đã được cấp phép bởi Quy tắc Chung. Bạn có thể sử dụng nó trên biểu đồ.
Bình luận
i show your code: mc(t)=>
nz(financial(t, "TOTAL_SHARES_OUTSTANDING", "FQ"))*nz(security(t, timeframe.period, close))/billion
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.
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) )
// truncate() truncates a given number
// to a certain number of decimals
truncate(number, decimals) =>
factor = pow(10, decimals)
int(number * factor) / factor