Overall Statistics
Total Trades
253
Average Win
0%
Average Loss
0%
Compounding Annual Return
21.309%
Drawdown
6.000%
Expectancy
0
Net Profit
9.978%
Sharpe Ratio
1.578
Probabilistic Sharpe Ratio
62.677%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.07
Beta
0.339
Annual Standard Deviation
0.14
Annual Variance
0.02
Information Ratio
-1.307
Tracking Error
0.172
Treynor Ratio
0.652
Total Fees
$253.00
from QuantConnect.Orders.Fills import *

class MooMocEquityFillModel(FillModel):
    def __init__(self, algorithm):
        self.algorithm = algorithm

    def MarketOnCloseFill(self, security, order):
        fill = super().MarketOnCloseFill(security, order)
        if fill.FillQuantity == 0:
            return fill
        else:
            # Note: Ignoring slippage
            self.algorithm.Debug(f"MarketOnCloseFill original FillPrice={fill.FillPrice} new FillPrice={security.Close}")
            fill.FillPrice = security.Close
            return fill

    def MarketOnOpenFill(self, security, order):
        fill = super().MarketOnOpenFill(security, order)
        if fill.FillQuantity == 0:
            return fill
        else:
            # Note: Ignoring slippage
            self.algorithm.Debug(f"MarketOnOpenFill original FillPrice={fill.FillPrice} new FillPrice={security.Open}")
            fill.FillPrice = security.Open
            return fill

class DynamicResistanceGearbox(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 6, 22)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        ticker = "BA"
        self.equity = self.AddEquity(ticker, Resolution.Minute)
        self.equity.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.equity.SetFillModel(MooMocEquityFillModel(self))

        self.Schedule.On(self.DateRules.EveryDay(ticker), self.TimeRules.BeforeMarketClose(ticker, 20), self.SubmitMarketOnCloseOrders) # MarketOnClose orders must be placed with at least a 16 minute buffer before market close.
        self.Schedule.On(self.DateRules.EveryDay(ticker), self.TimeRules.At(16, 30), self.SubmitMarketOnOpenOrders)

    def SubmitMarketOnCloseOrders(self):
        self.MarketOnCloseOrder(self.equity.Symbol, 1)

    def SubmitMarketOnOpenOrders(self):
        self.MarketOnOpenOrder(self.equity.Symbol, 1)

    def OnData(self, slice):
        pass