Rostfrei
Rostfrei

Reputation: 484

On Stop Loss strategy.exit, Profit Target strategy.exit order is left on the table

I've tried probably every tweak to get around this problem.

I'm creating 'enter_long', 'pt_long' and 'exit_long' orders. I've set to exit 75% of the position if the Profit Target price is reached.

strategy.entry("enter_long", strategy.long, stop = 
strategy.exit("pt_long", qty_percent = pt_exit_amount_percent, limit = long_profit_target_price)
strategy.exit("exit_long", stop = long_exit_price)

Here is an example of the order

enter image description here

As you can see, Profit Target price is never hit, but exit_long does not close the whole position. 75% of the position is still left on the table. Why?

Thank you for your time and help.

Upvotes: 0

Views: 61

Answers (1)

Rostfrei
Rostfrei

Reputation: 484

I solved the issue using strategy.order and oca group

strategy.entry("enter_long", strategy.long, stop = long_entry_price)
pt_amount = strategy.default_entry_qty(long_entry_price) * pt_exit_amount_percent / 100
strategy.order("pt_long", strategy.short, oca_name = "bracket", oca_type = strategy.oca.reduce, qty = pt_amount, limit = long_profit_target_price)
strategy.exit("exit_long", oca_name = "bracket", stop = long_exit_price)

Issue I was encountering is described in the documentation

https://www.tradingview.com/pine-script-docs/en/v5/concepts/Strategies.html#strategy-exit

It’s important to note that orders produced by this command reserve a portion of the open market position to exit. strategy.exit() cannot place an order to exit a portion of the position already reserved for exit by another exit command.

Upvotes: 0

Related Questions