backtesting.py
backtesting.py copied to clipboard
How to add a dollar amount for take profit and stop loss
I am having trouble adding a dollar amount to take profit and stop loss. I've seen examples of having percentages, but can I add a dollar amount to these two variables? For example, if my take profit was $1,000 and stop loss was $350 how can I add that to my code? Would it go in self.buy() or self.close_position(). Also, how can I add it to a short position? Would the values be negative?
its easier to set a percentage based stop/target:
def next(self): super().next()
price = self.data.Close[-1]
if self.signal == 1:
if not self.position:
self.buy(size=0.99, tp=1.06*price, sl=0.98*price)
maybe divide your capital by the dollar profit target (x100) to get a percentage, then add in as above?