backtesting.py
backtesting.py copied to clipboard
Error creating an order with size==0
It raise an error:
File "... /backtesting/backtesting.py", line 718, in new_order
raise ValueError(
ValueError: Short orders require: TP (0.04695176) < LIMIT (0.04686714259153687) < SL (0.046782525183073735)
This an error raises, as if a bad price for order has was set and it "is_short". But actually, the problem occurs when size == 0.
The bad assign is there: is_long = size > 0 else it "is_short".
There need to add above:
assert size > 0, "Size should be > 0." Or if size == 0: print("Size should be > 0.") return.
is_long = size > 0
...
if is_long:
if not (sl or -np.inf) < (limit or stop or adjusted_price) < (tp or np.inf):
raise ValueError(
"Long orders require: "
f"SL ({sl}) < LIMIT ({limit or stop or adjusted_price}) < TP ({tp})")
else:
if not (tp or -np.inf) < (limit or stop or adjusted_price) < (sl or np.inf):
raise ValueError(
"Short orders require: "
f"TP ({tp}) < LIMIT ({limit or stop or adjusted_price}) < SL ({sl})")
Thanks.
Additional info
- Backtesting version: 0.3.3
Hi @kernc, Can I work on this? Adding extra check to find out if the size == 0 and raise proper error?
Hi @kernc, can you please let me know if this issue has been resolved or if it's still open? Thanks