kernc / backtesting.py

:mag_right: :chart_with_upwards_trend: :snake: :moneybag: Backtest trading strategies in Python.
https://kernc.github.io/backtesting.py/
GNU Affero General Public License v3.0
5.04k stars 987 forks source link

entry exit check condition problem #1110

Open Avalanchecoder opened 5 months ago

Avalanchecoder commented 5 months ago

Expected Behavior

when supertrend is greater than open and no position present it should take trade

Actual Behavior

random trade are being taken.

Steps to Reproduce

  1. Include attached strategy.
  2. run on data

class Supertrend(Strategy):
    def init(self):
        self.sup = self.I(Z.closefn,self.data.df.ST)
        self.ope = self.I(Z.closefn,self.data.Open)

    def next(self):
        if ((self.ope > self.sup)  and ((self.position.is_long) or (self.position.is_short)))  :
            self.position.close()
        elif ((self.sup > self.ope) and ((self.position.is_long!=True) or (self.position.is_short!=True)) ) :
            self.sell(size=50)

Additional info

I'm new to backtesting.py if i am mistaking anything let me know

image