missing hourly quote of spy and stockplot data is empty

 

error log : Backtest Handled Error: Data Missing on: 2023-12-15 00:00:00

Received backtest 'Dancing Magenta Tapir' request

44

 

|

8:43:53

:

Initializing algorithm...

45

 

|

8:43:53

:

Launching analysis for 3b827b694df04a38d47b781dd14a2f01 with LEAN Engine v2.5.0.0.16267

46

 

|

8:43:53

:

Backtest Handled Error: Data Missing on: 2023-12-15 00:00:00

47

 

|

8:43:53

:

Algorithm '3b827b694df04a38d47b781dd14a2f01' completed

48

 

|

8:43:53

:

Algorithm Id:(3b827b694df04a38d47b781dd14a2f01) completed in 0.58 seconds at 0k data points per second. Processing total of 289 data points.

49

 

|

8:43:53

:

Backtest deployed in 9.798 seconds

 

 

source code:

from AlgorithmImports import *

# endregion


 

ticker="SPY"

class MACDTrendAlgorithm(QCAlgorithm):


 

   

    def Initialize(self):

        #self.ticker="SPY"

        #self.SetStartDate(2022, 1, 1)  

        self.SetStartDate(2023, 12, 1)

        self.SetEndDate(2024, 1, 1)    

        self.SetCash(1000)         # Find more symbols here: http://quantconnect.com/data

        self.symbol=self.AddEquity(ticker, Resolution.Hour)


 

        # define our daily macd(12,26) with a 9 day signal

        self.__macd = self.MACD(ticker, 12, 26, 9, MovingAverageType.Exponential, Resolution.Hour)

        self.__previous = datetime.min

        self.PlotIndicator("MACD", True, self.__macd, self.__macd.Signal)

        self.PlotIndicator(ticker, self.__macd.Fast, self.__macd.Slow)


 

        self.crossupTOLERANCE = 0

        self.crossDownTOLERANCE= 0


 

        #self.crossupTOLERANCE = 0.002

        #self.crossDownTOLERANCE= 0.002

        stockPlot = Chart('Trade Plot')


 

        from System.Drawing import Color

        stockPlot.AddSeries(Series('Price', SeriesType.Line, '$', Color.Green))

        stockPlot.AddSeries(Series('Buy', SeriesType.Scatter, '$', Color.Red, ScatterMarkerSymbol.Triangle))

        stockPlot.AddSeries(Series('Sell', SeriesType.Scatter, '$', Color.Blue, ScatterMarkerSymbol.TriangleDown))

        self.AddChart(stockPlot)


 

    def OnData(self, data):

        if not self.__macd.IsReady: return


 

        if data[self.symbol.Symbol]:

            self.Plot("TEST", "CLOSE", data[self.symbol.Symbol].Close)

            tolerance = 0.0025

            holdings = self.Portfolio[ticker].Quantity

            price=data[ticker].Close

            signalDeltaPercent = (self.__macd.Current.Value - self.__macd.Signal.Current.Value)/self.__macd.Fast.Current.Value


 

            if holdings <= 0 and signalDeltaPercent > self.crossupTOLERANCE:  # 0.01%

                self.Log(f"Buying SPY | Holding: {holdings} | Delta%:{signalDeltaPercent} | UP_Tolerance{self.crossupTOLERANCE}")

                self.SetHoldings(ticker, 1.0)

                self.Plot(ticker, "Buy", price)


 

            elif holdings >= 0 and signalDeltaPercent < -self.crossDownTOLERANCE:

                self.Log(f"Selling SPY | Holding: {holdings} | Delta%:{signalDeltaPercent} | DOWN_Tolerance{self.crossDownTOLERANCE}")

                self.Liquidate(ticker)

                #self.SetHoldings("SPY", -1.0)

                self.Plot(ticker, "Sell", price)

            else:

                self.Log(f"Nothing | Holding: {holdings} | Delta%:{signalDeltaPercent} | UP_Tolerance{self.crossupTOLERANCE} | DOWN_Tolerance{self.crossDownTOLERANCE}")

       

        else:

            self.Error(f"Data Missing on: {self.Time}")