0

I want to do a partial exit of my position (50%) on a condition that does NOT imply SL nor TP. How can I do it?

As I don't want to close my position, I don't use strategy.close but strategy.exit instead:

if condition 
   strategy.exit(id="long partial closing", from_entry="long entry", comment="partial close long", qty_percent=50)

Problem is, strategy.exit requires to specify a TP or SL parameter. How can I go with only my condition?

1 Answers1

0

Since you want to do it with a condition, you should use strategy.close().

strategy.close(id, comment, qty, qty_percent, alert_message, immediately) → void

It has two arguments which you can use to close your position partially:

qty (series int/float): An optional parameter. Number of contracts/shares/lots/units to exit a trade with. The default value is 'NaN'.
qty_percent (series int/float): Defines the percentage (0-100) of the position to close. Its priority is lower than that of the 'qty' parameter. Optional. The default is 100.

vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • Problem is, even if I specify a quantity parameter it will still close my position, which I don't want. I want it to stay open with its remaining 50%. I don't want to have to close it at 50% then open a new one, for fees reasons. – OmeletteAuFromage Dec 12 '22 at 14:14
  • It should not close your position. There must be something wrong with your code. – vitruvius Dec 12 '22 at 14:30
  • Increase your order size via the settings -> properties tab and try again. – vitruvius Dec 12 '22 at 14:31
  • If you cannot manage to make it work, please share a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – vitruvius Dec 12 '22 at 14:31
  • Indeed, problem is my position size was 1, I increased it and can now use strategy.close. Thanks! – OmeletteAuFromage Dec 12 '22 at 14:58
  • No worries. For some tickers you must have at least one contract. That's why partial closing might fail on them. – vitruvius Dec 12 '22 at 15:02