Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
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)))