这是一个非常小的松树脚本,遵循趋势,但我面临着重新绘制和重新打印的问题。
//@version=2
strategy("PrabhuTrendStrategy", overlay=true)
tim=input('160')
out1 = security(tickerid, tim, open)
out2 = security(tickerid, tim, close)
plot(out1,color=red)
plot(out2,color=green)
longCondition = crossover(security(tickerid, tim, close),security(tickerid, tim, open))
if (longCondition)
strategy.entry("long", strategy.long)
shortCondition = crossunder(security(tickerid, tim, close),security(tickerid, tim, open))
if (shortCondition)
strategy.entry("short", strategy.short)
在
//@version=2
中,lookahead
参数设置为barmerge.lookahead_on
,这将导致重新绘制。
将您的代码升级到
v5
并使用以下函数来实现共享的非重画安全功能这里。
// Function to securely and simply call `security()` so that it never repaints and never looks ahead.
f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)