After stop-loss is executed stop algorithm for x amount of hours
I was looking around on how to implement a timer so that every time I get stopped out I want to stop the strategy for x hours and start it up again once x hours has passed.
What is a simple way to implement this?
Let's say I have something like this:
if not self.position: if buy_signal1: self.buy() if self.position: if sell_signal1: self.sell() if stop_signal: self.sell() if stop_signal: [insert timer code here?]
You can simply have a variable (self.no_trade_time) or something like that, place it at the beginning of next and if the time is before that time, no trades. Every time you stop, set the variable 4 hours out.
To clarify, you have a
returnif current time is less than self.no_trade_time.
@run-out Thank you!
So I did not get the full picture of what you are trying to explain.
This is what I got so far:
self.t1 = close + datetime.timedelta(hours=4)
Current close + 4hours stored in a variable
if pos == step4: # 4 if close <= buy4: self.stoploss = self.sell(price=stop, size=-pos, exectype=bt.Order.Stop) self.log('Close below buy step 4.. creating stoploss @ %.2f' % stop) print(pos) if close >= sell1: self.cancel(self.stoploss) self.log('Current price reached sell 1 cancelling stop... %.2f' % close) print(pos)
Where do I place my "timer" variable so that if the stoploss executes the algorithm initiates the variable and stops the algorithm for x hours ?
You can set up your variable in notify_order at the end. When the order has traded, set your variable to four hours out, then check that variable at the beginning of next.