-
-
Couldn't load subscription status.
- Fork 1.3k
-
Hello,
I can't seem to figure out why I get a ValueError when stop loss = 0. I do not intend to use limit orders.
I have following next() in my strategy -
def next(self):
super().init()
price = self.data.Close
# Long Exit
if (self.position) and crossover(self.lema, self.lrs):
# Close any existing long trades, and sell the asset
self.position.close()
# Long Entry
elif (not self.position) and crossover(self.lrs, self.lema) and (price >= self.ema):
self.buy(sl=(1-self.stop_loss/100)*price)
I am running it with -
bt = Backtest(df, myStrategy, cash=10000, commission=0, trade_on_close=True, exclusive_orders=False, hedging=False)
with stop_loss = 0, it throws following error -
File ~\AppData\Roaming\Python\Python311\site-packages\backtesting\backtesting.py:713, in _Broker.new_order(self, size, limit, stop, sl, tp, trade)
711 if is_long:
712 if not (sl or -np.inf) < (limit or stop or adjusted_price) < (tp or np.inf):
--> 713 raise ValueError(
714 "Long orders require: "
715 f"SL ({sl}) < LIMIT ({limit or stop or adjusted_price}) < TP ({tp})")
716 else:
717 if not (tp or -np.inf) < (limit or stop or adjusted_price) < (sl or np.inf):
ValueError: Long orders require: SL (0.4557679295539856) < LIMIT (0.4557679295539856) < TP (None)
What am I doing wrong?
Thank you.
Best regards
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment