Hello, I was trying to write an algo using EMA crossover to long or short Bitcoin. I was trying to using 13 / 48 EMA crossover and supposedly there should be more than one cross as the time period I set was a year long. However, when I did the backtesting, there were only two orders: buy and sell. I was wondering how to edit my code so that it can keep trading? Thanks.

 

class MovingAverageCrossAlgorithm(QCAlgorithm):

    def Initialize(self):

        self.SetStartDate(2021, 4, 1)    #Set Start Date
        self.SetEndDate(2022, 3, 31)     #Set End Date
        self.SetCash("USDT", 100000)     #Set Strategy Cash
        
        self.SetBrokerageModel(BrokerageName.Binance, AccountType.Margin)
        self.AddCrypto("BTCUSDT", Resolution.Daily, Market.Binance)

        # create a 13 day exponential moving average
        self.fast = self.EMA("BTCUSDT", 13, Resolution.Daily)

        # create a 48 day exponential moving average
        self.slow = self.EMA("BTCUSDT", 48, Resolution.Daily)

        self.previous = None

    def OnData(self, data):
        # wait for our slow ema to fully initialize
        if not self.slow.IsReady:
            return

        holdings = self.Portfolio["BTCUSDT"].Quantity
            
        if holdings <= 0:
            # if the fast is greater than the slow, we'll go long
            if self.fast.Current.Value > self.slow.Current.Value:
                self.SetHoldings("BTCUSDT", 1)

        # we only want to liquidate if we're currently long
        # if the fast is less than the slow we'll liquidate our long
        if holdings > 0 and self.fast.Current.Value < self.slow.Current.Value:
            self.Liquidate("BTCUSDT")

        self.previous = self.Time