We demonstrate using the QuantConnect consolidators to build TradeBars of any period.

Consolidators are a collection of classes for building merged TradeBars. They are used internally in the Lean Algorithmic Trading Engine but can be manually applied in your algorithm.

1. Create your consolidator object:

var _consolidator = new TradeBarConsolidator( TimeSpan.FromHours(4) ); 2. Add an event handler method for the data output:

_consolidator.DataConsolidated += SpyFourHours; 3. Add it to subscription manager so you get data updates:

SubscriptionManager.AddConsolidator("SPY", _consolidator); 4. Create your event handler method:

public void SpyFourHours(Object o, TradeBar bar)

{

//Do Work

}