class ContinuousFuture(QCAlgorithm):
    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        self.SetCash(1000000)
        self.SetStartDate(2022, 1, 1)
        self.SetEndDate(2023, 6, 1)

        self.continuous_contract = self.add_future(Futures.Energies.CrudeOilWTI,
                                                  data_normalization_mode = DataNormalizationMode.BackwardsRatio,
                                                  data_mapping_mode = DataMappingMode.OpenInterest,
                                                  contract_depth_offset = 0,
                                                  resolution=Resolution.DAILY)
        self.slow_sma = self.sma(self.continuous_contract.Symbol, 3, Resolution.DAILY)
        self.fast_sma = self.sma(self.continuous_contract.Symbol, 5, Resolution.DAILY)

    def on_data(self, slice):
        self.current_contract = self.securities[self.continuous_contract.mapped]
        self.log(f"{self.current_contract.close} {self.slow_sma.current.value} {self.fast_sma.current.value}")
        if self.current_contract is not None and self.current_contract.Symbol != self.continuous_contract.mapped:
            self.log(f"{time} - rolling position from {self.current_contract.symbol} to {self.continuous_contract.mapped}")
            current_position_size = self.current_contract.holdings.quantity
            self.liquidate(self.current_contract.Symbol)
            self.set_holdings(self.continuous_contract.mapped, current_position_size)
            self.current_contract = self.securities[self.continuous_contract.mapped]

 

Hi guys, I am new here. I am trying to compute the simple moving average for continuous futures. The code snippet above returns no errors when executed. But the values of the sma are not correct. Here is a snippet of the output logs from the code above

2022-03-24 20:00:00 :	111.245 97.26056115751287 95.7416011719743
2022-03-25 20:00:00 :	112.635 98.38043782245417 97.36818566816957
2022-03-28 20:00:00 :	103.47 95.2215129961522 96.0697104909493
2022-03-29 20:00:00 :	105.19 93.44425418503756 95.44316131269383
2022-03-30 20:00:00 :	107.46 91.94914611807695 94.24067556389711
2022-03-31 20:00:00 :	101.15 91.28303766022876 92.48319639257885
2022-04-01 20:00:00 :	99.485 89.61340335977081 90.18294063508381
2022-04-04 20:00:00 :	103.685 88.50516177706265 90.21086483244339
2022-04-05 20:00:00 :	101.31 88.55751964711186 89.55115566982342
2022-04-06 20:00:00 :	96.995 87.84487086033103 87.72037548043625
2022-04-07 20:00:00 :	97.145 85.94835245632652 87.01005371010206
2022-04-08 20:00:00 :	97.93 84.93610030204192 86.74477383518608
2022-04-11 00:00:00 :	0.0 84.93610030204192 86.74477383518608
2022-04-11 20:00:00 :	94.83 84.44099889812388 85.28187775307299
2022-04-12 20:00:00 :	100.515 85.55332380368861 85.20753620404811
2022-04-13 20:00:00 :	103.67 87.36801158187936 86.45865826811509
2022-04-14 20:00:00 :	105.975 90.64672283329647 88.10089997925495
2022-04-18 20:00:00 :	106.99 92.55492109281106 89.77882867850958
2022-04-19 20:00:00 :	102.405 92.18672357259844 91.10609307279982
2022-04-20 20:00:00 :	102.44 91.13473065770525 91.44974409166494

 

First column is the close price, second column is the slow sma (3), third column is the fast sma (5). If I compute the sma myself using the closing price as logged, I am unable to get the same sma values. Am I understanding the code wrongly? How do I solve this issue?