Overall Statistics
Total Trades
1376
Average Win
2.04%
Average Loss
-1.34%
Compounding Annual Return
227.688%
Drawdown
40.800%
Expectancy
0.275
Net Profit
915.908%
Sharpe Ratio
3.319
Probabilistic Sharpe Ratio
95.022%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.52
Alpha
1.557
Beta
0.022
Annual Standard Deviation
0.47
Annual Variance
0.221
Information Ratio
2.662
Tracking Error
0.514
Treynor Ratio
70.983
Total Fees
$0.00
Estimated Strategy Capacity
$1400000.00
Lowest Capacity Asset
ETHUSD XJ
import datetime

class AlertAsparagusPig(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 12, 4)  # Set Start Date
        self.SetEndDate(2021, 11, 15)  # Set Start Date
        
        self.SetCash(100000)  # Set Strategy Cash
        self.SetWarmUp(10)
        #self.SetTimeZone("UTC")
        
        self.startHour = 15
        self.startHour1 = 0
        
        self.pMov = 1
        self.window = 8
        self.buy_down = True
        self.buy_up = True
        self.Resolution = Resolution.Hour
        
        self.symb = 'ETHUSD'
        self.s = self.AddCrypto(self.symb, self.Resolution).Symbol
        self.AddCrypto('BTCUSD', self.Resolution)
       
      #  self.symb = 'AAPL'
        #self.s = self.AddEquity(self.symb, self.Resolution).Symbol
       # self.AddEquity('SPY', self.Resolution)
        #self.AddEquity('AAPL', self.Resolution)
        #self.AddEquity('AA', self.Resolution)
        


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments:
                data: Slice object keyed by symbol containing the stock data
        '''
        #for b in data.Keys: 
        
        if self.symb in data.Keys: 
             self.Debug('------------------------------------------------------------------------------')
             self.Debug('OnData ' + str(data[self.symb].Time)+ ' UTC ' + str(self.UtcTime) + ' - '+ str(data[self.symb].Price))
        
            #  hist4 = self.History(self.s, 3, self.Resolution)
            #  hprice4 = hist4['close'].unstack(level= 0)
            #  self.Log('HISTORY')
            #  self.Log(hprice4.to_string())  
                    
            
             t = data[self.symb].Time.hour
             if self.startHour == t:
               
               start = data[self.symb].Time - datetime.timedelta(hours=8)
               end = data[self.symb].Time
               
               self.Log('Now self: ' + str(self.Time))
               self.Log('Now data: ' + str(end))
               self.Log('Delta date: ' + str(start))
               
            
               hist = self.History(self.s, self.window, self.Resolution)
        #       hist = self.History(self.s, start, end, self.Resolution) 
               
               #self.Log('HISTORY0')
               #self.Log(hist.close.to_string())  
             
        #       hist1 = self.History(self.s, 8, self.Resolution)
               
        #       self.Log('HISTORY1')
        #       self.Log(hist1.close.to_string())  
                     
               if hist.empty:
                   self.Log('HIST is EMPTY')
               else:   
                  # self.Log('HISTORY0')
                  # self.Log(hist.to_string())  
            
                   if (self.symb in hist.index.levels[0]) and (hist.loc[self.symb].shape[0] >= self.window):
                       hprice = hist['close'].unstack(level= 0)
                       self.Log('HISTORY')
                       self.Log(hprice.to_string())  
                       
                       hprice =hprice.iloc[0]
                       self.Log('Hist price: ' +str(hprice))  
                       
                       if data[self.symb].Price > hprice[0] * (1 + self.pMov/100):
                         if self.buy_up: 
                             self.SetHoldings(self.symb, 1)
                             self.current = self.Time
                             self.Log('BUY_up Price now: ' + str(data[self.symb].Price) + ' Price last 8: ' + str(hprice[0]))
                            
                       
        if self.startHour1 == t:
               
              hist = self.History(self.s, self.window, self.Resolution)
              if hist.empty:
                  self.Log('HIST is EMPTY')
              else:   
                  if (self.symb in hist.index.levels[0]) and (hist.loc[self.symb].shape[0] >= self.window):
                      hprice = hist['close'].unstack(level= 0)
                      self.Log(hprice.to_string())  
                      hprice =hprice.iloc[0]
                      self.Log('Hist price: ' +str(hprice))  
                      self.Debug( str(data[self.symb].Price) + ' < ' + str(hprice[0] * (1 + self.pMov/100)))
                       
                      if data[self.symb].Price < hprice[0] * (1 + self.pMov/100):
                          if self.buy_down:
                            self.SetHoldings(self.symb, 1) #, liquidateExistingHoldings=True)
                            self.current = self.Time
                            self.Log('BUY_down Price now: ' + str(data[self.symb].Price) + ' Price last 8: ' + str(hprice[0]))
              
                  else:
                      self.Log('HIST is not all data ' + str(hist.loc[self.symb].shape[0]))
                       
        holdings = self.Portfolio[self.symb].Quantity  
    
        if holdings > 0 and ((self.Time - self.current) / datetime.timedelta(hours=1) >= self.window):
             self.Liquidate()
             self.Log('SELL Price now: ' + str(data[self.symb].Price))
    
    def OnEndOfDay(self):  
       pass
       # mkt_price = self.History(self.s, 2, Resolution.Hour)['close'].unstack(level= 0).iloc[-1]
    #    self.mkt.append(mkt_price)
    #    mkt_perf = 100000 * self.mkt[-1] / self.mkt[0] 
    #    self.Plot('Strategy Equity', self.s, mkt_perf)        
        
    def OnEndOfTimeStep(self):
        self.Log('End hour')
        #if barssinceentry > n then begin exitlong;buyt=false;end;
        #if barssinceentry > n then exitshort;
            
            #self.Log(hprice[0])
            #self.Log(data[self.symb].Time)
            #self.Log(data[self.symb].Price)
            
        # if not self.Portfolio.Invested:
        #    self.SetHoldings("SPY", 1)