from AlgorithmImports import *

class SwimmingLightBrownBuffalo(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2022, 11, 1)

self.SetEndDate(2022, 12, 9)

self.SetCash(1000)

self.spy = self.AddEquity("SPY", Resolution.Minute).Symbol

self.macd = self.MACD(self.spy, 55, 90, 15, Resolution.Minute)

closing_prices = self.History(self.spy, 1, Resolution.Minute)["close"]

self.SetWarmUp(1)

for time, price in closing_prices.loc[self.spy].items():

self.macd.Update(time, price)

def OnData(self, Data):

if not self.macd.IsReady:

return

if self.macd.IsReady:

self.fast = self.macd.Fast.Current.Value

self.slow = self.macd.Slow.Current.Value

self.signal = self.macd.Signal.Current.Value

self.histogram = self.macd.Histogram.Current.Value

self.current = self.macd.Current.Value

price = self.Securities[self.spy].Price

if self.fast > self.slow:

if not self.Portfolio[self.spy].IsLong:

self.SetHoldings(self.spy, 1)

elif self.fast < self.slow:

self.Liquidate()

#if not self.Portfolio[self.spy].IsShort:

#self.SetHoldings(self.spy, -1)

else:

pass