Overall Statistics |
Total Trades 940 Average Win 0.07% Average Loss -0.09% Compounding Annual Return 0.065% Drawdown 3.800% Expectancy -0.007 Net Profit 0.336% Sharpe Ratio 0.042 Loss Rate 43% Win Rate 57% Profit-Loss Ratio 0.75 Alpha 0.018 Beta -1.084 Annual Standard Deviation 0.015 Annual Variance 0 Information Ratio -1.028 Tracking Error 0.015 Treynor Ratio -0.001 Total Fees $1222.92 |
from System import * from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Indicators import * from QuantConnect.Data.Market import TradeBar import decimal as d class RollingWindowAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2013, 6, 1) #Set Start Date self.SetEndDate(2019, 1, 1) #Set End Date self.SetCash(100000) #Set Strategy Cash self.SetBrokerageModel(BrokerageName.FxcmBrokerage) self.eurusd = self.AddForex("EURUSD", Resolution.Hour) self.SetTimeZone("Europe/Rome") self.window = RollingWindow[QuoteBar](2) # create a bollinger band self.Bolband = self.BB("EURUSD", 20, 2, MovingAverageType.Simple, Resolution.Hour) self.Bolband.Updated += self.BolbandUpdated self.BolbandWin = RollingWindow[IndicatorDataPoint](5) # set warmup period self.SetWarmUp(20) def BolbandUpdated(self, sender, updated): '''Adds updated values to rolling window''' self.BolbandWin.Add(updated) def OnData(self, data): self.window.Add(data["EURUSD"]) if not (self.window.IsReady and self.BolbandWin.IsReady): return holdings = self.Portfolio["EURUSD"].Quantity price = self.window[0].Price previousPrice = self.window[1].Close stop_price_ = self.Securities['EURUSD'].Price * 0.89 stop_price = self.Securities['EURUSD'].Price * 1.13 if price <= self.Bolband.LowerBand.Current.Value: self.SetHoldings("EURUSD", 0.2) self.LimitOrder("EURUSD", holdings, stop_price_) self.StopMarketOrder("EURUSD", holdings, stop_price) if price >= self.Bolband.UpperBand.Current.Value: self.SetHoldings("EURUSD", -0.2) self.LimitOrder("EURUSD", holdings, stop_price_) self.StopMarketOrder("EURUSD", holdings, stop_price) def OnOrderEvent(self, orderEvent): order = self.Transactions.GetOrderById(orderEvent.OrderId) if order.Status == OrderStatus.Filled: if order.Type == OrderType.Limit or order.Type == OrderType.StopMarket: self.Transactions.CancelOpenOrders(order.Symbol) if order.Status == OrderStatus.Canceled: self.Log(str(orderEvent))