Overall Statistics
Total Trades
50
Average Win
0.30%
Average Loss
-0.14%
Compounding Annual Return
-11.851%
Drawdown
20.900%
Expectancy
1.049
Net Profit
-4.886%
Sharpe Ratio
-0.296
Probabilistic Sharpe Ratio
16.151%
Loss Rate
36%
Win Rate
64%
Profit-Loss Ratio
2.22
Alpha
-0.04
Beta
0.267
Annual Standard Deviation
0.208
Annual Variance
0.043
Information Ratio
0.041
Tracking Error
0.521
Treynor Ratio
-0.231
Total Fees
$1517.45
Estimated Strategy Capacity
$610000.00
Lowest Capacity Asset
BTCUSD XJ
from System.Drawing import Color

class TestAlgorithm(QCAlgorithm):


    def Initialize(self):
        self.SetStartDate(2021,4,1)
        self.SetEndDate(2021,8,23)
        self.SetCash("BTC", 1)
        self.btc = self.AddCrypto("BTCUSD", Resolution.Hour, Market.GDAX).Symbol
        self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
        self.SetBenchmark("BTCUSD")
        self.avgPrice = 0
    
        self.entryTicket = None
        
        self.SetWarmUp(25)
        self.smafast = self.SMA("BTCUSD", 9, Resolution.Daily)
        self.smaslow = self.SMA("BTCUSD", 25, Resolution.Daily)
        self.rsi = self.RSI("BTCUSD", 25, Resolution.Hour)
        
    
        stockPlot = Chart("Trade Plot")
        stockPlot.AddSeries(Series('Buy', SeriesType.Scatter, '$',
                                Color.Green, ScatterMarkerSymbol.Triangle))
        stockPlot.AddSeries(Series('Buy 2', SeriesType.Scatter, '$',
                                Color.Black, ScatterMarkerSymbol.Triangle))  
        stockPlot.AddSeries(Series('Buy 3', SeriesType.Scatter, '$',
                                Color.Cyan, ScatterMarkerSymbol.Triangle))  
        stockPlot.AddSeries(Series('Sell', SeriesType.Scatter, '$',
                                Color.Red, ScatterMarkerSymbol.TriangleDown))
        stockPlot.AddSeries(Series('Liquidate Signal', SeriesType.Scatter, '$',
                                Color.Blue, ScatterMarkerSymbol.Diamond))
        stockPlot.AddSeries(Series('Liquidate Trend', SeriesType.Scatter, '$',
                                Color.Pink, ScatterMarkerSymbol.Diamond))
        stockPlot.AddSeries(Series('Price', SeriesType.Line, 0))
        stockPlot.AddSeries(Series('smafast', SeriesType.Line, 1))   
        stockPlot.AddSeries(Series('smaslow', SeriesType.Line, 1)) 
        stockPlot.AddSeries(Series('rsi', SeriesType.Line, 2)) 

        self.AddChart(stockPlot)
    
    def OnData(self, data):
        if self.IsWarmingUp: return
        price = self.Securities["BTCUSD"].Price
        tolerance = 0.00015
        
        self.Plot("Trade Plot", "Price", price)
        self.Plot("Trade Plot", "smafast", self.smafast.Current.Value)
        self.Plot("Trade Plot", "smaslow", self.smaslow.Current.Value)
        self.Plot("Trade Plot", "rsi", self.rsi.Current.Value)

        self.trendup = self.smafast.Current.Value > self.smaslow.Current.Value *(1 + tolerance)
        self.trenddown = self.smafast.Current.Value < self.smaslow.Current.Value
    
    
       #Long Signal
        if self.trendup == True and self.rsi.Current.Value < 25 and not self.Portfolio["BTCUSD"].IsLong:
                self.entryTicket = self.MarketOrder("BTCUSD", 0.1, False, "Long One")
                self.Debug("Market Order Fill Price: {0}".format(self.entryTicket.AverageFillPrice))
                self.Plot("Trade Plot", "Buy", price)
                #self.Log("BUY  >> {0}".format(self.Securities["BTCUSD"].Price))
        #averaging down               
        if self.trendup == True and self.rsi.Current.Value < 25 and self.Portfolio["BTCUSD"].IsLong and self.avgPrice>price: 
            self.entryTicket2 = self.MarketOrder("BTCUSD", 0.2, False, "Long Two")
        #Liquidate Signal        
        if self.Portfolio["BTCUSD"].IsLong and self.trendup == True and self.rsi.Current.Value > 60:
            
            self.Liquidate()
            self.Plot("Trade Plot", "Liquidate Signal", price)
                    
        #Liquidate Trend
        if self.Portfolio["BTCUSD"].IsLong and self.trendup == False:
                self.Liquidate()
                self.Plot("Trade Plot", "Liquidate Trend", price)
                
        #Short Signal
        ...

    def OnOrderEvent(self, orderEvent):
        
        if self.entryTicket is not None and orderEvent.Status == OrderStatus.Filled: 
            self.avgPrice = self.entryTicket.AverageFillPrice