Overall Statistics
Total Trades
1088
Average Win
2.35%
Average Loss
-0.95%
Compounding Annual Return
78.936%
Drawdown
33.100%
Expectancy
0.256
Net Profit
225.847%
Sharpe Ratio
1.417
Probabilistic Sharpe Ratio
55.673%
Loss Rate
64%
Win Rate
36%
Profit-Loss Ratio
2.47
Alpha
0.569
Beta
0.433
Annual Standard Deviation
0.476
Annual Variance
0.227
Information Ratio
0.898
Tracking Error
0.479
Treynor Ratio
1.557
Total Fees
$0.00
Estimated Strategy Capacity
$220000.00
Lowest Capacity Asset
EOSUSD XJ
# Cryptos RSI and SMA with Trailing Stop Loss

# https://www.quantconnect.com/project/11371503

# ------------------------------------------------------------------------------------------
CRYPTOS = ['BTCUSD', 'ETHUSD', 'EOSUSD', 'LTCUSD']; MA = 50; RSI = 14;  SL = 0.10;
# ------------------------------------------------------------------------------------------

class CryptosRSIandSMA(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2020, 4, 1)
        self.SetEndDate(2022, 4, 11)
        self.SetCash(100000)
        self.cryptos = [self.AddCrypto(ticker, Resolution.Minute).Symbol for ticker in CRYPTOS]
        self.sma = {}; self.rsi = {}; self.highestPrice={};
        for sec in self.cryptos:
            self.sma[sec] = self.SMA(sec, MA, Resolution.Daily)
            self.rsi[sec] = self.RSI(sec, RSI, MovingAverageType.Simple, Resolution.Daily)
            self.highestPrice[sec] = 0
        self.SetWarmUp(max(MA, RSI), Resolution.Daily)


    def OnData(self, data):
        if self.IsWarmingUp: return
        for sec in self.cryptos:
            if not self.sma[sec].IsReady or not self.rsi[sec].IsReady: continue
            rsi = self.rsi[sec].Current.Value
            price =  self.Securities[sec].Price
            sma = self.sma[sec].Current.Value
            quantity = self.CalculateOrderQuantity(sec, 0.24)
            
            if not self.Portfolio[sec].Invested:
                if rsi > 50 and price >= sma*1.005:
                    self.MarketOrder(sec, quantity)
                    self.highestPrice[sec] = price
                    

            elif self.Portfolio[sec].Invested:
                if self.highestPrice[sec] > 0:
                    if price > self.highestPrice[sec]:
                        self.highestPrice[sec] = price
                        
                    if price < sma*0.995:
                        self.Liquidate(sec, "price below sma")
                        self.highestPrice[sec] = 0
                    
                    elif rsi < 50:
                        self.Liquidate(sec, "rsi below 50")
                        self.highestPrice[sec] = 0

                    elif price < self.highestPrice[sec]*(1 - SL):
                        self.Liquidate(sec, "Stop Loss")
                        self.highestPrice[sec] = 0
                    
                    
    def OnEndOfDay(self, symbol):   
        if self.IsWarmingUp: return
        for sec in self.cryptos:
            if not self.sma[sec].IsReady or not self.rsi[sec].IsReady: continue
            self.Plot("RSI", sec, self.rsi[sec].Current.Value)
            self.Plot("RSI", 'threshold', 50)