Overall Statistics
class BounceBack(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2015, 1, 1)
        self.SetEndDate(2015, 2, 10)
        self.SetCash(100000)
        
        # Volatile ETFs
        tickers = 'UVXY,XIV,NUGT,DUST,JNUG,JDUST,LABU,LABD,GUSH,DRIP,TVIX,GASL,GASX,DWTI,UWTI,DGAZ,UGAZ,UBIO,ZBIO,BRZU,RUSS,SCO,UCO,RUSL,ERY,ERX,BIOL,SVXY,VXX,SILJ,BIB,BIS,VIXY,SOXL,VIIX,SOXS,BZQ,USLV,SLVP,DSLV,GDXJ,GLDX'
        
        resolution = Resolution.Hour
        security = self.AddEquity('TQQQ', resolution)
        security.FeeModel = ConstantFeeModel(0)
        self.sym = security.Symbol
        self.ma = self.SMA(self.sym, 50, resolution)
        self.over = None
        self.SetWarmUp(50)
        
    def OnData(self, data):
        if self.IsWarmingUp or not self.ma.IsReady:
            return
        
        if self.sym not in data or data[self.sym] is None:
            return
        
        price = data[self.sym].Price
        ma = self.ma.Current.Value
        if price > 0:
            over = price > ma
            if self.over is not None and self.over != over:
                self.Liquidate()
                limit = 0.03
                stop = 0.01
                quant = self.CalculateOrderQuantity(self.sym, 1)
                if over:
                    self.MarketOrder(self.sym, quant)
                    self.LimitOrder(self.sym, -quant, price * (1 + limit))
                    self.StopMarketOrder(self.sym, -quant, price * (1 - stop))
                # elif not over:
                #     stop = price * 1.02
                #     self.MarketOrder(self.sym, -quant)
                #     self.LimitOrder(self.sym, quant, price * (1 - limit))
                #     self.StopMarketOrder(self.sym, quant, price * (1 + stop))
                    
            self.over = over
                
        self.Plot('Chart', 'MA', ma)
        self.Plot('Chart', 'Price', price)