Overall Statistics
Total Trades
234
Average Win
3.80%
Average Loss
-1.31%
Compounding Annual Return
-43.178%
Drawdown
47.900%
Expectancy
-0.165
Net Profit
-24.517%
Sharpe Ratio
-0.95
Probabilistic Sharpe Ratio
6.135%
Loss Rate
79%
Win Rate
21%
Profit-Loss Ratio
2.91
Alpha
-0.406
Beta
0.62
Annual Standard Deviation
0.405
Annual Variance
0.164
Information Ratio
-1.229
Tracking Error
0.341
Treynor Ratio
-0.62
Total Fees
$1232.32
Estimated Strategy Capacity
$63000000.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:
                updateSettings = UpdateOrderFields()
                updateSettings.StopPrice = round(orderEvent.FillPrice * 0.99, 2)
                self.stopOrder.Update(updateSettings)
                self.exitPrice = round(orderEvent.FillPrice * 1.03, 2)
                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))
        
        elif orderEvent.Status == OrderStatus.Canceled:
            self.Transactions.CancelOpenOrders()
            self.state = False