| Overall Statistics |
|
Total Trades 205 Average Win 16.07% Average Loss -3.51% Compounding Annual Return 120.366% Drawdown 45.300% Expectancy 1.079 Net Profit 1567.261% Sharpe Ratio 1.367 Probabilistic Sharpe Ratio 81.214% Loss Rate 63% Win Rate 37% Profit-Loss Ratio 4.58 Alpha 0.671 Beta -0.129 Annual Standard Deviation 0.481 Annual Variance 0.232 Information Ratio 1.125 Tracking Error 0.495 Treynor Ratio -5.116 Total Fees $62621.30 |
from QuantConnect.Indicators import *
import decimal as d
### <summary>
### In this example we are looking for price to breakout above the bollinger bands
### and look to buy when we see that. We hold our position until price touches the
### middle band of the bollinger bands.
###
class BollingerBreakoutAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2016, 6, 1) #Set Start Date
#self.SetEndDate(2017, 7, 1) #Set End Date
self.SetCash(10000) #Set Strategy Cash
self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash )
# define crypto we want to trade on
# ETHUSD, LTCUSD or BTCUSD
self.target_crypto = "BTCUSD"
self.AddCrypto(self.target_crypto, Resolution.Daily)
# create a bollinger band
self.Bolband = self.BB(self.target_crypto, 3, 0.1, MovingAverageType.Exponential, Resolution.Daily)
# Plot Bollinger band
self.PlotIndicator(
"Indicators",
self.Bolband.LowerBand,
self.Bolband.MiddleBand,
self.Bolband.UpperBand,
)
# create a momentum indicator over 3 days
self.mom = self.MOM(self.target_crypto, 5)
# Plot Momentum
self.PlotIndicator(
"Indicators",
self.mom
)
# set warmup period
self.SetWarmUp(20)
def OnData(self, data):
#if self.Time == (2018, 8, 10):
holdings = self.Portfolio[self.target_crypto].Quantity
price = self.Securities[self.target_crypto].Close
mom = self.mom.Current.Value
# buy if price closes above upper bollinger band
if holdings <= 0:
if price > self.Bolband.LowerBand.Current.Value and mom > 0:
self.SetHoldings(self.target_crypto, 1.0)
# sell if price closes below middle bollinger band
if holdings > 0 and price < self.Bolband.MiddleBand.Current.Value and mom < 0:
self.Liquidate()