Overall Statistics
Total Trades
18
Average Win
2.83%
Average Loss
-1.83%
Compounding Annual Return
-48.062%
Drawdown
13.300%
Expectancy
-0.434
Net Profit
-7.095%
Sharpe Ratio
-1.56
Probabilistic Sharpe Ratio
18.621%
Loss Rate
78%
Win Rate
22%
Profit-Loss Ratio
1.55
Alpha
-0.45
Beta
-0.17
Annual Standard Deviation
0.296
Annual Variance
0.088
Information Ratio
-1.522
Tracking Error
0.351
Treynor Ratio
2.719
Total Fees
$0.00
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)