需要帮助将 Pinescript v2 转换为版本 5
Need help to convert Pinescript v2 to version 5
我通过图表艺术找到了这段代码。我正在制定自己的策略,我会喜欢我的这个功能。它为我的进入信号提供了更好的确认。我正在尝试自己学习 pinescript,但我认为如果我学习 pinescript v2 和 v5 会花费很多时间和精力,所以我请求帮助将其转换为 V5,然后我可以继续改进代码。我真的很感激任何帮助。提前谢谢大家。
//@version=2
threshold = input(title="Price Difference Threshold", type=float, defval=0, step=0.001)
getDiff() =>
yesterday=security(tickerid, 'D', close[1])
today=security(tickerid, 'D', close)
delta=today-yesterday
percentage=delta/yesterday
closeDiff = getDiff()
buying = closeDiff > threshold ? true : closeDiff < -threshold ? false : buying[1]
hline(0, title="zero line")
bgcolor(buying ? #3399FF : #FFFFFF , transp=1)
plot(closeDiff, color=silver, style=area, transp=75)
plot(closeDiff, color=aqua, title="prediction")
longCondition = buying
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = buying != true
if (shortCondition)
strategy.entry("Short", strategy.short)
直接 v2 -> v5 转换如下所示:
//@version=5
strategy("")
threshold = input.float(title="Price Difference Threshold", defval=0, step=0.001)
getDiff() =>
yesterday=request.security(syminfo.tickerid, 'D', close[1], lookahead=barmerge.lookahead_on)
today=request.security(syminfo.tickerid, 'D', close, lookahead=barmerge.lookahead_on)
delta=today-yesterday
percentage=delta/yesterday
closeDiff = getDiff()
bool buying = na
buying := closeDiff > threshold ? true : closeDiff < -threshold ? false : buying[1]
hline(0, title="zero line")
bgcolor(buying ? #3399FF : #FFFFFF , transp=1)
plot(closeDiff, color=color.new(color.silver, 75), style=plot.style_area)
plot(closeDiff, color=color.aqua, title="prediction")
longCondition = buying
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = buying != true
if (shortCondition)
strategy.entry("Short", strategy.short)
请注意,脚本使用 security()
函数从 "D"
时间范围请求数据,这允许它展望未来并在可能执行之前获取柱线值在 real-time 个图表 (more info here) 上以此类推。这在新脚本中是不受欢迎的。为避免这种情况,应使用 barmerge.loohakead_off
(在 v3 - v5 中默认打开)。在下面的脚本中,我更改了它,所以结果会与原始脚本不同,但这是最好的,因为原始脚本操作了它不应该访问的数据:
//@version=5
strategy("")
threshold = input.float(title="Price Difference Threshold", defval=0, step=0.001)
getDiff() =>
[today, yesterday] = request.security(syminfo.tickerid, 'D', [close, close[1]], lookahead=barmerge.lookahead_off)
delta = today - yesterday
percentage = delta / yesterday
closeDiff = getDiff()
bool buying = na
buying := closeDiff > threshold ? true : closeDiff < -threshold ? false : buying[1]
hline(0, title="zero line")
bgcolor(buying ? color.new(#3399FF, 1) : color.new(#FFFFFF, 1))
plot(closeDiff, color=color.new(color.silver, 75), style=plot.style_area)
plot(closeDiff, color=color.aqua, title="prediction")
longCondition = buying
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = buying != true
if (shortCondition)
strategy.entry("Short", strategy.short)
我通过图表艺术找到了这段代码。我正在制定自己的策略,我会喜欢我的这个功能。它为我的进入信号提供了更好的确认。我正在尝试自己学习 pinescript,但我认为如果我学习 pinescript v2 和 v5 会花费很多时间和精力,所以我请求帮助将其转换为 V5,然后我可以继续改进代码。我真的很感激任何帮助。提前谢谢大家。
//@version=2
threshold = input(title="Price Difference Threshold", type=float, defval=0, step=0.001)
getDiff() =>
yesterday=security(tickerid, 'D', close[1])
today=security(tickerid, 'D', close)
delta=today-yesterday
percentage=delta/yesterday
closeDiff = getDiff()
buying = closeDiff > threshold ? true : closeDiff < -threshold ? false : buying[1]
hline(0, title="zero line")
bgcolor(buying ? #3399FF : #FFFFFF , transp=1)
plot(closeDiff, color=silver, style=area, transp=75)
plot(closeDiff, color=aqua, title="prediction")
longCondition = buying
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = buying != true
if (shortCondition)
strategy.entry("Short", strategy.short)
直接 v2 -> v5 转换如下所示:
//@version=5
strategy("")
threshold = input.float(title="Price Difference Threshold", defval=0, step=0.001)
getDiff() =>
yesterday=request.security(syminfo.tickerid, 'D', close[1], lookahead=barmerge.lookahead_on)
today=request.security(syminfo.tickerid, 'D', close, lookahead=barmerge.lookahead_on)
delta=today-yesterday
percentage=delta/yesterday
closeDiff = getDiff()
bool buying = na
buying := closeDiff > threshold ? true : closeDiff < -threshold ? false : buying[1]
hline(0, title="zero line")
bgcolor(buying ? #3399FF : #FFFFFF , transp=1)
plot(closeDiff, color=color.new(color.silver, 75), style=plot.style_area)
plot(closeDiff, color=color.aqua, title="prediction")
longCondition = buying
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = buying != true
if (shortCondition)
strategy.entry("Short", strategy.short)
请注意,脚本使用 security()
函数从 "D"
时间范围请求数据,这允许它展望未来并在可能执行之前获取柱线值在 real-time 个图表 (more info here) 上以此类推。这在新脚本中是不受欢迎的。为避免这种情况,应使用 barmerge.loohakead_off
(在 v3 - v5 中默认打开)。在下面的脚本中,我更改了它,所以结果会与原始脚本不同,但这是最好的,因为原始脚本操作了它不应该访问的数据:
//@version=5
strategy("")
threshold = input.float(title="Price Difference Threshold", defval=0, step=0.001)
getDiff() =>
[today, yesterday] = request.security(syminfo.tickerid, 'D', [close, close[1]], lookahead=barmerge.lookahead_off)
delta = today - yesterday
percentage = delta / yesterday
closeDiff = getDiff()
bool buying = na
buying := closeDiff > threshold ? true : closeDiff < -threshold ? false : buying[1]
hline(0, title="zero line")
bgcolor(buying ? color.new(#3399FF, 1) : color.new(#FFFFFF, 1))
plot(closeDiff, color=color.new(color.silver, 75), style=plot.style_area)
plot(closeDiff, color=color.aqua, title="prediction")
longCondition = buying
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = buying != true
if (shortCondition)
strategy.entry("Short", strategy.short)