Overall Statistics
class BasicTemplateFrameworkAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2019, 6, 1)  # Set Start Date
        self.SetEndDate(2020, 6, 2)
        self.SetCash(100000)  # Set Strategy Cash

        self.AddEquity("SPY", Resolution.Hour, Market.USA)
        self.AddAlpha(CustomAlpha(self))

class CustomAlpha(AlphaModel):
    def __init__(self, algorithm):
        # define our daily macd(12,26) with a 9 day signal
        self.macd = algorithm.MACD("SPY", 12, 26, 9, MovingAverageType.Exponential, Resolution.Hour)
        #define our daily RSI with a 14 day period
        self.rsi = algorithm.RSI("SPY", 14, MovingAverageType.Simple, Resolution.Hour)
    def Update(self, algorithm, data):
        insights = []
        if "SPY" not in data.Keys:
            return []
        tolerance = 0.0025
        signalDeltaPercent = (self.macd.Current.Value - self.macd.Signal.Current.Value)/self.macd.Fast.Current.Value
        ## Selling conditions
        if (signalDeltaPercent < -tolerance and 
            self.rsi.Current.Value > 70):
            insights = [Insight(security, self.insightDuration, InsightType.Price, InsightDirection.Down, self.insightMagnitude, None) \
                        for security in algorithm.ActiveSecurities.Keys if security != "SPY"]
        ## Buying conditions
        if (signalDeltaPercent > tolerance and 
            self.rsi.Current.Value < 30):
            insights = [Insight(security, self.insightDuration, InsightType.Price, InsightDirection.Up, self.insightMagnitude, None) \
                        for security in algorithm.ActiveSecurities.Keys if security != "SPY"]
        return insights
        
    def OnSecuritiesChanged(self, algorithm, changes):
        pass