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

Pine Script v4:如何将input.resolution类型输入的默认值设为“Same as chart”

如何在Pine Script v4中将input.resolution的默认值设为“Same as chart”

要让“Same as chart”成为input.resolution的默认选中选项,你需要将defval参数设置为空字符串""——这是Pine Script v4中该选项对应的实际值,而不是界面上显示的文本。

你之前尝试的"Same as chart"、0、"0"都无法生效:

  • "Same as chart"只是下拉菜单的显示文本,不是参数能识别的有效值;
  • 0或"0"也不属于Pine Script定义的合法分辨率标识符,所以会触发报错。

下面是可以正常运行的代码示例:

//@version=4
study("Default to Same as Chart", overlay=true)

// 空字符串对应"Same as chart"选项,作为默认值
chartResolution = input(defval="", type=input.resolution, title="Time Resolution")

// 可选:添加验证逻辑,显示当前选中的分辨率
var statusLabel = label.new(bar_index, high, "", color=color.orange, textcolor=color.white)
label.set_text(statusLabel, "当前选择的分辨率: " + (chartResolution == "" ? "Same as chart" : chartResolution))

当你运行这段代码时,下拉菜单会默认选中“Same as chart”,同时依然保留所有其他有效的时间周期选项供切换。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 16:07:42