Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -1.735 Tracking Error 0.125 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset Portfolio Turnover 0% |
# region imports from AlgorithmImports import * # endregion class FormalBrownElephant(QCAlgorithm): def Initialize(self): self.SetStartDate(2023, 1, 1) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.symbol = self.AddEquity("SPY", Resolution.Hour).Symbol self.six_ema = ExponentialMovingAverage(6) self.twelve_ema = ExponentialMovingAverage(12) self.consolidator = TradeBarConsolidator(timedelta(hours = 1)) self.consolidator.DataConsolidated += self.consolidation_handler self.SubscriptionManager.AddConsolidator(self.symbol, self.consolidator) self.RegisterIndicator(self.symbol, self.six_ema, self.consolidator) self.RegisterIndicator(self.symbol, self.twelve_ema, self.consolidator) history = self.History(self.symbol, 200, Resolution.Hour).loc[self.symbol] for idx, bar in history.iterrows(): tradeBar = TradeBar(idx, self.symbol, bar.open, bar.high, bar.low, bar.close, bar.volume, timedelta(hours=1)) self.consolidator.Update(tradeBar) chart = Chart("SPY") chart.AddSeries(Series("Uptrend Crossover", SeriesType.Scatter, "$", Color.Green, ScatterMarkerSymbol.Triangle)) chart.AddSeries(Series("Downtrend Crossover", SeriesType.Scatter, "$", Color.Red, ScatterMarkerSymbol.TriangleDown)) self.AddChart(chart) def consolidation_handler(self, sender: object, consolidated_bar: TradeBar) -> None: pass #self.Plot(consolidated_bar.Symbol.Value, "4HourBar", consolidated_bar.Close) def OnData(self, slice): price = self.Securities[self.symbol].Price six_ema = self.six_ema.Current.Value twelve_ema = self.twelve_ema.Current.Value self.Plot("SPY", "Price", price) self.Plot("SPY", "6 EMA", self.six_ema.Current.Value) self.Plot("SPY", "12 EMA", self.twelve_ema.Current.Value) if six_ema >= twelve_ema: self.Plot("SPY", "Uptrend Crossover", six_ema) if six_ema < twelve_ema: self.Plot("SPY", "Downtrend Crossover", six_ema)