Overall Statistics
Total Trades
70
Average Win
0.51%
Average Loss
-0.36%
Compounding Annual Return
0.731%
Drawdown
3.600%
Expectancy
0.180
Net Profit
2.209%
Sharpe Ratio
0.343
Probabilistic Sharpe Ratio
12.976%
Loss Rate
51%
Win Rate
49%
Profit-Loss Ratio
1.43
Alpha
0.002
Beta
0.033
Annual Standard Deviation
0.022
Annual Variance
0
Information Ratio
-1.218
Tracking Error
0.126
Treynor Ratio
0.228
Total Fees
$137.43
Estimated Strategy Capacity
$110000000.00
class InsideDay(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 1, 1)  # Set Start Date
        self.SetEndDate(2020, 1, 1) # Set End Date
        self.SetCash(100000)  # Set Strategy Cash
        
        self.spy = self.AddEquity("SPY", Resolution.Hour).Symbol
        # self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
        
        # Schedule every day SPY is trading 10 minute after market open
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(self.spy, 10), Action(self.EveryDayOnMarketOpen))
        
        # Schedule every day SPY is trading 10 minutes before market close
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose(self.spy, 10), Action(self.BeforeMarketClose))
        
        
    def EveryDayOnMarketOpen(self):
        if self.Portfolio.Invested:
            return
        
        #Do nothing if outstanding order exist
        if self.Transactions.GetOpenOrders():
            return
        
        # History Request
        slices = self.History(self.spy, 3, Resolution.Daily)
        
        # high and low data for da -3 and -2
        Day3_High = slices["high"][-3]
        Day3_Low = slices["low"][-3]
        Day2_High = slices["high"][-2]
        Day2_Low = slices["low"][-2]
        # Close data of day -1
        Day1_Close = slices["close"][-1]
        
        # Submit Orders
        if Day3_High > Day2_High and Day3_Low < Day2_Low and Day1_Close > Day2_High:
            self.SetHoldings(self.spy, 1)
            self.Debug("Long SPY the: " + str(self.Time))
            self.Debug("High 3 days ago " + str(Day3_High))
            self.Debug("High 2 days ago at Inside day" + str(Day2_High))
        #+ " " + str(Day2_High) + " " + str(Day3_Low) + " " + str(Day2_Low))

    def BeforeMarketClose(self):
        if self.Portfolio.Invested:
            self.Liquidate(self.spy)