Overall Statistics
Total Trades
116
Average Win
1.11%
Average Loss
-0.66%
Compounding Annual Return
15.459%
Drawdown
5.500%
Expectancy
0.387
Net Profit
15.414%
Sharpe Ratio
1.578
Probabilistic Sharpe Ratio
69.228%
Loss Rate
48%
Win Rate
52%
Profit-Loss Ratio
1.68
Alpha
-0.022
Beta
0.589
Annual Standard Deviation
0.085
Annual Variance
0.007
Information Ratio
-1.882
Tracking Error
0.07
Treynor Ratio
0.229
Total Fees
$0.00
class RSIAlgorithm(QCAlgorithm):


    def Initialize(self):
        self.SetStartDate(2019, 1, 1)  
        self.SetEndDate(2019, 12, 30)  
        self.SetCash(10000)           
        EMA_Period    = 100
        RSI_Period    = 14            
        self.RSI_OB   = 70                
        self.RSI_OS   = 30                
        #self.Allocate = 0.25              
        
        self.spx = self.AddCfd("SPX500USD", Resolution.Hour, Market.Oanda)
        self.SetBrokerageModel(BrokerageName.OandaBrokerage)


        self.ema_spy = self.EMA("SPX500USD", EMA_Period)
        self.PSAR_NAS = self.PSAR("SPX500USD")
        self.rsi_spy = self.RSI("SPX500USD", RSI_Period)
        self.Ichi = self.ICHIMOKU("SPX500USD", 9, 26, 26, 52, 26, 26, Resolution.Daily)
        self.Ichi_Tenkan = self.Ichi.Tenkan.Current.Value
        
        self.Schedule.On(self.DateRules.EveryDay("SPX500USD"), self.TimeRules.BeforeMarketClose("SPX500USD", 5), self.Rebalance)


        self.SetWarmUp(RSI_Period)
        self.SetWarmUp(EMA_Period)

    def Rebalance(self):
        
        if self.IsWarmingUp:
            return
        
        price = round(self.Securities["SPX500USD"].Close, 1)
        
        if not self.Portfolio.Invested:
            # if self.rsi_spy.Current.Value < self.RSI_OS and price > self.ema_spy.Current.Value:
            self.SetHoldings("SPX500USD", 1)

           
        elif self.Portfolio.Invested:
            if price < self.ema_spy.Current.Value:
                self.Liquidate("SPX500USD")