在策略上更好地处理多个条目



我写了一个策略,在不同的设置中使用相同的条目。多重移动平均线交叉策略。我用三条移动平均线:慢、中、快。当MA1穿过MA2时,输入一个位置。与MA3的MA2交叉相同。

这可以通过单独的strategy.entry方法非常容易地完成:

ma1Ma2CrossUp = ta.crossover(ma1, ma2)
ma1Ma2CrossDown = ta.crossunder(ma1, ma2)
if ma1Ma2CrossUp
strategy.entry("Long", strategy.long)
if ma1Ma2CrossDown
strategy.entry("Short", strategy.short)

显然,MA2和MA3是一样的。为了得到正确的结果,我发现我必须将金字塔设置为2。处理多个条目的正确方法是什么,还是我在文档中遗漏了什么?没有多少脚本以这种方式使用多个条目,尽管在我看来这是直截了当的。如果能得到一些反馈,那就太好了。

为什么不这样做(如下(,如果你希望每个趋势有多个条目,那么是的,金字塔应该大于1

CrossUp = ta.crossover(ma1, ma2) or ta.crossover(ma2, ma3)
CrossDown = ta.crossunder(ma1, ma2) or ta.crossunder(ma2, ma3)
if CrossUp
strategy.entry("Long", strategy.long)
if CrossDown
strategy.entry("Short", strategy.short)

最新更新