Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-0.499
Tracking Error
0.17
Treynor Ratio
0
Total Fees
$0.00
class RSIAlgorithm(QCAlgorithm):


    def Initialize(self):
        self.SetStartDate(2007, 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.Daily, 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.SetWarmUp(RSI_Period)
        self.SetWarmUp(EMA_Period)

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

           
        elif self.Portfolio.Invested:
            if self.Securities["SPX500USD"].Close < self.ema_spy.Current.Value:
                self.Liquidate("SPX500USD")
                #self.SetHoldings("BND", 1)