Overall Statistics |
Total Trades 30 Average Win 0.67% Average Loss -0.63% Compounding Annual Return 31.765% Drawdown 1.600% Expectancy 0.241 Net Profit 2.270% Sharpe Ratio 5.59 Probabilistic Sharpe Ratio 98.547% Loss Rate 40% Win Rate 60% Profit-Loss Ratio 1.07 Alpha 0.265 Beta -0.046 Annual Standard Deviation 0.046 Annual Variance 0.002 Information Ratio 0.367 Tracking Error 0.117 Treynor Ratio -5.499 Total Fees $0.00 Estimated Strategy Capacity $3100000.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 = [] self.lastonehourmacdvalues = [] self.removekeys = [] self.counter = 0 self.tpsl = {} def OneHourBarHandler(self, sender, consolidated): pass def FiveMinuteBarHandler(self, sender, consolidated): if not self.macdonehour.IsReady: return if len(self.lastfiveminutemacdvalues) < 2: self.lastfiveminutemacdvalues.append(self.macdfiveminute.Histogram.Current.Value) self.lastonehourmacdvalues.append(self.macdonehour.Histogram.Current.Value) 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[0] and self.macdonehour.Current.Value > self.lastonehourmacdvalues[0]: # 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] # 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[0] and self.macdonehour.Current.Value < self.lastonehourmacdvalues[0]: # 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] # Record MACD values to compare at next datapoint self.lastfiveminutemacdvalues.append(self.macdfiveminute.Histogram.Current.Value) self.lastfiveminutemacdvalues.pop(0) self.lastonehourmacdvalues.append(self.macdonehour.Histogram.Current.Value) self.lastonehourmacdvalues.pop(0) def WeekendLiquidation(self): self.Liquidate() self.tpsl = {} def OnData(self, data): pass