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 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
namespace QuantConnect.Algorithm.CSharp { public class ConsolidatorAt30 : QCAlgorithm { private MovingAverageConvergenceDivergence oneHourMACD; private MovingAverageConvergenceDivergence fourHourMACD; private readonly string _spy = "SPY"; RollingWindow<IndicatorDataPoint> oneHourWindow; RollingWindow<IndicatorDataPoint> fourHourWindow; TradeBarConsolidator oneHour; TradeBarConsolidator fourHours; public override void Initialize() { SetStartDate(2020, 01, 01); SetEndDate(DateTime.Now); SetWarmUp(TimeSpan.FromDays(30)); AddEquity(_spy, Resolution.Minute); // define our daily macd(12,26) with a 9 day signal oneHourMACD = new MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential); fourHourMACD = new MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential); oneHourWindow = new RollingWindow<IndicatorDataPoint>(4); fourHourWindow = new RollingWindow<IndicatorDataPoint>(4); oneHour = new TradeBarConsolidator(CustomPeriod); fourHours = new TradeBarConsolidator(TimeSpan.FromMinutes(240)); //bind event handler to data consolidated event. oneHour.DataConsolidated += OnOneHour; fourHours.DataConsolidated += OnFourHours; oneHourMACD.Histogram.Updated += (object sender, IndicatorDataPoint updated) => { oneHourWindow.Add(updated); }; fourHourMACD.Histogram.Updated += (object sender, IndicatorDataPoint updated) => { fourHourWindow.Add(updated); }; //register the consolidator for data. SubscriptionManager.AddConsolidator(_spy, oneHour); RegisterIndicator(_spy, oneHourMACD, oneHour); SubscriptionManager.AddConsolidator(_spy, fourHours); RegisterIndicator(_spy, fourHourMACD, fourHours); Schedule.On(DateRules.EveryDay("SPY"), TimeRules.BeforeMarketClose("SPY", 1), OnMarketClose); } public void OnOneHour(object sender, TradeBar consolidated) { if (!oneHourMACD.IsReady) return; if (!oneHourWindow.IsReady) return; Debug("One Hour MACD: "+ oneHourMACD.Histogram + " Previous: " + oneHourWindow[1]*1); } public void OnFourHours(object sender, TradeBar consolidated) { if (!fourHourMACD.IsReady) return; if (!fourHourWindow.IsReady) return; Debug("---Four Hour MACD: "+ fourHourMACD.Histogram + " Previous: " + fourHourWindow[1]*1); } public void OnData(TradeBars data) { } private CalendarInfo CustomPeriod(DateTime datetime) { var period = TimeSpan.FromHours(1); var start = datetime.RoundDown(TimeSpan.FromMinutes(30)); return new CalendarInfo(start, period); } public void OnMarketClose(){ var bar = oneHour.WorkingData; Debug(bar.Value); } } }