The tool you need for storing past values is the RollingWindow, another alternative is using History
To get today’s open you can use a Schelude the first minute before the market opens and store in a field.
Here is an example:
public class BasicTemplateDailyAlgorithm : QCAlgorithm
{
private RollingWindow<TradeBar> _dailyBars = new RollingWindow<TradeBar>(3);
private TradeBar _todayFirstMinuteBar;
public override void Initialize()
{
SetStartDate(2013, 10, 07); //Set Start Date
SetEndDate(2013, 10, 18); //Set End Date
SetCash(100000); //Set Strategy Cash
AddEquity("SPY", Resolution.Daily);
Schedule.On(DateRules.EveryDay(), TimeRules.AfterMarketOpen("SPY", 1), () =>
{
_todayFirstMinuteBar = History<TradeBar>("SPY", TimeSpan.FromMinutes(5), Resolution.Minute).Last();
});
}
public override void OnData(Slice slice)
{
_dailyBars.Add(slice.Bars["SPY"]);
if (_dailyBars.IsReady)
{
var todaysOpen = _todayFirstMinuteBar.Open;
// Implement your logic here.
}
}
}