Overall Statistics
Total Trades
90
Average Win
3.77%
Average Loss
-1.40%
Compounding Annual Return
-36.536%
Drawdown
27.400%
Expectancy
-0.343
Net Profit
-20.249%
Sharpe Ratio
-1.45
Probabilistic Sharpe Ratio
2.977%
Loss Rate
82%
Win Rate
18%
Profit-Loss Ratio
2.69
Alpha
-0.355
Beta
0.196
Annual Standard Deviation
0.24
Annual Variance
0.058
Information Ratio
-0.905
Tracking Error
0.423
Treynor Ratio
-1.778
Total Fees
$605.64
Estimated Strategy Capacity
$78000000.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
        self.exitPrice = 9999
        
        
    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:
            self.quantity = self.CalculateOrderQuantity(self.symbol, 1.)
            self.longOrder = self.LimitOrder(self.symbol, self.quantity, price)
            self.state = True
               
        elif self.state and 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.exitPrice = round(orderEvent.FillPrice * 1.03, 2)
                self.stopPrice = round(orderEvent.FillPrice * 0.99, 2)
                self.stopOrder = self.StopMarketOrder(self.symbol, -self.quantity, self.stopPrice) #stop order
                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.exitPrice = 9999
                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.exitPrice = 9999
                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))