Overall Statistics
Total Trades
28
Average Win
193.38%
Average Loss
-4.79%
Compounding Annual Return
139.691%
Drawdown
42.700%
Expectancy
7.865
Net Profit
440.534%
Sharpe Ratio
1.571
Loss Rate
79%
Win Rate
21%
Profit-Loss Ratio
40.37
Alpha
0.807
Beta
-0.065
Annual Standard Deviation
0.509
Annual Variance
0.259
Information Ratio
1.34
Tracking Error
0.52
Treynor Ratio
-12.387
Total Fees
$341.86
# WarmCryptoCrossover v0.02 (Py) 

from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Data import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from datetime import datetime
import decimal as d
import numpy as np

class WarmupAlgorithm(QCAlgorithm):

    def Initialize(self):
        
        # define email address for buy/sell notifications
        # please change prior to Live deploy
        self.email_address = 'test@test.com'

        self.SetStartDate(2017,4,1)   #Set Start Date
        self.SetEndDate(2017,11,5)    #Set End Date
        self.SetCash(1000)           #Set Strategy Cash
        
        # define crypto we want to trade on
        # ETHUSD or LTCUSD or BTCUSD
        self.target_crypto = "ETHUSD" 

        # Set brokerage to GDAX for cryptos
        self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)

        # Set crypto and time resolution
        self.AddCrypto(self.target_crypto, Resolution.Hour)

        # Define windows in days for EMA
        # 168 hours in a week, 1440 minutes in a day
        fast_period = 16
        slow_period = (168 * 2)
        medium_period = ((slow_period - fast_period) / 2) + fast_period

        # Define a fast and slow exponential moving average
        self.fast = self.EMA(self.target_crypto, fast_period)
        self.medium = self.EMA(self.target_crypto, medium_period)
        self.slow = self.EMA(self.target_crypto, slow_period)
        
        # Define average direction
        self.adxr = self.ADXR(self.target_crypto, medium_period)
        
        # Request warmup data
        self.SetWarmup(slow_period)
        
        # Plot EMAs
        self.PlotIndicator(self.target_crypto,self.fast,self.medium,self.slow)
        
        self.first = True


    def OnData(self, data):
        if self.first and not self.IsWarmingUp:
            self.first = False
            self.Log("Fast: {0}".format(self.fast.Samples))
            self.Log("Medium: {0}".format(self.medium.Samples))
            self.Log("Slow: {0}".format(self.slow.Samples))
            self.Log("ADXR >> {0}".format(self.adxr.Samples))

        # Determine holdings (# of units held) and price of unit
        holdings = self.Portfolio[self.target_crypto].Quantity
        price = self.Securities[self.target_crypto].Price

        # define a small tolerance on our checks to avoid bouncing
        if holdings > 0:
            tolerance = 0.0001
        else:
            tolerance = 0.0001
            
        self.Log("ADXR >> {0}".format(self.adxr))
            
        # we only want to go long if we're currently short or flat
        if holdings <= 0:
            # if the fast is greater than the slow, we'll go long
            if self.fast.Current.Value > self.slow.Current.Value * d.Decimal(1 + tolerance):
                self.SetHoldings(self.target_crypto, 1)
                message = "BUY >> {0} at {1}/unit".format(self.target_crypto,price)
                self.Log(message)
                
                # Email notification of buy (only in Live environment)
                #self.Notify(self.email_address, 'QuantConnect Algo Buy', message)

        # we only want to liquidate if we're currently long
        # if the fast is less than the slow we'll liquidate our long
        if holdings > 0:
            if self.fast.Current.Value < self.slow.Current.Value * d.Decimal(1 - tolerance):
                self.SetHoldings(self.target_crypto, 0)
                message = "Sell >> {0} at {1}/unit".format(self.target_crypto,price)
                self.Log(message)
                
                # Email notification of sell (only in Live environment)
                #self.Notify(self.email_address, 'QuantConnect Algo Sell', message)