Overall Statistics |
Total Trades 28 Average Win 0.67% Average Loss -0.63% Compounding Annual Return 42.264% Drawdown 1.600% Expectancy 0.331 Net Profit 2.910% Sharpe Ratio 5.588 Probabilistic Sharpe Ratio 98.996% Loss Rate 36% Win Rate 64% Profit-Loss Ratio 1.07 Alpha 0.351 Beta -0.063 Annual Standard Deviation 0.06 Annual Variance 0.004 Information Ratio 1.005 Tracking Error 0.125 Treynor Ratio -5.384 Total Fees $0.00 Estimated Strategy Capacity $3000000.00 Lowest Capacity Asset AUDUSD 8G |
class HyperActiveApricotFalcon(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 7, 1) self.SetEndDate(2021, 7, 31) self.SetCash(10000) self.pair = 'AUDUSD' self.AddForex(self.pair, Resolution.Minute, Market.Oanda) # Set Take Profit and Stop Loss Here self.tp = 0.0008 self.sl = 0.0005 # Long / Short - Set one to True self.Long = True self.Short = False # Set number of open positions allowed at a tome self.numtrades = 10 self.takeprofit = [] self.stoploss = [] self.numshares = [] self.takeprofitpos = {} self.stoplosspos = {} self.quantity = 100000 self.rsi = RelativeStrengthIndex(14, MovingAverageType.Wilders) self.macdfiveminute = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential) self.macdonehour = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential) self.atr = AverageTrueRange(14, MovingAverageType.Wilders) self.emafast = ExponentialMovingAverage(9) self.emaslow = ExponentialMovingAverage(50) oneHourConsolidator = QuoteBarConsolidator(timedelta(hours=1)) fiveMinuteConsolidator = QuoteBarConsolidator(timedelta(minutes=5)) oneHourConsolidator.DataConsolidated += self.OneHourBarHandler fiveMinuteConsolidator.DataConsolidated += self.FiveMinuteBarHandler self.SubscriptionManager.AddConsolidator(self.pair, oneHourConsolidator) self.SubscriptionManager.AddConsolidator(self.pair, fiveMinuteConsolidator) self.RegisterIndicator(self.pair, self.rsi, fiveMinuteConsolidator) self.RegisterIndicator(self.pair, self.macdonehour, oneHourConsolidator) 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.Schedule.On(self.DateRules.WeekEnd(self.pair), self.TimeRules.BeforeMarketClose(self.pair), self.WeekendLiquidation) self.fiveminbaropen = 0 self.SetWarmUp(50) self.lastfiveminutemacdvalues = RollingWindow[float](2) self.lastonehourmacdvalues = RollingWindow[float](2) self.removekeys = [] self.counter = 0 self.tpsl = {} def OneHourBarHandler(self, sender, consolidated): pass def FiveMinuteBarHandler(self, sender, consolidated): if not self.macdonehour.IsReady: return self.lastfiveminutemacdvalues.Add(self.macdfiveminute.Histogram.Current.Value) self.lastonehourmacdvalues.Add(self.macdonehour.Histogram.Current.Value) if not self.lastfiveminutemacdvalues.IsReady:return 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 # Exit Trades if self.Long: if len(self.tpsl) > 0: # Check Take Profit for key, value in self.tpsl.items(): if High >= value[0]: self.MarketOrder(self.pair, -self.quantity) self.removekeys.append(key) # Check Stop Loss for key, value in self.tpsl.items(): if Low <= value[1]: self.MarketOrder(self.pair, -self.quantity) self.removekeys.append(key) if self.Short: if len(self.tpsl) > 0: # Check Take Profit for key, value in self.tpsl.items(): if Low <= value[0]: self.MarketOrder(self.pair, self.quantity) self.removekeys.append(key) # Check Stop Loss for key, value in self.tpsl.items(): if High >= value[1]: self.MarketOrder(self.pair, self.quantity) self.removekeys.append(key) if len(self.removekeys) > 0: for x in self.removekeys: self.tpsl.pop(x) self.removekeys.clear() # Limit number of open trades if len(self.tpsl) >= self.numtrades: return # Entry Long if self.Long: # Close > 9 EMA ( 5 minute ) if Close > self.emafast.Current.Value: # Open > 9 EMA ( 5 minute) if Open > self.emafast.Current.Value: # Close < Open ( 5 minute ) if Close < Open: # 9EMA > 50EMA ( 5 minute ) if self.emaslow.Current.Value < self.emafast.Current.Value: # RSI < 65 ( 5 minute ) if self.rsi.Current.Value < 63 and self.rsi.Current.Value > 58: # MACD > .0001 ( 5 minute ) if self.macdfiveminute.Current.Value > .00005: # MACD Current > MACD 1 Bar Ago ( 5 minute and 1 hour ) if self.macdfiveminute.Current.Value > self.lastfiveminutemacdvalues[1] and self.macdonehour.Current.Value > self.lastonehourmacdvalues[1]: # ATR > .00025 if self.atr.Current.Value > .00025: # MACD Difference > 0 ( 5 minute and 1 hour ) if self.macdfiveminute.Current.Value - self.macdfiveminute.Signal.Current.Value > 0 and self.macdonehour.Current.Value - self.macdonehour.Signal.Current.Value > 0: self.counter += 1 self.MarketOrder(self.pair, self.quantity) tp = Close+self.tp sl = Close-self.sl self.tpsl[self.counter] = [tp, sl] self.Debug("Went long "+str(self.Time)) # Entry Short if self.Short: # Close < 9 EMA ( 5 minute ) if Close < self.emafast.Current.Value: # Open < 9 EMA ( 5 minute) if Open < self.emafast.Current.Value: # Close > Open ( 5 minute ) if Close > Open: # 9EMA < 50EMA ( 5 minute ) if self.emaslow.Current.Value > self.emafast.Current.Value: # RSI > 35 ( 5 minute ) if self.rsi.Current.Value > 38 and self.rsi.Current.Value < 45: # MACD < -.0001 ( 5 minute ) if self.macdfiveminute.Current.Value < -.00005: # MACD Current > MACD 1 Bar Ago ( 5 minute and 1 hour ) if self.macdfiveminute.Current.Value < self.lastfiveminutemacdvalues[1] and self.macdonehour.Current.Value < self.lastonehourmacdvalues[1]: # ATR > .00025 if self.atr.Current.Value > .00025: # MACD Difference > 0 ( 5 minute and 1 hour ) if self.macdfiveminute.Current.Value - self.macdfiveminute.Signal.Current.Value < 0 and self.macdonehour.Current.Value - self.macdonehour.Signal.Current.Value < 0: self.counter += 1 self.MarketOrder(self.pair, -self.quantity) tp = Close-self.tp sl = Close+self.sl self.tpsl[self.counter] = [tp, sl] def WeekendLiquidation(self): self.Liquidate() self.tpsl = {} def OnData(self, data): pass