OPEN-SOURCE SCRIPT
premium

//version=5
indicator("Custom Binance Premium Index + Alerts", overlay=false)
// === 1. 数据源(可修改) ===
// 永续合约价格(默认 BTCUSDT 永续)
futures = request.security("BINANCE:BTCUSDT_PERP", timeframe.period, close)
// 现货价格(默认 BTCUSDT 现货)
spot = request.security("BINANCE:BTCUSDT", timeframe.period, close)
// === 2. 计算自定义溢价指数 ===
premium = ((futures / spot) - 1) * 100
// === 3. 用户设定阈值(你给的值) ===
upper = 1.5 // 溢价 ≥ 1.5 触发告警
lower = -2.0 // 溢价 ≤ -2.0 触发告警
// === 4. 绘图 ===
plot(premium, title="Premium Index (%)", color=color.new(color.blue, 0))
hline(upper, "Upper Threshold (1.5%)", color=color.new(color.red, 0))
hline(lower, "Lower Threshold (-2.0%)", color=color.new(color.green, 0))
// === 5. 告警条件 ===
alertcondition(premium >= upper,
title="溢价 ≥ 1.5%",
message="Premium Index ≥ 1.5%(永续合约偏高,多头较强)"
)
alertcondition(premium <= lower,
title="溢价 ≤ -2.0%",
message="Premium Index ≤ -2.0%(永续合约偏低,空头压力大)"
)
// === 6. 信息显示 ===
label.new(bar_index, premium, "Premium: " + str.tostring(premium, "#.##") + "%",
style=label.style_label_left, color=color.new(color.blue, 85))
indicator("Custom Binance Premium Index + Alerts", overlay=false)
// === 1. 数据源(可修改) ===
// 永续合约价格(默认 BTCUSDT 永续)
futures = request.security("BINANCE:BTCUSDT_PERP", timeframe.period, close)
// 现货价格(默认 BTCUSDT 现货)
spot = request.security("BINANCE:BTCUSDT", timeframe.period, close)
// === 2. 计算自定义溢价指数 ===
premium = ((futures / spot) - 1) * 100
// === 3. 用户设定阈值(你给的值) ===
upper = 1.5 // 溢价 ≥ 1.5 触发告警
lower = -2.0 // 溢价 ≤ -2.0 触发告警
// === 4. 绘图 ===
plot(premium, title="Premium Index (%)", color=color.new(color.blue, 0))
hline(upper, "Upper Threshold (1.5%)", color=color.new(color.red, 0))
hline(lower, "Lower Threshold (-2.0%)", color=color.new(color.green, 0))
// === 5. 告警条件 ===
alertcondition(premium >= upper,
title="溢价 ≥ 1.5%",
message="Premium Index ≥ 1.5%(永续合约偏高,多头较强)"
)
alertcondition(premium <= lower,
title="溢价 ≤ -2.0%",
message="Premium Index ≤ -2.0%(永续合约偏低,空头压力大)"
)
// === 6. 信息显示 ===
label.new(bar_index, premium, "Premium: " + str.tostring(premium, "#.##") + "%",
style=label.style_label_left, color=color.new(color.blue, 85))
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.