Overall Statistics
Total Trades
40
Average Win
1037.21%
Average Loss
-5.15%
Compounding Annual Return
229.860%
Drawdown
70.900%
Expectancy
35.807
Net Profit
1705.240%
Sharpe Ratio
2.833
Probabilistic Sharpe Ratio
89.133%
Loss Rate
82%
Win Rate
18%
Profit-Loss Ratio
201.44
Alpha
1.698
Beta
0.032
Annual Standard Deviation
0.617
Annual Variance
0.38
Information Ratio
0.208
Tracking Error
0.907
Treynor Ratio
55.398
Total Fees
$478.73
Estimated Strategy Capacity
$2800000.00
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Data.Market import TradeBar

class RollingWindowAlgorithm(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(2016,6,1)  #Set Start Date
        self.SetEndDate(2018,11,1)    #Set End Date
        self.SetCash(1000)           #Set Strategy Cash
      
        self.symbol= "BTCUSD"
        btc = self.AddCrypto("BTCUSD", Resolution.Daily,Market.GDAX)
        btc.SetLeverage(1)
        
        self.period = 200
        self.sma = self.SMA(self.symbol,self.period )
        
        self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
        #self.SetBrokerageModel(BrokerageName.AlphaStreams)
        
        self.invested = 0
        self.Schedule.On(self.DateRules.MonthStart("BTCUSD"), self.TimeRules.BeforeMarketClose("BTCUSD",0),self.deposit)
    def deposit(self):
        self.Portfolio.CashBook["USD"].AddAmount(100)
        self.invested += 100

    def OnData(self, data):
        close = self.Securities[self.symbol].Close
        
        if close > self.sma.Current.Value:
            self.SetHoldings(self.symbol, 1)
            
        else:
            self.SetHoldings(self.symbol, 0)
            #self.SetHoldings([PortfolioTarget(self.symbol, 0)])
            #self.Liquidate()