Overall Statistics
Total Trades
38
Average Win
0.12%
Average Loss
-0.14%
Compounding Annual Return
-5.393%
Drawdown
0.900%
Expectancy
-0.135
Net Profit
-0.373%
Sharpe Ratio
-2.53
Probabilistic Sharpe Ratio
13.110%
Loss Rate
53%
Win Rate
47%
Profit-Loss Ratio
0.83
Alpha
0
Beta
0
Annual Standard Deviation
0.021
Annual Variance
0
Information Ratio
-2.53
Tracking Error
0.021
Treynor Ratio
0
Total Fees
$49.98
Estimated Strategy Capacity
$100000000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
class BuyOnOpenTakeProfit(QCAlgorithm):

    longTradeSignalActive = False
    tradeLock = False
    
    def __init__(self):
        
        self.ticker = "QQQ"
        self.SetStartDate(2022, 3, 1)
        self.SetEndDate(2022, 3, 25)
        self.SetCash(100000)
        self.takeProfit = 0.005
    
    def Initialize(self):

        self.symbol = self.AddEquity(self.ticker, Resolution.Second).Symbol
        self.Consolidate(self.symbol, timedelta(minutes=1), lambda x: self.window.Add(x))
        #barConsolidator = TradeBarConsolidator(60)
        #barConsolidator.DataConsolidated += self.BarHandler
        #self.SubscriptionManager.AddConsolidator(self.symbol, barConsolidator)
        
        self.window = RollingWindow[TradeBar](2)
        
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
        
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(23, 59), self.DailyReset)

        
    def OnData(self, data):
        
        if data[self.symbol] is None:
            return
            
        self.window.Add(data[self.symbol])

        if not self.window.IsReady:
            return
        
        barB = self.window[0]
        barA = self.window[1]
        
        if (barA.Close - barA.Open >0)          \
            and (barB.Close - barB.Open >0)     \
            and (barA.High < barB.High)         \
            and (barA.Low < barB.Low)           \
            and (barB.Open >= barA.Close):
                    self.longTradeSignalActive = True
        
        if not self.Portfolio.Invested: 
            if self.longTradeSignalActive is True and self.tradeLock is False:
                self.SetHoldings(self.symbol, .9)
                self.limitQuantity = self.Portfolio[self.symbol].Quantity
                self.limitPrice = self.Portfolio[self.symbol].Price * (1 + self.takeProfit)
                self.LimitOrder(self.symbol, -self.limitQuantity, self.limitPrice)
                self.tradeLock = True
                    
        elif self.Portfolio[self.symbol].IsLong:
            if self.Securities[self.symbol].AskPrice < barB.Low:
                self.Transactions.CancelOpenOrders()
                self.LimitOrder(self.symbol, -self.limitQuantity, self.Securities[self.symbol].AskPrice)
        
    
    #def BarHandler(self, sender, bar):
    #    return
    
    def DailyReset(self):
        self.longTradeSignalActive = False
        self.tradeLock = False