Overall Statistics
import numpy as np
import pandas as pd
import talib as tb

class UnfilledGap(QCAlgorithm):
    stopMarketTicket = None
    StopPrice = 0
    MarketTicket = None
    
    def Initialize(self):
        self.SetStartDate(2019, 1, 1)
        self.SetEndDate(2019, 8, 30)
        self.SetCash(100000)
        self.Keys = self.AddEquity("KEYS", Resolution.Daily)
        self.OneDayATR = self.ATR("KEYS", 1, MovingAverageType.Simple, Resolution.Daily)
        self.Window = RollingWindow[TradeBar](3)
        self.TwentyDayATR = self.ATR("KEYS", 20, MovingAverageType.Simple, Resolution.Daily)
        self.SetWarmup(20, Resolution.Daily)
    def TradeBarHandler(self, TradeBar):
        self.Window.Add(TradeBar); 
    def OnData(self, data):
        if not self.Window.IsReady:
            return
        if self.OneDayATR.IsReady and self.TwentyDayATR.IsReady:
            OneDayATR = self.OneDayATR.Current.Value
            TwentyDayATR = self.TwentyDayATR.Current.Value
                                                
            if not self.Portfolio.Invested and OneDayATR is not None and TwentyDayATR is not None and self.Window.IsReady:
                if OneDayATR > TwentyDayATR and self.Securities["KEYS"].Price > self.Window[0].High:
                    self.MarketOrder("KEYS", 100, True, '1st day')
                if OneDayATR > TwentyDayATR and self.Securities["KEYS"].Price > self.Window[1].High:
                    self.MarketOrder("KEYS", 100, True, '2nd day')
                if OneDayATR > TwentyDayATR and self.Securities["KEYS"].Price > self.Window[2].High:                
                    self.MarketOrder("KEYS", 100, True, '3rd day')
            self.Log("OneDayATR: {} TwentyDayATR: {}".format(str(OneDayATR),str(TwentyDayATR)))