Adjusting Stop Loss and Take Profit price #1015
Replies: 2 comments 3 replies
-
"self.trades.sl= self.trades.entry_price * .9" Type of "self.trades" is tuple. You had better extract each trade infomation by using for loop. Example
|
Beta Was this translation helpful? Give feedback.
-
If you want to make a strategy that uses the entry price to determine the take profit and stop loss price, If "trade_on_close=False" is used with Class Backtest's parameters, the entry price is open price of next day.
|
Beta Was this translation helpful? Give feedback.
-
I am messing around and want to make a strategy that uses the entry price to determine the take profit and stop loss price. So far I can not figure out how to change these values and I can not set them when the buy or sell order is made since the Price technically doesn't exist at that point.
class DemaCross(Strategy):
fast = 10
slow = 30
def init(self):
self.DEMASlow = self.I(DEMA,self.data.Close.s,self.slow)
self.DEMAFast = self.I(DEMA,self.data.Close.s,self.fast)
def next(self):
if self.position.is_long:
self.trades.sl= self.trades.entry_price * .9
self.trades.tp = self.trades.entry_price * 1.1
if self.position.is_short:
self.trades.sl= self.trades.entry_price * 1.1
self.trades.tp = self.trades.entry_price * .9
if crossover(self.DEMASlow,self.DEMAFast):
self.buy(sl=None,tp=None)
elif crossover(self.DEMAFast,self.DEMASlow):
self.sell(sl=None,tp=None)
This is what I am trying to do instead. When the trade is executed, see if the trade is a long or short, then try and change the stop loss and take profit point. But this is not working, am I missing something simple?
Beta Was this translation helpful? Give feedback.
All reactions