本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Default inputs: the BICAPITAL 40/60 crypto portfolio as of 5 Nov 2026 (cost share and average price of each coin).
//@version=6
indicator("Portfolio tracker: basket return on average cost vs BTC", "Basket vs BTC", overlay = false, format = format.percent, precision = 2)
string GG = "General"
int startDate = input.time(timestamp("2026-08-20T00:00:00+00:00"), "Plot from", group = GG, display = display.none)
float btcBench = input.float(79718.71, "BTC benchmark entry price (same cash flows in BTC only)", minval = 0, group = GG, display = display.none)
bool showTable = input.bool(true, "Show table", group = GG, display = display.none)
string G = "Holdings: symbol, share of cost (%), average price"
string s01 = input.symbol("BINANCE:BTCUSDT", "BTC", inline = "01", group = G, display = display.none)
float c01 = input.float(38.300, "", minval = 0, inline = "01", group = G, display = display.none)
float p01 = input.float(78012.03053, "", minval = 0, inline = "01", group = G, display = display.none)
string s02 = input.symbol("BINANCE:SOLUSDT", "SOL", inline = "02", group = G, display = display.none)
float c02 = input.float(3.288, "", minval = 0, inline = "02", group = G, display = display.none)
float p02 = input.float(102.8976574, "", minval = 0, inline = "02", group = G, display = display.none)
string s03 = input.symbol("BINANCE:TAOUSDT", "TAO", inline = "03", group = G, display = display.none)
float c03 = input.float(3.155, "", minval = 0, inline = "03", group = G, display = display.none)
float p03 = input.float(239.373307, "", minval = 0, inline = "03", group = G, display = display.none)
string s04 = input.symbol("BINANCE:PENGUUSDT", "PENGU", inline = "04", group = G, display = display.none)
float c04 = input.float(3.242, "", minval = 0, inline = "04", group = G, display = display.none)
float p04 = input.float(0.007368727426, "", minval = 0, inline = "04", group = G, display = display.none)
string s05 = input.symbol("BINANCE:PUMPUSDT", "PUMP", inline = "05", group = G, display = display.none)
float c05 = input.float(2.959, "", minval = 0, inline = "05", group = G, display = display.none)
float p05 = input.float(0.004050836106, "", minval = 0, inline = "05", group = G, display = display.none)
string s06 = input.symbol("BINANCE:SYRUPUSDT", "SYRUP", inline = "06", group = G, display = display.none)
float c06 = input.float(3.577, "", minval = 0, inline = "06", group = G, display = display.none)
float p06 = input.float(0.1781831507, "", minval = 0, inline = "06", group = G, display = display.none)
string s07 = input.symbol("BINANCE:ETHFIUSDT", "ETHFI", inline = "07", group = G, display = display.none)
float c07 = input.float(3.202, "", minval = 0, inline = "07", group = G, display = display.none)
float p07 = input.float(0.5879580915, "", minval = 0, inline = "07", group = G, display = display.none)
string s08 = input.symbol("BINANCE:ONDOUSDT", "ONDO", inline = "08", group = G, display = display.none)
float c08 = input.float(3.051, "", minval = 0, inline = "08", group = G, display = display.none)
float p08 = input.float(0.3957131482, "", minval = 0, inline = "08", group = G, display = display.none)
string s09 = input.symbol("BINANCE:JTOUSDT", "JTO", inline = "09", group = G, display = display.none)
float c09 = input.float(3.635, "", minval = 0, inline = "09", group = G, display = display.none)
float p09 = input.float(0.4175252114, "", minval = 0, inline = "09", group = G, display = display.none)
string s10 = input.symbol("BINANCE:ASTERUSDT", "ASTER", inline = "10", group = G, display = display.none)
float c10 = input.float(3.090, "", minval = 0, inline = "10", group = G, display = display.none)
float p10 = input.float(0.7060469781, "", minval = 0, inline = "10", group = G, display = display.none)
string s11 = input.symbol("BINANCE:VIRTUALUSDT", "VIRTUAL", inline = "11", group = G, display = display.none)
float c11 = input.float(3.249, "", minval = 0, inline = "11", group = G, display = display.none)
float p11 = input.float(0.6298534244, "", minval = 0, inline = "11", group = G, display = display.none)
string s12 = input.symbol("BINANCE:PENDLEUSDT", "PENDLE", inline = "12", group = G, display = display.none)
float c12 = input.float(3.632, "", minval = 0, inline = "12", group = G, display = display.none)
float p12 = input.float(2.0881106, "", minval = 0, inline = "12", group = G, display = display.none)
string s13 = input.symbol("BINANCE:NEARUSDT", "NEAR", inline = "13", group = G, display = display.none)
float c13 = input.float(2.539, "", minval = 0, inline = "13", group = G, display = display.none)
float p13 = input.float(3.306405077, "", minval = 0, inline = "13", group = G, display = display.none)
string s14 = input.symbol("BINANCE:SKYUSDT", "SKY", inline = "14", group = G, display = display.none)
float c14 = input.float(2.959, "", minval = 0, inline = "14", group = G, display = display.none)
float p14 = input.float(0.06495637056, "", minval = 0, inline = "14", group = G, display = display.none)
string s15 = input.symbol("BINANCE:POLUSDT", "POL", inline = "15", group = G, display = display.none)
float c15 = input.float(3.060, "", minval = 0, inline = "15", group = G, display = display.none)
float p15 = input.float(0.0980628033, "", minval = 0, inline = "15", group = G, display = display.none)
string s16 = input.symbol("BINANCE:MORPHOUSDT", "MORPHO", inline = "16", group = G, display = display.none)
float c16 = input.float(3.095, "", minval = 0, inline = "16", group = G, display = display.none)
float p16 = input.float(2.222783279, "", minval = 0, inline = "16", group = G, display = display.none)
string s17 = input.symbol("BINANCE:METUSDT", "MET", inline = "17", group = G, display = display.none)
float c17 = input.float(2.676, "", minval = 0, inline = "17", group = G, display = display.none)
float p17 = input.float(0.2480809154, "", minval = 0, inline = "17", group = G, display = display.none)
string s18 = input.symbol("BINANCE:REDUSDT", "RED", inline = "18", group = G, display = display.none)
float c18 = input.float(2.210, "", minval = 0, inline = "18", group = G, display = display.none)
float p18 = input.float(0.1350118198, "", minval = 0, inline = "18", group = G, display = display.none)
string s19 = input.symbol("BINANCE:BERAUSDT", "BERA", inline = "19", group = G, display = display.none)
float c19 = input.float(2.190, "", minval = 0, inline = "19", group = G, display = display.none)
float p19 = input.float(0.1879540361, "", minval = 0, inline = "19", group = G, display = display.none)
string s20 = input.symbol("BINANCE:BABYUSDT", "BABY", inline = "20", group = G, display = display.none)
float c20 = input.float(2.255, "", minval = 0, inline = "20", group = G, display = display.none)
float p20 = input.float(0.01174935267, "", minval = 0, inline = "20", group = G, display = display.none)
string s21 = input.symbol("BINANCE:GPSUSDT", "GPS", inline = "21", group = G, display = display.none)
float c21 = input.float(2.571, "", minval = 0, inline = "21", group = G, display = display.none)
float p21 = input.float(0.01046884695, "", minval = 0, inline = "21", group = G, display = display.none)
string s22 = input.symbol("BINANCE:ORCAUSDT", "ORCA", inline = "22", group = G, display = display.none)
float c22 = input.float(2.066, "", minval = 0, inline = "22", group = G, display = display.none)
float p22 = input.float(1.422607325, "", minval = 0, inline = "22", group = G, display = display.none)
f(string s) => request.security(s, timeframe.period, close)
fmtP(float p) => str.tostring(p, p >= 100 ? "#" : p >= 1 ? "#.###" : "#.######")
array<string> syms = array.from(s01, s02, s03, s04, s05, s06, s07, s08, s09, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22)
array<float> shares = array.from(c01, c02, c03, c04, c05, c06, c07, c08, c09, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22)
array<float> avgs = array.from(p01, p02, p03, p04, p05, p06, p07, p08, p09, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22)
array<float> closes = array.from(f(s01), f(s02), f(s03), f(s04), f(s05), f(s06), f(s07), f(s08), f(s09), f(s10), f(s11), f(s12), f(s13), f(s14), f(s15), f(s16), f(s17), f(s18), f(s19), f(s20), f(s21), f(s22))
// Return on cost of the current holdings: each coin's price over its average price, weighted by its share of cost.
float val = 0.0
float tot = 0.0
for i = 0 to array.size(syms) - 1
float c = array.get(closes, i)
float p = array.get(avgs, i)
float w = array.get(shares, i)
if not na(c) and p > 0 and w > 0
val += w * c / p
tot += w
float basket = tot > 0 ? (val / tot - 1) * 100 : na
float btcRet = btcBench > 0 ? (array.get(closes, 0) / btcBench - 1) * 100 : na
bool show = time >= startDate
plot(show ? basket : na, "Basket return on cost", color.new(#2a78d6, 0), 2)
plot(show ? btcRet : na, "BTC only, same cash flows", color.new(#eb6834, 0), 2)
hline(0, "Zero", color.gray, hline.style_dotted)
var table tb = table.new(position.top_left, 4, 24, bgcolor = color.new(color.black, 85), border_width = 1)
if showTable and barstate.islast
table.cell(tb, 0, 0, "Coin", text_color = color.gray, text_size = size.small)
table.cell(tb, 1, 0, "Cost %", text_color = color.gray, text_size = size.small)
table.cell(tb, 2, 0, "Avg price", text_color = color.gray, text_size = size.small)
table.cell(tb, 3, 0, "vs avg", text_color = color.gray, text_size = size.small)
for i = 0 to array.size(syms) - 1
string nm = str.replace(str.replace(array.get(syms, i), "BINANCE:", ""), "USDT", "")
float c = array.get(closes, i)
float p = array.get(avgs, i)
float r = p > 0 and not na(c) ? (c / p - 1) * 100 : na
table.cell(tb, 0, i + 1, nm, text_color = chart.fg_color, text_size = size.small)
table.cell(tb, 1, i + 1, str.tostring(array.get(shares, i) / tot * 100, "0.0"), text_color = chart.fg_color, text_size = size.small)
table.cell(tb, 2, i + 1, fmtP(p), text_color = chart.fg_color, text_size = size.small)
table.cell(tb, 3, i + 1, na(r) ? "n/a" : str.tostring(r, "+0.0;-0.0") + "%", text_color = na(r) ? color.gray : r >= 0 ? color.teal : color.red, text_size = size.small)
table.cell(tb, 0, array.size(syms) + 1, "Basket", text_color = chart.fg_color, text_size = size.small)
table.cell(tb, 3, array.size(syms) + 1, str.tostring(basket, "+0.0;-0.0") + "%", text_color = basket >= 0 ? color.teal : color.red, text_size = size.small)