BarHistoryCompressor is a static utility class containing methods that let you compress a BarHistory instance from one scale down to a more compressed scale. For example, you can call BarHistoryCompressor.ToWeekly to compress a daily BarHistory into a weekly one.
If you want to be able to plot a compressed BarHistory onto the chart, you would need to first expand it back to the original scale. You can use the BarHistorySynchronizer utility class to accomplish this.
Compresses the source BarHistory to a daily scale, returning a new BarHistory instance.
Compresses the source BarHistory to an interval-hour hourly scale, returning a new BarHistory instance.
Compresses the source BarHistory to an interval-minute scale, returning a new BarHistory instance.
Compresses the source BarHistory to a monthly scale, returning a new BarHistory instance.
Compresses the source BarHistory to a quarterly scale, returning a new BarHistory instance.
Compresses the source BarHistory to the specified scale, returning a new BarHistory instance.
Compresses the source BarHistory to a weekly scale, returning a new BarHistory instance.
Example Codeusing Quantacula.Backtest; using Quantacula.Core; using Quantacula.Indicators; using System.Drawing; namespace Quantacula { public class MyModel1 : UserModelBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { //get weekly data BarHistory weekly = BarHistoryCompressor.ToWeekly(bars); //get 4 week RSI RSI rsiWeekly = new RSI(weekly.Close, 4); //synchronize it back to the original (daily) scale TimeSeries rsiWeeklySynched = TimeSeriesSynhronizer.Synchronize(rsiWeekly, bars); //Plot the weekly RSI on the daily chart PlotTimeSeries(rsiWeeklySynched, "RSI(Weekly4)", "RSI", Color.Blue); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { } //declare private variables below } }
Compresses the source BarHistory to a yearly scale, returning a new BarHistory instance.