Overall Statistics
class UncoupledModulatedFlange(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2016, 1, 1)  # Set Start Date
        self.SetEndDate(2020, 7, 30)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.AddEquity("SPY", Resolution.Minute)
        self.flag=0
        self.Securities['SPY'].FeeModel = ConstantFeeModel(0)
        self.amount = 10000


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments:
                data: Slice object keyed by symbol containing the stock data
        '''
        if data.ContainsKey('SPY'):
            if data['SPY'] is not None:
                close = data['SPY'].Close
                open = data['SPY'].Open
                if data['SPY'].Close > data['SPY'].Open and self.flag!=1:
                    if self.Portfolio['SPY'].IsShort:
                        self.Liquidate()
                    quantity = int(self.amount/data['SPY'].Close)
                    self.MarketOrder('SPY',quantity)
                    self.flag=1
                elif data['SPY'].Close < data['SPY'].Open and self.flag!=-1:
                    if self.Portfolio['SPY'].IsLong:
                        self.Liquidate()
                    quantity = int(self.amount/data['SPY'].Close)
                    self.MarketOrder('SPY',quantity*-1)
                    self.flag=-1