Consolidating Data

Consolidator History

Introduction

This page explains how to save and access historical consolidated bars.

Save Consolidated Bars

To access historical bars that were passed to your consolidation handler, save the bars as you receive them. You can use a RollingWindow to save the consolidated bars and easily access them later on in your algorithm.

// Create a class member to store the RollingWindow
_window = new RollingWindow<TradeBar>(2);

// In the consolidation handler, add consolidated bars to the RollingWindow
private void ConsolidationHandler(object sender, TradeBar consolidatedBar)
{
    _window.Add(consolidatedBar);
}
# Create a class member to store the RollingWindow
self.window = RollingWindow[TradeBar](2)

# In the consolidation handler, add consolidated bars to the RollingWindow
def consolidation_handler(self, sender: object, consolidated_bar: TradeBar) -> None:
    self.window.add(consolidated_bar)

Get Historical Bars

If you save consolidated bars in a RollingWindow, you can access them by indexing the RollingWindow. RollingWindow objects operate on a first-in, first-out process to allow for reverse list access semantics. Index 0 refers to the most recent item in the window and the largest index refers to the last item in the window.

var mostRecentBar = _window[0];
var previousBar = _window[1];
var oldestBar = _window[_window.Count-1];
most_recent_bar = self.window[0]
previous_bar = self.window[1]
oldest_bar = self.window[self.window.count-1]

To get the consolidated bar that was most recently removed from the RollingWindow, use the MostRecentlyRemoved property.

var removedBar = _window.MostRecentlyRemoved;
removed_bar = self.window.most_recently_removed

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: