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

如何在Pine Script绘图标题中显示实时浮点数值?

在Pine Script的plot标题中显示浮点数值的解决办法

嘿,这个问题我之前也踩过坑!Pine Script的plot()函数里title参数只认纯字符串,直接把浮点变量和字符串硬拼接肯定会报错,因为类型不匹配嘛。不过别担心,用内置的str.tostring()函数就能轻松搞定。

改好的可运行代码

//@version=5
indicator("Stop Loss Tracker", overlay=true)

var float adjustedStoploss = 3000.00
// 这里可以替换成你实际的止损计算逻辑,我加了个模拟数值变化的例子
adjustedStoploss := close > adjustedStoploss ? adjustedStoploss + 12.75 : adjustedStoploss - 8.2

// 关键一步:用str.tostring()把浮点数转成字符串再拼接标题
plot(adjustedStoploss, title="Stop Loss Value: " + str.tostring(adjustedStoploss), linewidth=3, style=plot.style_line, color=#28B463)

额外优化:自定义小数位数

如果你想让数值显示得更规整(比如固定保留两位小数),可以给str.tostring()加个格式参数,比如:

plot(adjustedStoploss, title="Stop Loss Value: " + str.tostring(adjustedStoploss, "#.##"), linewidth=3, style=plot.style_line, color=#28B463)

#.##这个格式会让数值始终显示两位小数,哪怕末尾是0也会保留,看起来更专业。

这样改完之后,你的止损线标题就会实时跟着adjustedStoploss的数值变化啦!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 22:57:42