松树脚本“strategy.position_size”被蜡烛延迟

时间:2021-02-26 09:40:17

标签: pine-script

函数--strategy.position_size-- 未更新到订单。 在此代码中,我将获得 position_size +1/-1,但在我下订单后更改蜡烛。 Offset=1 查看位置值。 有没有办法保持位置更新?

//@version=4
strategy("RSI Strategy", overlay=true, process_orders_on_close=true)

length = input( 3 )
overSold = input( 40 )
overBought = input( 60 )
price = close
vrsi = rsi(price, length)
co = crossover(vrsi, overSold)
cu = crossunder(vrsi, overBought)
if (not na(vrsi))
    if (co)
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
    if (cu)
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
        
        
plot(strategy.position_size, title="position", color=color.red, linewidth=2, style=plot.style_linebr, offset=1)

1 个答案:

答案 0 :(得分:0)

一种解决方案可能是您在 strategy() 函数中使用的参数。如果您将 process_orders_on_close 设置为 false,那么您的策略可能会给您所需的输出。然后我会从头寸大小的图中删除偏移量,否则将其设置为 0。

另一个考虑因素是价格变量在蜡烛收盘时获取价格,并根据输入到 rsi 函数的收盘价计算进场和离场。因此,策略脚本只会在蜡烛收盘时检测历史蜡烛价格行为内的进入和退出条件。由于这是触发交易信号的蜡烛,它是图表上标记为进场或退场的蜡烛。订单实际上是在蜡烛收盘时放置的,然后更改仓位大小以反映新开盘蜡烛的新仓位,您可能将其解释为一根柱线的延迟,但实际上并非如此。

具有根据实时数据的当前价格下订单的策略的实时蜡烛图被区别对待,并且需要其他考虑因素。

如果您只想将头寸大小图向后移动一根蜡烛,那么情节策略参数将为 offset = -1,但我相信当前蜡烛的图将是 NA,直到蜡烛关闭。