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

如何在Pinescript中让用户通过输入调整plotshape尺寸?

TradingView plotshape 自定义尺寸实现方案

你不需要创建新标签,直接将已转换好的shapeSizeOption变量传入plotshape的size参数即可完成需求,以下是修改后的完整代码:

// 尺寸选择输入框
shapeSizeInput = input.string("default", title="Label Size", options=["very small", "small", "default", "large", "very large"])

// 将用户选择转换为TradingView支持的size枚举值
shapeSizeOption = switch shapeSizeInput
    "very small" => size.tiny
    "small"      => size.small
    "default"    => size.normal
    "large"      => size.large
    "very large" => size.huge

// 应用自定义尺寸的plotshape信号
plotshape(x2_cross_long, title = "X2 Cross Long", style=shape.triangleup, location = location.belowbar, color=color.blue, size=shapeSizeOption)

扩展说明

如果需要为多个不同的plotshape信号分别设置独立的自定义尺寸,只需为每个信号单独创建输入变量和转换逻辑:

// 多头信号尺寸设置
longShapeSizeInput = input.string("default", title="Long Signal Size", options=["very small", "small", "default", "large", "very large"])
longShapeSize = switch longShapeSizeInput
    "very small" => size.tiny
    "small"      => size.small
    "default"    => size.normal
    "large"      => size.large
    "very large" => size.huge

// 空头信号尺寸设置
shortShapeSizeInput = input.string("default", title="Short Signal Size", options=["very small", "small", "default", "large", "very large"])
shortShapeSize = switch shortShapeSizeInput
    "very small" => size.tiny
    "small"      => size.small
    "default"    => size.normal
    "large"      => size.large
    "very large" => size.huge

// 多头信号(使用独立尺寸)
plotshape(x2_cross_long, title = "X2 Cross Long", style=shape.triangleup, location = location.belowbar, color=color.blue, size=longShapeSize)
// 空头信号(使用独立尺寸)
plotshape(x2_cross_short, title = "X2 Cross Short", style=shape.triangledown, location = location.abovebar, color=color.red, size=shortShapeSize)

这样用户就能通过指标设置面板,分别为不同信号选择想要的尺寸,同时不影响原有样式的自定义(用户仍可通过TradingView自带的样式设置修改信号样式)。

内容的提问来源于stack exchange,提问作者7X Investors

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 12:42:53