Synchronize
public static BarHistory Synchronize(BarHistory source, TimeSeriesBase master)Synchronizes source to the DateTimes of master and returns a new BarHistory whose Scale matches the scale determined from master. The synchronized BarHistory contains one bar for each DateTime in the master series. Values from the source BarHistory are carried forward as appropriate until the next source bar becomes available.
If either source or master is null, returns source. If either series contains no data, returns source.
The method also synchronizes NamedSeries registered with the source BarHistory. The resulting BarHistory retains the source BarHistory's MetaTag.
When synchronizing a Daily or more compressed source BarHistory to an intraday master, WealthLab aligns the source bars with the appropriate market session before making the values available. This prevents a completed Daily, Weekly, or other compressed bar from becoming available prematurely during the intraday session. Markets whose sessions trade through midnight are handled using their configured market open and close times.
For intraday synchronization between BarHistory instances associated with different Markets, source DateTimes are converted from the source Market's time zone to the master Market's time zone before synchronization.
using WealthLab.Backtest;
using WealthLab.Core;
using System.Drawing;
namespace WealthLab
{
public class MyStrategy1 : UserStrategyBase
{
public override void Initialize(BarHistory bars)
{
//get weekly data
BarHistory weekly = BarHistoryCompressor.ToWeekly(bars);
//synchronize it back to the original daily scale
BarHistory weeklySynched = BarHistorySynchronizer.Synchronize(weekly, bars);
//plot the weekly bars on top of the daily bars
PlotBarHistory(weeklySynched, "Price", WLColor.FromArgb(62, 0, 0, 0));
}
public override void Execute(BarHistory bars, int idx)
{
}
}
}