Overall Statistics
Total Trades
42
Average Win
0.55%
Average Loss
-0.47%
Compounding Annual Return
30.276%
Drawdown
2.400%
Expectancy
0.229
Net Profit
2.272%
Sharpe Ratio
1.719
Probabilistic Sharpe Ratio
58.479%
Loss Rate
43%
Win Rate
57%
Profit-Loss Ratio
1.15
Alpha
0.118
Beta
-0.096
Annual Standard Deviation
0.08
Annual Variance
0.006
Information Ratio
2.063
Tracking Error
0.17
Treynor Ratio
-1.433
Total Fees
$77.70
Estimated Strategy Capacity
$230000000.00
Lowest Capacity Asset
ES 1S1
class BasicTemplateFuturesAlgorithm(QCAlgorithm):

   def Initialize(self):
       self.SetStartDate(2015, 1, 1)
       self.SetEndDate(2015,2,1)
       self.SetCash(100000)  
       self.crudeoilwti = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Minute)
       self.rsi = self.RSI(self.crudeoilwti.Symbol, 5)
       minuteConsolidator = TradeBarConsolidator(timedelta(minutes=5))
       self.SubscriptionManager.AddConsolidator(self.crudeoilwti.Symbol, minuteConsolidator)

       self.Schedule.On(self.DateRules.EveryDay(self.crudeoilwti.Symbol), self.TimeRules.At(15, 00), self.ClosePositions)
       
       
       self.SetWarmUp(timedelta(weeks=20))
       
       
       self.buyticket = None
       self.sellticket = None
       self.stoplossticket = None
       self.takeprofitticket = None

   def OnData(self,slice):
       if self.Time.hour >= 9 and self.Time.hour <= 14:
           self.Debug(f"Time is between 9h and 12h inclusive. Time is: {self.Time}")
       
           if not self.Portfolio.Invested:    
           
               
                   if self.rsi.Current.Value <= 10:
                       self.buyticket = self.MarketOrder(self.crudeoilwti.Symbol, 1)
                       
               
                   if self.rsi.Current.Value >= 90:
                       self.sellticket = self.MarketOrder(self.crudeoilwti.Symbol, -1)
                       
                   
   def OnOrderEvent(self, orderEvent):
       if orderEvent.Status != OrderStatus.Filled:
           return
         
       if self.buyticket is not None:
           if orderEvent.OrderId == self.buyticket.OrderId:
               price = orderEvent.FillPrice
               self.StopMarketOrder(self.crudeoilwti.Symbol, -1, 
                               orderEvent.FillPrice * .995)
               self.LimitOrder(self.crudeoilwti.Symbol, -1, 
                               orderEvent.FillPrice * 1.005)
               self.buyticket = None
           else:
               self.Transactions.CancelOpenOrders(orderEvent.Symbol)
               #self.buyticket = None
       if self.sellticket is not None:
           if orderEvent.OrderId == self.sellticket.OrderId:
               price = orderEvent.FillPrice
               self.StopMarketOrder(self.crudeoilwti.Symbol, 1, 
                           orderEvent.FillPrice * 1.005)
               self.LimitOrder(self.crudeoilwti.Symbol, 1, 
                           orderEvent.FillPrice * .995) 
               self.sellticket = None
           else:
               self.Transactions.CancelOpenOrders(orderEvent.Symbol)
               #self.sellticket = None
       
   def ClosePositions(self):
       self.Liquidate(self.crudeoilwti.Symbol)