Open anugrah797 opened 10 months ago
I am having the same issue.
For 'sell' orders SL and TP should be reversed, as far as I'm aware. This should make your TP lower than LIMIT - as expected.
But even so I'm still getting this error unless i set SL and TP far enough from the last closing price: * 1.01:
If that's the case, I find 1% is much too harsh restriction in case of day trading for example. But I realize module is not made with daytrading in mind.
Expected Behavior I expect the backtesting strategy MyCandlesStrat to execute buy and sell orders with the calculated stop-loss (SL), take-profit (TP), and limit values without encountering a ValueError.
Actual Behavior When executing the backtesting strategy with the provided code, I encounter the following ValueError: Short orders require: TP (1890.425) < LIMIT (1886.10523) < SL (1890.455)
Steps to Reproduce 1.Import the required libraries and data. 2.initialize the backtesting strategy MyCandlesStrat as shown in the provided code. 3.Run the backtesting strategy by calling the next() method.
from backtesting import Strategy
class MyCandlesStrat(Strategy): def init(self): super().init() self.signal1 = self.I(SIGNAL) # You need to define SIGNAL or replace it with a concrete value
Initialize any additional variables or data you need here