I am trying to add a rolling window of data to connect my custom indicator to but I keep receiving the following error on the first line of my own code and cannot figure out where I've gone wrong initializing self.

Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ./cache/algorithm/main.pyc. AlgorithmPythonWrapper(): NameError : name 'self' is not defined
at in main.py:line 54
:: low = self.quoteBarWindow(\'Low\')
NameError : name 'self' is not defined Stack Trace: QuantConnect.Lean.Engine.Setup.AlgorithmSetupException: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ./cache/algorithm/main.pyc. AlgorithmPythonWrapper(): NameError : name 'self' is not defined
at in main.py:line 54
:: low = self.quoteBarWindow(\'Low\')
NameError : name 'self' is not defined
at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler.CreateAlgorithmInstance (QuantConnect.Packets.AlgorithmNodePacket algorithmNodePacket, System.String assemblyPath) [0x0009c] in :0
at QuantConnect.Lean.Engine.Engine.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Lean.Engine.AlgorithmManager manager, System.String assemblyPath, QuantConnect.Util.WorkerThread workerThread) [0x000f8] in :0 

Here is my code up to that point:

from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from statistics import stdev, mean
import matplotlib
# ___library_import_statements___
import pandas as pd
# for pandas_datareader, otherwise it might have issues, sometimes there is some version mismatch
pd.core.common.is_list_like = pd.api.types.is_list_like
import numpy as np
import matplotlib.pyplot as plt
import datetime
import time
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Common")
AddReference("QuantConnect.Jupyter")
AddReference("QuantConnect.Indicators")
from System import *
from QuantConnect import *
from QuantConnect.Data.Custom import *
from QuantConnect.Data.Market import TradeBar, QuoteBar
from QuantConnect.Jupyter import *
from QuantConnect.Indicators import *
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import pandas as pd
matplotlib


class RollingWindowAlgorithm(QCAlgorithm):

def Initialize(self):


self.SetStartDate(2000, 10, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddEquity("CENX", Resolution.Daily)
self.SetExecution(ImmediateExecutionModel())
self.quoteBarWindow = RollingWindow[QuoteBar](270)


def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''

# Add SPY TradeBar in rollling window
self.window.Add(data["SPY"])

# Wait for windows to be ready.
if not (self.window.IsReady and self.smaWin.IsReady): return

currBar = self.window[0] # Current bar had index zero.
pastBar = self.window[1] # Past bar has index one.
self.Log("Price: {0} -> {1} ... {2} -> {3}".format(pastBar.Time, pastBar.Close, currBar.Time, currBar.Close))

low = self.quoteBarWindow('Low')
# use numerical integer index instead of date
df = self.quoteBarWindow('Time')

Any ideas? Thanks!

Author