Overall Statistics
Total Trades
144
Average Win
0.35%
Average Loss
-0.14%
Compounding Annual Return
0.638%
Drawdown
1.700%
Expectancy
0.036
Net Profit
0.638%
Sharpe Ratio
0.204
Probabilistic Sharpe Ratio
17.091%
Loss Rate
70%
Win Rate
30%
Profit-Loss Ratio
2.40
Alpha
0.006
Beta
-0.002
Annual Standard Deviation
0.023
Annual Variance
0.001
Information Ratio
-1.412
Tracking Error
0.556
Treynor Ratio
-2.458
Total Fees
$29.68
Estimated Strategy Capacity
$3000.00
Lowest Capacity Asset
SANUSD E3
# --------------------------------------------------------------------------------
MA_1 = 120; MA_2 = 12; AlphA = float(MA_1/ MA_2); 
Beta = (AlphA * float(MA_1 - 1)) / float(MA_1 - AlphA); Gamma = float(Beta) + 1.0; 

RSIUP = 70; RSIDOWN = 30; 
a = RSIUP - RSIDOWN; b = RSIUP - a;
c = ((RSIUP + 10) - (RSIDOWN - 10 )) / 100; d = (RSIUP + 10) - c * 100;
# -------------------------------------------------------------------------------- 

class UpgradedApricotPony(QCAlgorithm):

    def Initialize(self):
        #Grunddaten für Indikator
        self.SetStartDate(2019, 1, 1)  # Set Start Date
        self.SetEndDate(2019, 12, 31) #Set End Date
        self.SetCash(10000)  # Set Strategy Cash
        
        #Allgemeine Einstellungen
        self.SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Margin) #Broker Modell
        self.SetTimeZone("Europe/Berlin") #durch die Zeitzone wird auch die 4h Anzeige in der Grafik um 2h verschoben
        self.positionSizeUSD = 100
        self.profit_percentage = 0.3
        self.loss_percentage = -0.1
        
        #Universe
        universe = ['BTCUSD', 'LTCUSD', 'ETHUSD', 'XMRUSD', 'XRPUSD', 'EOSUSD', 'SANUSD', 'XLMUSD']
        self.pairs = [Pair(self, ticker) for ticker in universe]
        self.SetWarmUp((MA_1 + MA_2 + 250), Resolution.Daily)
        
      
    def OnData(self, data):
        for pair in self.pairs:
            if self.IsWarmingUp:
                return
            
            #Aktuelle Datenpunkte
            
            symbol = pair.symbol
            price = self.Securities[symbol].Price
            
            #RSI over EMA
            rsi_1 = pair.rsi_1.Current.Value
            rsi_ema = pair.rsi_ema.Current.Value
            diff = rsi_ema - rsi_1
            
            
            #New Moving Average
            nma = pair.nma.Current.Value
            nma_ema = pair.nma_ema.Current.Value
            nma_hl = nma * Gamma - nma_ema * Beta
            
            #Bollinger Bands%
            bbr = (self.Securities[symbol].Price - pair.bb.LowerBand.Current.Value) / (pair.bb.UpperBand.Current.Value - pair.bb.LowerBand.Current.Value)
            bbnorm = (a * bbr + b)
            
            #Stochastic Smoothed
            sto = pair.sto.Current.Value
            sto_stochd = (c * pair.sto.StochK.Current.Value + d)
            
           
            #Strategie:
            
            #Prüfen ob man bereits in einen Coin investiert ist:
            if not self.Portfolio[symbol].Invested:
                #Long
                if self.Securities[symbol].Close > nma and pair.rsi_1.Current.Value > pair.rsi_ema.Current.Value and bbnorm > pair.rsi_1.Current.Value and pair.rsi_1.Current.Value > sto_stochd:
                    quantity = (self.Portfolio.Cash * 0.01)/ self.Securities[symbol].Price
                    self.MarketOrder(symbol, quantity)
                #Short    
                elif self.Securities[symbol].Close < nma and pair.rsi_1.Current.Value < pair.rsi_ema.Current.Value and bbnorm < pair.rsi_1.Current.Value and pair.rsi_1.Current.Value < sto_stochd:
                    quantity = (self.Portfolio.Cash * 0.01)/ self.Securities[symbol].Price
                    self.MarketOrder(symbol, -quantity)
                    return
                
            profit = self.Portfolio[symbol].UnrealizedProfitPercent   
            
            if self.Portfolio[symbol].Invested:
                if self.Portfolio[symbol].IsLong:
                    if profit > self.profit_percentage:
                        self.Liquidate(symbol, "Take Profit reached")
                        self.Log(str(self.Time) + " " + str(symbol) + " " + str(profit))
                    elif profit < self.loss_percentage:
                        self.Liquidate(symbol, "Stop Price reached")
                        self.Log(str(self.Time) + " " + str(symbol) + " " + str(profit))
                elif self.Portfolio[symbol].IsShort:
                    if profit > self.profit_percentage:
                        self.Liquidate(symbol, "Take Profit reached")
                        self.Log(str(self.Time) + " " + str(symbol) + " " + str(profit))
                    elif profit < self.loss_percentage:
                        self.Liquidate(symbol, "Stop Price reached")
                        self.Log(str(self.Time) + " " + str(symbol) + " " + str(profit)) 
                
             
    def OnOrderEvent(self, orderEvent):
        if orderEvent.FillQuantity == 0:
            return
        fetched = self.Transactions.GetOrderById(orderEvent.OrderId)
        
        #self.Log(f"{str(fetched.Type)} was filled") funktioniert nicht richtig
        self.Log(f" Symbol was: {str(orderEvent.Symbol)}")
        self.Log(f" Quantity was: {str(orderEvent.FillQuantity)}")        
            
            
            
 #Verschiedene Indikatoren werden angelgt           
        
class Pair:
    def __init__(self, algorithm, ticker):
        self.symbol = algorithm.AddCrypto(ticker, Resolution.Daily, Market.Bitfinex).Symbol
        
        #RSI over EMA
        self.rsi_1 = algorithm.RSI(self.symbol, 14)#, MovingAverageType.Simple, Resolution.Daily)
        self.rsi_ema = IndicatorExtensions.EMA(algorithm.RSI(self.symbol, 13), 13)
        
        #New Moving Average
        self.nma = IndicatorExtensions.Over(IndicatorExtensions.Plus(algorithm.EMA(self.symbol, MA_1, Resolution.Daily, Field.High), algorithm.EMA(self.symbol, MA_1, Resolution.Daily, Field.Low)), 2)
        self.nma_ema = IndicatorExtensions.Of(ExponentialMovingAverage(MA_2), self.nma)
        
        #Bollinger Bands%
        self.bb = algorithm.BB(self.symbol, 20, 2)
        
        #Stochastic Smoothed
        self.sto = algorithm.STO(self.symbol, 14, 5, 1)