Overall Statistics
import numpy as np

class BasicTemplateAlgorithm(QCAlgorithm):
    '''Basic template algorithm simply initializes the date range and cash'''

    def Initialize(self):
        self.SetStartDate(2007,1, 1)  #Set Start Date
        self.SetEndDate(2018,9,30)    #Set End Date
        self.SetCash(10000)           #Set Strategy Cash
        self.spy = self.AddEquity("SPY", Resolution.Daily)
        self.AddEquity("UPRO", Resolution.Daily)
        self.rsi = self.RSI("SPY", 2)
        self.sma200 = self.SMA("SPY", 200)
        self.sma20 = self.SMA("SPY", 20) ## will use this later on

    def OnData(self, data):
        if not self.sma200.IsReady: return
        if data.ContainsKey("SPY") == False: return
#var buy1 = RSI<24 && adx>20;
#var buy2 = RSI<10 && adx>30;
#if _spyhigh>Avg200 then buy1 else buy2;

        if data[self.spy.Symbol].High > self.sma200.Current.Value and self.rsi.Current.Value <24 and not self.Portfolio["UPRO"].Invested:
            self.Debug("UPRO buy")
            self.MarketOrder("UPRO", 5000)
            self.Debug("Market order was placed")
#var sell1 = _spy>_Avg20 && RSI>85;
#var sell2 = _spy>Avg20 && RSI>80;
#if _spyhigh<SMA200 then sell1 else sell2;        
        if data[self.spy.Symbol].High > self.sma200.Current.Value and (self.rsi.Current.Value > 85 or self.rsi.Current.Value < 80): 
            self.Debug("UPRO sell")