1
votes

I want to set up a trading strategy that uses three entry signals to go "fully long."

Ideally:

  • I want the first long to happen when the price closes above an EMA.
  • The second, heavier, long to happen when there is an EMA crossover.
  • And then the third which would double the position size will happen when the close is above the donchian channel.

I have named each entry a different ID thinking I could limit an entry to 1.

I tried pyramiding but it would keep entering the first trade over and over again if the price dipped below for a day and then came back up. It wouldn't hit my stop so it would just add a single contract to the position.

//Over EMA 2
lCOne = crossover(close,ematwo)

//EMA1 crossover EMA2
lCTwo = crossover(emaone, ematwo)

//Close above upper DC
lCThree = crossover(close,DChiHighs)

CloseOne = crossunder(close,DCloLows)
CloseTwo = crossunder(close,ematwo)

//if (lCOne)
strategy.risk.max_position_size(3)
strategy.entry("LONG ONE", strategy.long,1, when = lCOne)
strategy.entry("LONG TWO", strategy.long,2, when = lCTwo)
strategy.entry("LONG THREE", strategy.long,3, when = lCThree)

strategy.close("LONG ONE",when = CloseOne)
strategy.close("LONG TWO",when = CloseTwo)
strategy.close("LONG THREE",when = CloseTwo)

1

1 Answers

0
votes

I'm not sure if it's the best but I did find a solution.

strategy.entry("LONG ONE", strategy.long, 1 , when = lCOne and strategy.position_size < 1)
strategy.entry("LONG TWO", strategy.long, 1 , when = lCTwo and strategy.opentrades == 1)
strategy.entry("LONG THREE", strategy.long, 1 , when = lCThree)

Using strategy.position_size and strategy.opentrades

I could probably use strategy.opentrades for all three but I haven't played around too much. This satisfies me for now, hopefully it helps.