backtesting.py icon indicating copy to clipboard operation
backtesting.py copied to clipboard

i want to set buy limit orders and sell limit orders at the same time , but the sell orders can only be used to reduce or close positions , do not open short position, how to fullfill?

Open xiaobaomao opened this issue 2 years ago • 1 comments

    if self.position.size >= self.initial_position:
        for i in greater_than_target:
            if i == greater_than_target[0]:
                self.sell(size=-self.initial_position, limit=i)
            else:
                self.sell(size=int(-self.initial_position*self.ratio), limit=i)
    elif 0 < self.position < self.initial_position:
        for i in greater_than_target:
            self.sell(size=int(-self.initial_position * self.ratio), limit=i)

only using the sell limit order to reduce or colse positions, do not open short positions, how to do ?

xiaobaomao avatar Aug 18 '23 11:08 xiaobaomao

I'm not quite sure I understand what you're trying to do.

Have you tried using Trade.close(portion=...) API to close existing trades?

kernc avatar Aug 24 '23 14:08 kernc