| Overall Statistics |
|
Total Trades 6204 Average Win 0.00% Average Loss 0.00% Compounding Annual Return -7.313% Drawdown 11.700% Expectancy -0.939 Net Profit -6.733% Sharpe Ratio -0.914 Loss Rate 94% Win Rate 6% Profit-Loss Ratio 0.09 Alpha -0.2 Beta 8.785 Annual Standard Deviation 0.064 Annual Variance 0.004 Information Ratio -1.164 Tracking Error 0.064 Treynor Ratio -0.007 Total Fees $0.00 |
from QuantConnect.Indicators import *
from NodaTime import DateTimeZone
import decimal as d
class BollingerBreakoutAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017, 6, 1) #Set Start Date
self.SetEndDate(2018, 5, 1) #Set End Date
self.SetCash(10000) #Set Strategy Cash
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
self.eurusd = self.AddForex("EURUSD", Resolution.Minute).Symbol
self.SetTimeZone(DateTimeZone.Utc)
# create a bollinger band
self.Bolband = self.BB("EURUSD", 21, 2, MovingAverageType.Simple, Resolution.Minute)
# create a bollinger band of 4 std deviations for stop
self.Bolband_stop = self.BB("EURUSD", 21, 6, MovingAverageType.Simple, Resolution.Minute)
# set warmup period
self.SetWarmUp(21)
def OnData(self, data):
holdings = self.Portfolio["EURUSD"].Quantity
price = self.Securities["EURUSD"].Close
price_now = self.Securities["EURUSD"].Price
# If price closes above upper bollinger band then sell and close when price hits lower bollinger band or price hits the Upper band of the stop
if self.Time.hour >= 22 or self.Time.hour <= 8: #only trading between 10pm and 8am UTC
if holdings <= 0:
if price >= self.Bolband.UpperBand.Current.Value:
self.SetHoldings("EURUSD", -1.0)
else:
if price_now <= self.Bolband.LowerBand.Current.Value:
self.Liquidate("EURUSD")
elif price_now >= self.Bolband_stop.UpperBand.Current.Value:
self.Liquidate("EURUSD")
# # Buy if price closes below lower bollinger band then close when price hits lower bollinger band or price hits the stop
# if self.Time.hour >= 22 or self.Time.hour <= 8: #only trading between 10pm and 8am UTC
# if holdings <= 0:
# if price <= self.Bolband.LowerBand.Current.Value:
# self.SetHoldings("EURUSD", 1.0)
# else:
# if price_now >= self.Bolband.UpperBand.Current.Value:
# self.Liquidate("EURUSD")
# elif price_now <= self.Bolband_stop.LowerBand.Current.Value:
# self.Liquidate("EURUSD")