Overall Statistics
Total Trades
486
Average Win
0.05%
Average Loss
0%
Compounding Annual Return
287.661%
Drawdown
36.100%
Expectancy
0
Net Profit
2425.479%
Sharpe Ratio
1.963
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
-0.001
Beta
0.997
Annual Standard Deviation
0.555
Annual Variance
0.308
Information Ratio
-1.834
Tracking Error
0.002
Treynor Ratio
1.093
Total Fees
$327.39
# https://www.quantconnect.com/forum/discussion/2914/help-with-simple-crypto-strategies

from datetime import datetime

import numpy as np
import decimal as d
from datetime import timedelta


class DualThrustAlgorithm(QCAlgorithm):

    def Initialize(self):
        
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        
        self.SetStartDate(2015,07,01)
        self.SetEndDate(2017,11,15)
        self.SetCash(100000)

        equity           = self.AddCrypto("BTCUSD", Resolution.Daily)
        self.SetBrokerageModel(BrokerageName.GDAX)
        self.SetBenchmark(equity.Symbol)
        self.syls        = equity.Symbol
        
        # schedule an event to fire every trading day for a security 
        # the time rule here tells it to fire when market open 
        self.syl         = "BTCUSD"
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.Every(timedelta(minutes=10)),Action(self.SetSignal))
        self.selltrig    = None
        self.buytrig     = None
        self.currentopen = None
        
        sPlot = Chart('Strategy Equity')
        sPlot.AddSeries(Series('Dual Thrust',  SeriesType.Line, 2)) #Only for axis title override
        sPlot.AddSeries(Series('BTCUSD',  SeriesType.Line, 2))
        sPlot.AddSeries(Series('Buy Trigger',  SeriesType.Line, 2))
        sPlot.AddSeries(Series('Sell Trigger',  SeriesType.Line, 2))
        self.AddChart(sPlot)

    
    def SetSignal(self):
        
        """
        history = self.History(["BTCUSD",], 4, Resolution.Daily)
        self.Log(str(history))
                             close    high     low    open       volume
        symbol time                                                   
        BTCUSD 2016-12-29  982.17  983.46  923.95  926.03  9792.346831
               2016-12-30  970.72  988.88  950.50  982.28  8997.859016
               2016-12-31  960.81  970.51  930.30  970.51  7945.763020
               2017-01-01  973.26  973.37  949.00  961.52  3837.287886
        """
        history = self.History(["BTCUSD",], 4, Resolution.Daily).loc["BTCUSD"]
        
        k1         = 0.5
        k2         = 0.5
        self.high  = history.high.values.astype(np.float32)
        self.low   = history.low.values.astype(np.float32)
        self.close = history.close.values.astype(np.float32)
        
        # Pull the open price on each trading day
        self.currentopen = float(self.Portfolio[self.syl].Price)
        
        HH, HC, LC, LL = max(self.high), max(self.close), min(self.close), min(self.low)
        if HH - LC >= HC - LL:
            signalrange = HH - LC
        else:
            signalrange = HC - LL
        
        self.selltrig = self.currentopen - k1 * signalrange
        self.buytrig  = self.currentopen + k2 * signalrange    
    
    def OnData(self,data):
        
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
        
        holdings = self.Portfolio[self.syl].Quantity
        
        if self.Portfolio[self.syl].Price >= self.selltrig:
            if holdings >= 0:
                self.SetHoldings(self.syl, 1.0)
            else:
                self.Liquidate(self.syl)
                self.SetHoldings(self.syl, 1.0)
                
        elif self.Portfolio[self.syl].Price < self.selltrig:
             if holdings >= 0:
                self.Liquidate(self.syl)
                self.SetHoldings(self.syl, -1.0)
             else:
                self.SetHoldings(self.syl, -1.0)
        
        self.Log("open: "+ str(self.currentopen)+" buy: "+str(self.buytrig)+" sell: "+str(self.selltrig))
        
        self.Plot('Strategy Equity', 'BTCUSD', self.currentopen); 
        self.Plot('Strategy Equity', 'Buy Trigger', self.buytrig); 
        self.Plot('Strategy Equity', 'Sell Trigger', self.selltrig);