Overall Statistics |
Total Trades 1243 Average Win 0.01% Average Loss 0.00% Compounding Annual Return -1.635% Drawdown 2.000% Expectancy -0.654 Net Profit -1.880% Sharpe Ratio -2.723 Probabilistic Sharpe Ratio 0.000% Loss Rate 88% Win Rate 12% Profit-Loss Ratio 1.82 Alpha -0.011 Beta -0.002 Annual Standard Deviation 0.004 Annual Variance 0 Information Ratio -0.549 Tracking Error 0.133 Treynor Ratio 6.939 Total Fees $0.00 |
class ForexMinuteTrading(QCAlgorithm): def Initialize(self): self.SetStartDate(2018, 10, 1) self.SetCash(10000) self.symbol = "EURUSD" self.resolution = Resolution.Minute # Order Variables self.buyOrder = None self.stopProfit = None self.stopLoss = None self.buyOrderPrice = 0 self.stopProfitPrice = 0 self.stopLossPrice = 0 # Indicators self.AddForex(self.symbol, self.resolution, Market.FXCM) self.slow = self.EMA(self.symbol, 20, self.resolution) self.fast = self.EMA(self.symbol, 5, self.resolution) self.atr = self.ATR(self.symbol, 20, MovingAverageType.Exponential, self.resolution) self.SetWarmUp(100) def isReady(self): # Indicators are still warming up if self.IsWarmingUp: return False # Do not continue until our indicators are ready if not self.slow.IsReady or not self.fast.IsReady or not self.atr.IsReady: return False return True def OnData(self, data): if not self.isReady(): return holdings = self.Portfolio[self.symbol].Quantity ########## # BUYING # ########## if holdings <= 0: # No existing buy order if self.buyOrder == None: if self.fast.Current.Value > self.slow.Current.Value * 1.0001: # Buy Order self.buyOrder = self.LimitOrder(self.symbol, 1000, self.Securities[self.symbol].Price) ########### # SELLING # ########### if holdings > 0: # We have holdings. If stop orders have not been placed and the fast EMA is higher than the slow EMA, place new stop orders. if self.stopProfit == None and self.stopLoss == None: if self.fast.Current.Value < self.slow.Current.Value: self.stopProfitPrice = self.buyOrderPrice * (1 + self.atr.Current.Value) self.stopProfit = self.LimitOrder(self.symbol, -1*self.Portfolio[self.symbol].Quantity, self.stopProfitPrice) self.stopLossPrice = self.buyOrderPrice * (1 - (2 * self.atr.Current.Value)) self.stopLoss = self.LimitOrder(self.symbol, -1*self.Portfolio[self.symbol].Quantity, self.stopLossPrice) # We have holdings. If stop orders have already been placed but not fulfilled, create the stop orders tighter by 1 PIP. elif False: # or self.stopProfit != None and self.stopLoss != None: if self.stopProfit.Status != OrderStatus.Filled and self.stopLoss.Status != OrderStatus.Filled: # Update Stop Profit updateStopProfitSettings = UpdateOrderFields() self.stopProfitPrice = self.stopProfitPrice * .9999 updateStopProfitSettings.LimitPrice = self.stopProfitPrice responseProfit = self.stopProfit.Update(updateStopProfitSettings) # if responseProfit.IsSuccess: # self.Debug("UPDATE: Stop Profit Limit Order" ) # Update Stop Loss updateStopLossSettings = UpdateOrderFields() self.stopLossPrice = self.stopLossPrice * 1.0001 updateStopLossSettings.LimitPrice = self.stopLossPrice responseLoss = self.stopLoss.Update(updateStopLossSettings) # if responseLoss.IsSuccess: # self.Debug("UPDATE: Stop Loss Limit Order" ) def OnOrderEvent(self, OrderEvent): if self.buyOrder != None: # Buy Order has been fulfilled if OrderEvent.OrderId == self.buyOrder.OrderId and OrderEvent.Status == OrderStatus.Filled: self.Debug("BUY >> " + str(OrderEvent.FillPrice)) self.buyOrderPrice = OrderEvent.FillPrice self.buyOrder = None if self.stopProfit != None: # Stop Profit has been fulfilled. Cancel the Stop Loss order. if OrderEvent.OrderId == self.stopProfit.OrderId and OrderEvent.Status == OrderStatus.Filled: self.Debug("SELL (PROFIT) >> " + str(OrderEvent.FillPrice)) self.stopLoss.Cancel() self.stopProfit = None self.stopLoss = None if self.stopLoss != None: # Stop Loss has been fulfilled. Cancel the Stop Profit order. if OrderEvent.OrderId == self.stopLoss.OrderId and OrderEvent.Status == OrderStatus.Filled: self.Debug("SELL (LOSS) >> " + str(OrderEvent.FillPrice)) self.stopProfit.Cancel() self.stopProfit = None self.stopLoss = None
from QuantConnect import * from Selection.ManualUniverseSelectionModel import ManualUniverseSelectionModel class G10CurrencySelectionModel(ManualUniverseSelectionModel): def __init__(self): super().__init__([Symbol.Create(x, SecurityType.Forex, Market.Oanda) for x in [ "EURUSD", "GBPUSD", "USDJPY", "AUDUSD", "NZDUSD","USDCAD", "USDCHF", "USDNOK", "USDSEK"]])