Pine Script代码报错求助:斐波那契乘数输入行问题修复
修复Pine Script v5斐波那契支撑阻力指标的错误
错误原因及修复方案
1. 输入项语法错误(你标注的行)
在Pine Script v5中已废弃input()函数加type参数的写法,需直接使用对应类型的输入函数。原代码用了v4语法,导致报错。
错误代码:
multiplier = input(1, title='Fibonacci Multiplier', type=input.float, minval=0.1, step=0.1)
修复后代码:
multiplier = input.float(1.0, title='Fibonacci Multiplier', minval=0.1, step=0.1)
2. 极值函数参数错误
原代码中ta.highest(high, barmerge.gaps_off, period)写法完全错误:
ta.highest()的第二个参数应为整数类型的周期长度,不能传分辨率字符串(如"4H")barmerge.gaps_off是security类函数的参数,不能传递给ta.highest()
完整修复代码
//@version=5 indicator("Main Support and Resistance Levels with Fibonacci", overlay=true) // 设置输入选项 period = input.resolution("4H", title='Chart Period') multiplier = input.float(1.0, title='Fibonacci Multiplier', minval=0.1, step=0.1) getSupportResistanceLevels() => // 获取当前周期下20周期内的高低极值(可根据需求调整周期长度) swHigh = ta.highest(high, 20) swLow = ta.lowest(low, 20) // 计算高低点间距与斐波那契扩展幅度 distance = swHigh - swLow extension = distance * multiplier // 计算支撑和阻力位 resistance = swHigh + extension support = swLow - extension [support, resistance] // 获取指定周期下的支撑阻力位,设置K线合并规则 [support, resistance] = request.security(syminfo.tickerid, period, getSupportResistanceLevels(), gaps=barmerge.gaps_off) // 绘制支撑阻力位 plot(resistance, color=color.red, style=plot.style_circles, linewidth=1) plot(support, color=color.green, style=plot.style_circles, linewidth=1)
额外说明
- 替换原
security函数为v5推荐的request.security写法 - 新增
gaps=barmerge.gaps_off参数,实现你原本需要的K线合并规则 - 调整
period输入项为v5规范的input.resolution()函数
内容的提问来源于stack exchange,提问作者Channel ABC
相关产品推荐
相关产品推荐

