Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 7.545% Drawdown 0.100% Expectancy 0 Net Profit 0.099% Sharpe Ratio 11.532 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.043 Beta 0.497 Annual Standard Deviation 0.004 Annual Variance 0 Information Ratio 8.337 Tracking Error 0.004 Treynor Ratio 0.1 Total Fees $0.00 |
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): self.SetStartDate(2018, 6, 1) #Set Start Date self.SetEndDate(2018, 6, 5) #Set End Date self.SetCash(100000) #Set Strategy Cash self.eurusd = self.AddForex("EURUSD", Resolution.Hour) self.SetTimeZone("Europe/Rome") # create a bollinger band self.Bolband = self.BB("EURUSD", 20, 2, MovingAverageType.Simple, Resolution.Hour) # set warmup period self.SetWarmUp(20) def OnData(self, data): if not (self.Bolband.IsReady): return # Current price price = self.Securities['EURUSD'].Price # Calculate lower = self.Securities['EURUSD'].Price * 0.95 higher = self.Securities['EURUSD'].Price * 1.05 # Calculate quantity holdings = self.Portfolio["EURUSD"].Quantity if not self.Portfolio.Invested: if price < self.Bolband.LowerBand.Current.Value: self.SetHoldings("EURUSD", 0.2) holdings = self.Portfolio["EURUSD"].Quantity self.LimitOrder("EURUSD", -holdings, higher) self.StopMarketOrder("EURUSD", -holdings, lower) ### Cancel remaining order if limit order or stop loss order is executed def OnOrderEvent(self, orderEvent): order = self.Transactions.GetOrderById(orderEvent.OrderId) if order.Status == OrderStatus.Filled: if order.Type == OrderType.Limit or order.Type == OrderType.Limit: self.Transactions.CancelOpenOrders(order.Symbol) if order.Status == OrderStatus.Canceled: self.Log(str(orderEvent))