Apologies if this is a basic concepts question I am reasonably new to this,, but I am trying to take one the quantapedia base strategy which is buy at close and sell at open and tweak it to only fire if some conditions are made. This is part as it's an easy one to start with to learn how to get data features into OnData to be used as filters.

Where I am struggling, is onData how I can pull in the previous Close, High, Low as the following error message pops up during running the backtest:

 Runtime Error: AttributeError : 'NoneType' object has no attribute 'Close'
  at OnData
    prevcloseprice = data[self.spy].Close
===
   at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 30

Also I would like to retrieve the price of SPY at last bar (hourly) before the close, and do some comparison logic on it, and say if price < high of previous day for instance, buy at close if not skip this day. So it would be great to understand how to get the data related to the last bar before close data points for a given security, so they can be used in if statements.

Thanks