You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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 -
I am running it with -
with stop_loss = 0, it throws following error -
What am I doing wrong?
Thank you.
Best regards
Beta Was this translation helpful? Give feedback.
All reactions