Overall Statistics |
Total Trades 213 Average Win 0.17% Average Loss -0.11% Compounding Annual Return -10.826% Drawdown 3.200% Expectancy -0.087 Net Profit -1.053% Sharpe Ratio -0.967 Probabilistic Sharpe Ratio 24.622% Loss Rate 64% Win Rate 36% Profit-Loss Ratio 1.55 Alpha -0.027 Beta -0.201 Annual Standard Deviation 0.078 Annual Variance 0.006 Information Ratio -2.376 Tracking Error 0.132 Treynor Ratio 0.373 Total Fees $0.00 Estimated Strategy Capacity $3600000.00 Lowest Capacity Asset EURNZD 8G |
class HyperActiveApricotFalcon(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 6, 27) self.SetEndDate(2021, 7, 31) self.SetCash(100000) self.pair = 'EURNZD' self.forex = self.AddForex(self.pair, Resolution.Minute, Market.Oanda).Symbol self.quantity = 100000 # Set Take Profit and Stop Loss Here self.tp = 0.002 self.sl = 0.0015 # Long / Short - True = Live self.Long = True self.Short = False # Indicators self.rsi = RelativeStrengthIndex(14, MovingAverageType.Wilders) self.macdfiveminute = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential) self.macdonehour = self.MACD(self.forex, 12, 26, 9, MovingAverageType.Exponential, Resolution.Hour) self.atr = AverageTrueRange(14, MovingAverageType.Wilders) self.emafast = ExponentialMovingAverage(9) self.emaslow = ExponentialMovingAverage(50) self.stc = SchaffTrendCycle( 10, 23, 50, MovingAverageType.Exponential) # One Hour Consolidator and Indicator Registrations oneHourConsolidator = QuoteBarConsolidator(timedelta(minutes=60)) oneHourConsolidator.DataConsolidated += self.OneHourBarHandler self.SubscriptionManager.AddConsolidator(self.pair, oneHourConsolidator) # Five Minute Consolidator and Indicator Registrations fiveMinuteConsolidator = QuoteBarConsolidator(timedelta(minutes=5)) fiveMinuteConsolidator.DataConsolidated += self.FiveMinuteBarHandler self.SubscriptionManager.AddConsolidator(self.pair, fiveMinuteConsolidator) self.RegisterIndicator(self.pair, self.rsi, fiveMinuteConsolidator) self.RegisterIndicator(self.pair, self.atr, fiveMinuteConsolidator) self.RegisterIndicator(self.pair, self.macdfiveminute, fiveMinuteConsolidator) self.RegisterIndicator(self.pair, self.emafast, fiveMinuteConsolidator) self.RegisterIndicator(self.pair, self.emaslow, fiveMinuteConsolidator) self.RegisterIndicator(self.pair, self.stc, fiveMinuteConsolidator) self.macdLastHourWindow = RollingWindow[float](2) self.macdHourSignal = RollingWindow[float](2) self.Schedule.On(self.DateRules.Every(DayOfWeek.Friday), self.TimeRules.BeforeMarketClose(self.pair), self.WeekendLiquidation) self.fiveminbaropen = 0 self.SetWarmUp(50) self.lastfiveminutemacdvalues = [] self.lastonehourmacdvalues = [] self.macdLastFiveBar = None self.entryTicket = None self.SLTicket = None self.TPTicket = None self.entryTickets = [] self.entryTicketIDs = [] self.SLTickets = {} self.TPTickets = {} def OneHourBarHandler(self, sender, consolidated): self.macdLastHourWindow.Add(self.macdonehour.Current.Value) self.macdHourSignal.Add(self.macdonehour.Signal.Current.Value) def FiveMinuteBarHandler(self, sender, consolidated): if not self.macdonehour.IsReady: return if self.macdLastFiveBar == None or self.macdLastHourWindow.Count <= 1: self.macdLastFiveBar = self.macdfiveminute.Current.Value return # Bar Values Close = (consolidated.Bid.Close+consolidated.Ask.Close)/2 Open = (consolidated.Bid.Open+consolidated.Ask.Open)/2 Low = (consolidated.Bid.Low+consolidated.Ask.Low)/2 High = (consolidated.Bid.High+consolidated.Ask.High)/2 Price = consolidated.Price # Indicator Shortcuts emaFast = self.emafast.Current.Value emaSlow = self.emaslow.Current.Value rsiValue = self.rsi.Current.Value macdFive = self.macdfiveminute.Current.Value # Entry Long if self.Long and Close > emaFast and Open > emaFast and Close < Open and emaSlow < emaFast and rsiValue < 63 and rsiValue > 55: self.GoLong(Close) # Entry Short # elif self.Short and Close < emaFast and Open < emaFast and Close > Open and emaSlow > emaFast and rsiValue > 38 and rsiValue < 45: # self.GoShort(Close) # Record MACD values to compare at next datapoint self.macdLastFiveBar = self.macdfiveminute.Current.Value # Order Tickets ''' LONG STRATEGY ''' def GoLong(self, Close): FiveMACDdifference = self.macdfiveminute.Current.Value - self.macdfiveminute.Signal.Current.Value HourMACDdifference = self.macdLastHourWindow[0] - self.macdHourSignal[0] if self.macdfiveminute.Current.Value > .00005: if self.macdfiveminute.Current.Value > self.macdLastFiveBar and self.macdLastHourWindow[0] > self.macdLastHourWindow[self.macdLastHourWindow.Count-1]: if self.atr.Current.Value > .00025 and self.stc.Current.Value > 74 and FiveMACDdifference > 0 and HourMACDdifference > -.0001: self.MadeEntry() self.BuyPrice = Close self.SLPrice = self.BuyPrice - .0015 self.TPPrice = self.BuyPrice + .002 self.entryTicket = self.LimitOrder(self.pair, self.quantity, self.BuyPrice, str(self.macdfiveminute.Current.Value) + " " + str(self.macdLastFiveBar)) self.entryTickets.append(self.entryTicket) self.entryTicketIDs.append(self.entryTicket.OrderId) else: self.NoEntry() ''' SHORT STRATEGY ''' ''' ''' ''' ''' ''' Shorting code needs to be changed, and so does the shorting quantity ''' def GoShort(self, Close): FiveMACDdifference = self.macdfiveminute.Current.Value - self.macdfiveminute.Signal.Current.Value HourMACDdifference = self.macdonehour.Current.Value - self.macdonehour.Signal.Current.Value if self.entryTicket == None and self.macdfiveminute.Current.Value < -.00005: if self.macdfiveminute.Current.Value < self.macdLastFiveBar and self.macdonehour.Current.Value < self.macdLastHourWindow[self.macdLastHourWindow.Count-1]: if self.atr.Current.Value > .00025 and self.stc.Current.Value < 20 and FiveMACDdifference < 0 and HourMACDdifference < .0001: self.MadeEntry() self.BuyPrice = Close self.SLPrice = self.BuyPrice + .0015 self.TPPrice = self.BuyPrice - .002 self.entryTicket = self.LimitOrder(self.pair, -self.quantity, self.BuyPrice, str(self.macdfiveminute.Current.Value) + " " + str(self.macdLastFiveBar)) # Enter Stop Loss Order self.SLTicket = self.StopMarketOrder( self.pair, self.quantity, self.SLPrice) # Enter Take Profit Order self.TPTicket = self.LimitOrder( self.pair, self.quantity, self.TPPrice) else: self.NoEntry() ''' Close ALL Open Positions Before Weekend ''' def WeekendLiquidation(self): self.Liquidate() def MadeEntry(self): return self.Debug("ENTRY APPROVED ON " + str(self.Time)) self.Debug(f"STC Value : {self.stc.Current.Value}") def NoEntry(self): return self.Debug("No Entry: " + str(self.Time) + ". ENTRY TICKET: " + str(self.entryTicket)) self.Debug(f"STC Value : {self.stc.Current.Value}") def OnOrderEvent(self, orderEvent): if orderEvent.Status != OrderStatus.Filled: return order = self.Transactions.GetOrderById(orderEvent.OrderId) if orderEvent.OrderId in self.entryTicketIDs: self.Debug("Number of open limit orders: " + str(len(self.entryTickets))) # Enter Stop Loss Order self.SLTicket = self.StopMarketOrder( self.pair, -self.quantity, self.SLPrice) # Enter Take Profit Order self.TPTicket = self.LimitOrder( self.pair, -self.quantity, self.TPPrice) self.SLTickets[self.SLTicket] = self.TPTicket self.TPTickets[self.TPTicket] = self.SLTicket remove = None for entryTicket in self.entryTickets: if entryTicket.Status == OrderStatus.Filled: remove = entryTicket break if remove != None: self.entryTickets.remove(remove) self.entryTicketIDs.remove(remove.OrderId) return SLOrders = list(self.SLTickets.keys()) SLOrderIds = [x.OrderId for x in SLOrders] if orderEvent.OrderId in SLOrderIds: for ticket in SLOrders: if ticket.Status == OrderStatus.Filled: self.TPTickets[self.SLTickets[ticket]].Cancel() self.TPTickets.pop(self.SLTickets[ticket]) self.SLTickets[ticket].Cancel() self.SLTickets.pop(ticket, None) return TPOrders = list(self.TPTickets.keys()) TPOrderIds = [x.OrderId for x in TPOrders] if orderEvent.OrderId in TPOrderIds: for ticket in TPOrders: if ticket.Status == OrderStatus.Filled: self.SLTickets[self.TPTickets[ticket]].Cancel() self.SLTickets.pop(self.TPTickets[ticket]) self.TPTickets[ticket].Cancel() self.TPTickets.pop(ticket, None) return