Handling multiple entries better in strategy

Viewed 17

I wrote a strategy that uses the same entry on different settings. A multiple moving average cross strategy. I use three moving averages: slow, medium, fast. When MA1 cross MA2, enter a position. Same for MA2 cross of MA3.

This can be done super easy with separate strategy.entry methods:

ma1Ma2CrossUp = ta.crossover(ma1, ma2)
ma1Ma2CrossDown = ta.crossunder(ma1, ma2)

if ma1Ma2CrossUp
    strategy.entry("Long", strategy.long)
if ma1Ma2CrossDown
    strategy.entry("Short", strategy.short)

Obviously it's the same for MA2 and MA3. To get correct looking results, I find that I have to set pyramiding to 2. Is the correct way of handling multiple entries, or am I missing something in the documentation? There aren't many script that use multiple entries in such a way, although it seems straight forward to me. Would be great to get some feedback.

1 Answers

Why not doing this (below) and if you want multiple entries per trend, then yes pyramiding should be greater than 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)
Related