Pine script 相同的代码,v2和v3中的结果不同

Pine script 相同的代码,v2和v3中的结果不同,pine-script,Pine Script,我尝试将脚本从v2迁移到v3脚本。然而,事实证明,在v3中,相同的代码返回不同的值。这怎么可能?我做错了什么?您可以在下面找到此脚本的代码 这就是图表上的情况 ? 测试1-v2,绿色、灰色线条 测试2-v3,粉色,蓝色线条 提前感谢您的帮助!:) 这种差异是由于security()函数的lookahead参数在v2中的默认值为on,在v3中的默认值为off,因此需要在v3中将其显式设置为on //@version=3 study("Test3",overlay=true) long_time

我尝试将脚本从v2迁移到v3脚本。然而,事实证明,在v3中,相同的代码返回不同的值。这怎么可能?我做错了什么?您可以在下面找到此脚本的代码

这就是图表上的情况 ?

测试1-v2,绿色、灰色线条 测试2-v3,粉色,蓝色线条

提前感谢您的帮助!:)


这种差异是由于
security()
函数的
lookahead
参数在v2中的默认值为
on
,在v3中的默认值为
off
,因此需要在v3中将其显式设置为
on

//@version=3

study("Test3",overlay=true)

long_timeframe = input(title="Long timeframe", type=resolution, defval="180")
short_timeframe = input(title="Long timeframe", type=resolution, defval="60")

step_shift = input(0,"Step Shift")


ha_symbol = heikinashi(tickerid)
// These 2 lines yield same result as v2 version of the script.
long_ha_close = security(ha_symbol, long_timeframe, hlc3, lookahead=barmerge.lookahead_on)
short_ha_close = security(ha_symbol, short_timeframe, hlc3, lookahead=barmerge.lookahead_on)
// To avoid repainting, these 2 lines are preferable.
// long_ha_close = security(ha_symbol, long_timeframe, hlc3[1], lookahead=barmerge.lookahead_on)
// short_ha_close = security(ha_symbol, short_timeframe, hlc3[1], lookahead=barmerge.lookahead_on)


long_step = ema(long_ha_close[step_shift],1)
short_step = ema(short_ha_close[step_shift],1)

plot(long_step,title="LongStep",color=aqua,linewidth=2,style=line)
plot(short_step,title="ShortStep",color=fuchsia,linewidth=2,style=line)
//@version=3

study("Test3",overlay=true)

long_timeframe = input(title="Long timeframe", type=resolution, defval="180")
short_timeframe = input(title="Long timeframe", type=resolution, defval="60")

step_shift = input(0,"Step Shift")


ha_symbol = heikinashi(tickerid)
// These 2 lines yield same result as v2 version of the script.
long_ha_close = security(ha_symbol, long_timeframe, hlc3, lookahead=barmerge.lookahead_on)
short_ha_close = security(ha_symbol, short_timeframe, hlc3, lookahead=barmerge.lookahead_on)
// To avoid repainting, these 2 lines are preferable.
// long_ha_close = security(ha_symbol, long_timeframe, hlc3[1], lookahead=barmerge.lookahead_on)
// short_ha_close = security(ha_symbol, short_timeframe, hlc3[1], lookahead=barmerge.lookahead_on)


long_step = ema(long_ha_close[step_shift],1)
short_step = ema(short_ha_close[step_shift],1)

plot(long_step,title="LongStep",color=aqua,linewidth=2,style=line)
plot(short_step,title="ShortStep",color=fuchsia,linewidth=2,style=line)