Overall Statistics |
Total Trades 5 Average Win 14.33% Average Loss 0% Compounding Annual Return 217.764% Drawdown 11.400% Expectancy 0 Net Profit 33.743% Sharpe Ratio 3.995 Probabilistic Sharpe Ratio 84.504% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 1.127 Beta 0.027 Annual Standard Deviation 0.336 Annual Variance 0.113 Information Ratio -8.02 Tracking Error 0.811 Treynor Ratio 48.999 Total Fees $8290.36 Estimated Strategy Capacity $26000000.00 |
# MACD and STO with IndicatorExtensions Delay() class MACDandSTOwithIndicatorExtensionsDelay(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 1, 1) # Set Start Date self.SetEndDate(2021, 4, 1) # Set End Date self.SetCash(1000000) self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash) res = Resolution.Daily self.crypto = self.AddCrypto("BTCUSD", res).Symbol self.SetWarmUp(100) self.macd = self.MACD(self.crypto, 12, 26, 9, MovingAverageType.Simple, res) self.macd_delayed = IndicatorExtensions.Of(Delay(1), self.macd) self.macd_delayed_histogram = IndicatorExtensions.Of(Delay(1), self.macd.Histogram) self.macd_delayed_signal = IndicatorExtensions.Of(Delay(1), self.macd.Signal) self.stoch = self.STO(self.crypto, 14, 3, 3, res) self.delayed_slowK = IndicatorExtensions.Of(Delay(1), self.stoch.StochK) self.delayed_slowD = IndicatorExtensions.Of(Delay(1), self.stoch.StochD) self.control = False def OnData(self, data): if not (self.macd.IsReady and self.stoch.IsReady): return macd = self.macd.Current.Value macd_d = self.macd_delayed.Current.Value signal = self.macd.Signal.Current.Value signal_d = self.macd_delayed_signal.Current.Value hist = self.macd.Histogram.Current.Value hist_d = self.macd_delayed_histogram.Current.Value stochK = self.stoch.StochK.Current.Value stochK_d = self.delayed_slowK.Current.Value stochD = self.stoch.StochD.Current.Value stochD_d = self.delayed_slowD.Current.Value self.Plot('MACD', 'macd', macd) self.Plot('MACD', 'macd_delayed', macd_d) self.Plot('SIGNAL', 'signal', signal) self.Plot('SIGNAL', 'delayed_signal', signal_d) self.Plot('HIST', 'hist', hist) self.Plot('HIST', 'delayed_histogram', hist_d) if hist < hist_d and ((stochK > stochD and stochK_d < stochD_d) or stochK > stochD) and hist < 0 and stochD < 40 and self.control == False: self.control = True usdTotal = self.Portfolio.CashBook["USD"].Amount limitPrice = round(self.Securities["BTCUSD"].Price * 0.95, 2) quantity = usdTotal * 0.5 / limitPrice self.MarketOrder("BTCUSD", quantity) elif (signal > macd and signal_d < macd_d) and self.control == True: self.control = False limitPrice = round(self.Securities["BTCUSD"].Price * 1.00, 2) quantity = self.Portfolio.CashBook["BTC"].Amount self.MarketOrder("BTCUSD", -quantity) ''' def OnOrderEvent(self, orderEvent): self.Debug("{} {}".format(self.Time, orderEvent.ToString())) def OnEndOfAlgorithm(self): self.Log("{} - TotalPortfolioValue: {}".format(self.Time, self.Portfolio.TotalPortfolioValue)) self.Log("{} - CashBook: {}".format(self.Time, self.Portfolio.CashBook)) '''