Overall Statistics |
Total Trades 778 Average Win 0.06% Average Loss -0.07% Compounding Annual Return -58.670% Drawdown 8.600% Expectancy -0.286 Net Profit -7.229% Sharpe Ratio -3.893 Probabilistic Sharpe Ratio 0.048% Loss Rate 63% Win Rate 37% Profit-Loss Ratio 0.94 Alpha -0.47 Beta -0.11 Annual Standard Deviation 0.128 Annual Variance 0.016 Information Ratio -4.852 Tracking Error 0.159 Treynor Ratio 4.539 Total Fees $0.00 Estimated Strategy Capacity $770000.00 Lowest Capacity Asset AUDUSD 8G |
class HyperActiveApricotFalcon(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 6, 1) self.SetEndDate(2021, 7, 1) self.SetCash(10000) self.pair = 'AUDUSD' self.AddForex(self.pair, Resolution.Minute) # 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 = 5 self.takeprofit = [] self.stoploss = [] self.numshares = [] self.takeprofitpos = {} self.stoplosspos = {} self.quantity = 10000 self.rsi = RelativeStrengthIndex(14, MovingAverageType.Simple) self.macdfiveminute = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Simple) self.macdonehour = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Simple) self.atr = AverageTrueRange(14, MovingAverageType.Simple) 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, oneHourConsolidator) self.RegisterIndicator(self.pair, self.macdonehour, oneHourConsolidator) self.RegisterIndicator(self.pair, self.atr, oneHourConsolidator) 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(500) self.lastfiveminutemacdvalues = [] self.lastonehourmacdvalues = [] self.removekeys = [] self.counter = 0 self.tpsl = {} def OneHourBarHandler(self, sender, consolidated): pass def FiveMinuteBarHandler(self, sender, consolidated): pass def WeekendLiquidation(self): self.Liquidate() self.tpsl = {} def OnData(self, data): 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 = (data[self.pair].Bid.Close+data[self.pair].Ask.Close)/2 Open = (data[self.pair].Bid.Open+data[self.pair].Ask.Open)/2 Low = (data[self.pair].Bid.Low+data[self.pair].Ask.Low)/2 High = (data[self.pair].Bid.High+data[self.pair].Ask.High)/2 Price = data[self.pair].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: # 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.lastfiveminutemacdvalues[0] > 0 and self.macdonehour.Current.Value - self.lastonehourmacdvalues[0] > 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 > 37: # 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.lastfiveminutemacdvalues[0] < 0 and self.macdonehour.Current.Value - self.lastonehourmacdvalues[0] < 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) # Your New Python File
class HyperActiveApricotFalcon(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 6, 1) self.SetEndDate(2021, 7, 1) self.SetCash(10000) self.pair = 'AUDUSD' self.AddForex(self.pair, Resolution.Minute) # 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 = 15 self.takeprofit = [] self.stoploss = [] self.numshares = [] self.takeprofitpos = {} self.stoplosspos = {} self.quantity = 10000 self.rsi = RelativeStrengthIndex(14, MovingAverageType.Simple) self.macdfiveminute = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Simple) self.macdonehour = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Simple) self.atr = AverageTrueRange(14, MovingAverageType.Simple) 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, oneHourConsolidator) self.RegisterIndicator(self.pair, self.macdonehour, oneHourConsolidator) self.RegisterIndicator(self.pair, self.atr, oneHourConsolidator) 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(500) self.lastfiveminutemacdvalues = [] self.lastonehourmacdvalues = [] self.removekeys = [] self.counter = 0 self.tpsl = {} def OneHourBarHandler(self, sender, consolidated): pass def FiveMinuteBarHandler(self, sender, consolidated): pass def WeekendLiquidation(self): self.Liquidate() self.tpsl = {} def OnData(self, data): 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 = (data[self.pair].Bid.Close+data[self.pair].Ask.Close)/2 Open = (data[self.pair].Bid.Open+data[self.pair].Ask.Open)/2 Low = (data[self.pair].Bid.Low+data[self.pair].Ask.Low)/2 High = (data[self.pair].Bid.High+data[self.pair].Ask.High)/2 Price = data[self.pair].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: # MACD > .0001 ( 5 minute ) if self.macdfiveminute.Current.Value > .0001: # 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.lastfiveminutemacdvalues[0] > 0 and self.macdonehour.Current.Value - self.lastonehourmacdvalues[0] > 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 > 37: # MACD < -.0001 ( 5 minute ) if self.macdfiveminute.Current.Value < -.0001: # 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.lastfiveminutemacdvalues[0] < 0 and self.macdonehour.Current.Value - self.lastonehourmacdvalues[0] < 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)