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

Pine Script V2转V5报错求助:input函数参数适配问题

解决Pine Script V2转V5的input()函数报错问题

错误原因

报错核心问题:Pine Script V5中input()函数不再支持maxval、minval和step参数,必须使用类型专属的input.int()(整数类型)或input.float()(浮点数类型)来定义带范围的输入值。

关键修改点

  • 把原V2中带范围的数值输入,替换为V5的input.int()或input.float()
  • 将security()函数的tickerid参数替换为V5规范的syminfo.tickerid
  • 适配V5命名空间:atr()→ta.atr()、max()→math.max()、min()→math.min()、cross()→ta.cross()
  • 新增//@version=5版本声明

转换后的完整V5代码

//@version=5
strategy("Tradingview", overlay=true, default_qty_value=100)

res = input.timeframe(title="Main SuperTrend Time Frame", defval="720")
Factor = input.float(2, title="Factor", minval=1, maxval=100)
Pd = input.int(10, title="PD", minval=1, maxval=100)

tp = input.int(500, title="Take Profit")
sl = input.int(400, title="Stop Loss")

Up = hl2 - (Factor * ta.atr(Pd))
Dn = hl2 + (Factor * ta.atr(Pd))
MUp = request.security(syminfo.tickerid, res, hl2 - (Factor * ta.atr(Pd)))
MDn = request.security(syminfo.tickerid, res, hl2 + (Factor * ta.atr(Pd)))

Mclose = request.security(syminfo.tickerid, res, close)

TrendUp = close[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up
TrendDown = close[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn

MTrendUp = Mclose[1] > MTrendUp[1] ? math.max(MUp, MTrendUp[1]) : MUp
MTrendDown = Mclose[1] < MTrendDown[1] ? math.min(MDn, MTrendDown[1]) : MDn

Trend = close > TrendDown[1] ? 1 : close < TrendUp[1] ? -1 : nz(Trend[1], 1)
Tsl = Trend == 1 ? TrendUp : TrendDown

MTrend = Mclose > MTrendDown[1] ? 1 : Mclose < MTrendUp[1] ? -1 : nz(MTrend[1], 1)
MTsl = MTrend == 1 ? MTrendUp : MTrendDown

linecolor = Trend == 1 ? color.green : color.red
plot(Tsl, color=linecolor, style=plot.style_line, linewidth=4, title="SuperTrend")

Mlinecolor = MTrend == 1 ? color.black : color.red
plot(MTsl, color=Mlinecolor, style=plot.style_line, linewidth=4, title="Main SuperTrend")

plotshape(ta.cross(close, Tsl) and close > Tsl, title="Up Arrow", shape=shape.triangleup, location=location.belowbar, color=color.black, size=size.small)
plotshape(ta.cross(Tsl, close) and close < Tsl, title="Down Arrow", shape=shape.triangledown, location=location.abovebar, color=color.black, size=size.small)

up = Trend == 1 and Trend[1] == -1 and MTrend == 1 
down = Trend == -1 and Trend[1] == 1 and MTrend == -1 

golong = Trend == 1 and Trend[1] == -1 and MTrend == 1 
goshort = Trend == -1 and Trend[1] == 1 and MTrend == -1

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 20:31:06