You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Pine Script中添加ticker条目以接收BTC期货数据

Pine Script适配BTC期货数据修改方案

核心修改点

  • 在原有外汇品种映射的fxroot逻辑中新增BTC期货的CFTC代码映射,比特币期货在CFTC的上报根代码为BTC,添加匹配规则后脚本识别到BTC相关交易对时会自动匹配对应CFTC数据源
  • BTC对USD计价的期货属于正向计价品类,无需添加到反向计价的is_inversed规则列表中
  • 适配完成后可直接在BTCUSD交易对下打开脚本,也可以手动在Override Product输入框填写BTC强制读取BTC期货的CFTC数据

修改后完整代码

study("William's Commercial Index", shorttitle="WILLCO", precision=2)
force_root = input("", title="Override Product")
is_includeoptions = input(false, type=bool, title="Include Options")

fxroot =
      ticker == "USDRUB" ? "RU" : 
      ticker == "USDSEK" ? "SE" : 
      ticker == "USDZAR" ? "RA" : 
      ticker == "EURUSD" ? "EC" : 
      ticker == "AUDUSD" ? "AD" : 
      ticker == "GBPUSD" ? "BP" : 
      ticker == "NZDUSD" ? "NE" : 
      ticker == "BRLUSD" ? "BR" : 
      ticker.contains("BTC") ? "BTC" : // 新增BTC期货映射规则
      ""
root = force_root == "" ? fxroot == "" ? syminfo.root : fxroot : force_root
code = root + (is_includeoptions ? "_FO_L_ALL" : "_F_L_ALL")

is_inversed = 
      ticker == "USDNOK" ? true : 
      ticker == "USDPLN" ? true : 
      ticker == "USDRUB" ? true : 
      ticker == "USDSEK" ? true : 
      ticker == "USDZAR" ? true : 
      false

long_total = security("QUANDL:CFTC/"+code+"|4", "D", close)
short_total = close
oi = security("QUANDL:CFTC/"+code+"|0", "D", close)

long = is_inversed ? short_total : long_total
short = is_inversed ? long_total : short_total
net = long-short
willco = net / oi

length = input(24, title="Period (weeks)")

max = highest(willco, length)
min = lowest(willco, length)
index = 100 * (willco - min) / (max - min)

index_adopted = security("QUANDL:CFTC/"+code+"|5", "D", index)

plot(index_adopted, color = black, title="Index", style=line)
hline(80, color=blue, linestyle=dashed)
hline(20, color=blue, linestyle=dashed)

内容的提问来源于stack exchange,提问作者Dimon B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 02:12:04