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

Pine Script能否通过input.symbol/input.timeframe切换TradingView当前图表?

关于Pine Script切换图表标的与时间框架的问题

Pine Script无法直接实现切换当前图表的标的或时间框架,这是由TradingView的平台架构和沙箱运行机制决定的:Pine Script的权限被限制在当前图表的上下文内,只能读取数据、绘制指标/策略,没有权限修改主图表的核心全局设置(包括切换标的、时间框架这类操作)。

不过你可以通过以下替代方案实现类似需求:

  • 跨标的/时间框架数据展示:使用request.security()函数获取你选择的标的和时间框架的数据,在当前图表上可视化这些内容。比如可以绘制目标标的的K线、收盘价,或者在子图中展示其指标。示例代码如下:

    //@version=5
    indicator("跨数据展示工具", overlay=false)
    
    // 用户输入选项
    target_symbol = input.symbol("BTC/USDT", "选择目标标的")
    target_timeframe = input.timeframe("D", "选择目标时间框架")
    
    // 请求目标数据
    target_close = request.security(target_symbol, target_timeframe, close)
    target_open = request.security(target_symbol, target_timeframe, open)
    target_high = request.security(target_symbol, target_timeframe, high)
    target_low = request.security(target_symbol, target_timeframe, low)
    
    // 绘制目标标的的K线数据
    plotcandle(target_open, target_high, target_low, target_close, title="目标标的K线", color=color.new(color.blue, 0))
    
  • 使用TradingView内置UI功能:如果需要直接切换图表,建议用平台自带的功能:右键图表选择「添加符号」打开新图表窗口,或者使用多面板布局同时展示多个标的/时间框架,也可以使用顶部菜单栏的「图表切换器」快速切换预设的图表配置。

内容的提问来源于stack exchange,提问作者Tom Vos

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 20:27:17