from AlgorithmImports import *

class SwimmingLightBrownBuffalo(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2022, 12, 1)

self.SetEndDate(2022, 12, 14)

self.SetCash(1000)

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

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

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

#self.SetWarmUp(300, Resolution.Minute)

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.short:

#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

if self.macd.IsReady:

self.Plot("Benchmark", "fast", self.fast)

self.Plot("Benchmark", "slow", self.slow)

202366_1671062663.jpg