OPEN-SOURCE SCRIPT

premium

197
//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))

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.