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

Pine Script添加25%/75%分位线报错及历史线显示需求求助

问题解决:Pine Script绘制历史25%/75%分位线的报错修复

报错原因

你遇到的Cannot call 'operator +' with argument 'expr1'='m'错误,是因为m = plot(...)这行代码里,m是plot类型的对象(Pine Script中plot()函数返回的是绘图句柄,不是具体价格数值),不能直接用它做算术运算(比如(day_low + m)/2),必须用series float类型的数值变量来计算分位线。

修正后的完整脚本

//@version=5
indicator("oldcyd Regular Session High Low Mid & Quartiles", overlay=true)
t = time("390", session.regular) // 390=60*6.5,也可替换为"0930-1600"指定时段

is_first = na(t[1]) and not na(t) or t[1] < t

day_high = float(na)
day_low = float(na)

if is_first and barstate.isnew
    day_high := high
    day_low := low
else
    day_high := day_high[1]
    day_low := day_low[1]

if high > day_high
    day_high := high
    
if low < day_low
    day_low := low

// 先定义各分位的数值变量(关键修正:用数值变量而非plot句柄计算)
day_mid = (day_low + day_high) / 2
day_25 = (day_low + day_mid) / 2  // 25%分位线
day_75 = (day_high + day_mid) / 2 // 75%分位线

// 绘制所有线条
plot(day_high, style=plot.style_circles, color=#ff0000, linewidth=1, title="Reg Session High")
plot(day_mid, style=plot.style_circles, color=#ffeb3b, linewidth=1, title="Reg Session Mid")
plot(day_low, style=plot.style_circles, color=#ff0000, linewidth=1, title="Reg Session Low")
plot(day_25, style=plot.style_circles, color=#b2b5be, linewidth=1, title="Reg Session 25%")
plot(day_75, style=plot.style_circles, color=#b2b5be, linewidth=1, title="Reg Session 75%")

关键修改点

  1. 分离数值计算与绘图操作:先把中位线、25%/75%分位线的数值单独计算并存储为day_mid、day_25、day_75这些series float变量,确保后续算术运算的是价格数值而非绘图对象。
  2. 修正分位线绘图逻辑:直接用计算好的数值变量调用plot(),避免了用plot句柄做运算的错误。
  3. 保留了原脚本显示历史分位线的逻辑,同时实现了你需要的25%/75%分位线绘制。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 16:35:34