Overall Statistics
Total Trades
117
Average Win
1.66%
Average Loss
-0.70%
Compounding Annual Return
49.888%
Drawdown
34.400%
Expectancy
0.397
Net Profit
22.310%
Sharpe Ratio
1.36
Probabilistic Sharpe Ratio
50.578%
Loss Rate
58%
Win Rate
42%
Profit-Loss Ratio
2.36
Alpha
0.697
Beta
1.103
Annual Standard Deviation
0.541
Annual Variance
0.292
Information Ratio
3.064
Tracking Error
0.229
Treynor Ratio
0.667
Total Fees
$728.14
Estimated Strategy Capacity
$45000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X

class GeekyYellowGreenArmadillo(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2020, 6, 30)
        self.SetCash(100000) 
        
        equity = self.AddEquity("AAPL", Resolution.Hour)
        
        equity.SetDataNormalizationMode(DataNormalizationMode.Adjusted)
        
        self.symbol = equity.Symbol
        self.SetBenchmark(self.AddEquity("SPY").Symbol)
        
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
        
        self.period = timedelta(hours=1)
        self.nextEntryTime = self.Time
        self.state = False
        
        
    def OnData(self, data):
        if not self.symbol in data:
            return
        
        price = self.Securities[self.symbol].Price
        
        if not self.state and self.Time >= self.nextEntryTime:
            quantity = self.CalculateOrderQuantity(self.symbol, 1.)
            self.longOrder = self.LimitOrder(self.symbol, quantity, price)
            self.exitPrice = round(price * 1.03, 2)
            self.stopPrice = round(price * 0.99, 2)
            self.stopOrder = self.StopMarketOrder(self.symbol, quantity, self.stopPrice) #stop order
            self.state = True
               
        elif price > self.exitPrice:       #profit taker
            self.Liquidate()   #stop order cancelled
            
    
    def OnOrderEvent(self, orderEvent):
        if orderEvent.Status == OrderStatus.Filled: 
            
            if orderEvent.OrderId == self.longOrder.OrderId:
                self.Log("BUY " + self.symbol.Value + " @ " + str(orderEvent.FillPrice) + " STOP ORDER @ " + str(self.stopPrice) + " TARGET EXIT @ " + str(self.exitPrice) )
                
            elif orderEvent.OrderId == self.stopOrder.OrderId: #upon stop order
                self.state = False
                self.nextEntryTime = self.Time + self.period
                self.Transactions.CancelOpenOrders()
                self.Log("STOP ORDER FILLED @ " + str(orderEvent.FillPrice) + " NEXT ENTRY TIME " + str(self.nextEntryTime))
                
            else:
                self.state = False
                self.nextEntryTime = self.Time + self.period
                self.Transactions.CancelOpenOrders()
                self.Log("PROFIT " + self.symbol.Value + " @ " + str(orderEvent.FillPrice) + " STOP ORDER CANCELLED " + " NEXT ENTRY TIME " + str(self.nextEntryTime))