Overall Statistics |
Total Trades 3954 Average Win 0.20% Average Loss -0.17% Compounding Annual Return 14.762% Drawdown 64.400% Expectancy 0.255 Net Profit 141.571% Sharpe Ratio 0.518 Loss Rate 43% Win Rate 57% Profit-Loss Ratio 1.20 Alpha 0.148 Beta 0.696 Annual Standard Deviation 0.307 Annual Variance 0.094 Information Ratio 0.465 Tracking Error 0.307 Treynor Ratio 0.229 Total Fees $0.00 |
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. # Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Indicators") AddReference("QuantConnect.Common") from System import * from QuantConnect import * from QuantConnect.Data import * from QuantConnect.Algorithm import * from QuantConnect.Indicators import * from datetime import timedelta import numpy as np ### <summary> ### Algorithm demonstrating FOREX asset types and requesting history on them in bulk. As FOREX uses ### QuoteBars you should request slices or ### </summary> ### <meta name="tag" content="using data" /> ### <meta name="tag" content="history and warm up" /> ### <meta name="tag" content="history" /> ### <meta name="tag" content="forex" /> class SalixcRider(QCAlgorithm): def Initialize(self): # Set the cash we'd like to use for our backtest self.SetCash(10000) # Start and end dates for the backtest. self.SetStartDate(2013, 1, 1) self.SetEndDate(2019, 5, 27) # Add FOREX contract you want to trade # find available contracts here https://www.quantconnect.com/data#forex/oanda/cfd self.forex = self.AddForex("EURUSD", Resolution.Daily) self.entry_price = 0 self.buy_price = 0 # Create a Rolling Window to keep the 2 QuoteBar self.quoteBarWindow = RollingWindow[QuoteBar](2) def OnData(self, data): if data.ContainsKey("EURUSD"): # Update our rolling windows self.quoteBarWindow.Add(data["EURUSD"]) # Wait for windows to be ready. if not (self.quoteBarWindow.IsReady): return #Bearish trade setup if self.entry_price > 0: newTicket = self.MarketOrder(self.forex.Symbol, 2000, asynchronous = False) if newTicket.Status != OrderStatus.Filled: self.Log("Sell order cancelled") self.entry_price = 0 if self.quoteBarWindow[1].Close > self.quoteBarWindow[1].Open: newTicket = self.MarketOrder(self.forex.Symbol, -2000, asynchronous = False) if newTicket.Status != OrderStatus.Filled: self.Log("Market sell order filled!") self.entry_price = 1 #Bullish trade setup if self.buy_price > 0: newTicket = self.MarketOrder(self.forex.Symbol, -2000, asynchronous = False) if newTicket.Status != OrderStatus.Filled: self.Log("Buy order cancelled") self.buy_price = 0 if self.quoteBarWindow[1].Close < self.quoteBarWindow[1].Open: newTicket = self.MarketOrder(self.forex.Symbol, 2000, asynchronous = False) if newTicket.Status != OrderStatus.Filled: self.Log("Market buy order filled!") self.buy_price = 1 #self.Debug('{} Current Close: {}, Prev Close: {}'.format(self.Time, round(self.quoteBarWindow[0].Close,5), round(self.quoteBarWindow[1].Close,5)))