3

This is a simple strategy based on EMA cross. The issue comes when trying to exit a % at a certain level and letting the remaining position to be filled by the trailing stop.

Let's set a target of 3%. When the price hits the target the strategy should close 50% of the order and letting the Trailing Stop continue until it is hit and then exit the order.

Issue: if the price doesn't reach the target, exit 100% at my trailing stop

The code:

if(strategy.position_size > 0)
  strategy.exit("XL", qty_percent=50, limit=longExitPrice)
  strategy.exit("EL", stop=longStopPrice)
if(strategy.position_size < 0)
  strategy.exit("XS", qty_percent=50, limit=shortExitPrice)
  strategy.exit("ES", stop=shortStopPrice)

When the target is reached, it works without any issue. One order (XL) at the target and another one (EL) at the trailing stop. When the price doesn't reach the specific target, the strategy exit only 50% of the order (EL). When there isn't any percentage set. Strategy screenshot

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
dgtomu
  • 31
  • 1
  • 2
  • 1
    I'm having the exact same issue and no matter what I try I can't seem to get it to work. Did you find any solution? – ragamufin Feb 05 '21 at 16:40

1 Answers1

0

Perhaps the 50% carries over from previous use. Try adding qty_percent=100% to the EL as well.