2019-10-02: The community is currently in read-only mode
Help with coding a position reversal strategy
SkullTech last edited by SkullTech
This is the strategy I'm using
class AMAStrat(bt.Strategy): def __init__(self): fast_ama = bt.indicators.AdaptiveMovingAverage(fast=2, slow=5) slow_ama = bt.indicators.AdaptiveMovingAverage(fast=4, slow=10) self.co = bt.indicators.CrossOver(fast_ama, slow_ama) def next(self): dayend = self.data.datetime.time(0) > time(15, 15) if dayend and self.position: self.close() if self.co > 0: self.close() self.order = self.buy() elif self.co < 0: self.close() self.order = self.sell()
It is a position reversal strategy, so it's supposed to always stay in the market, and close all positions at the end of the day.
And this is the result upon running the strategy on the data
As you can see from the cash // value graph at the top, it was not in the market all the time, it exited after some time. Specifically, at the buy signal, it only closed the previous position, but did not buy any more and create a new position.
Any clue why this might be happening?
closeblindly when entering the market.