What is the best way to retrieve the prior day close from a minute scale bar timeseries? Currently I'm getting a close timeseries and trying to back up to the prior day's last bar using IntraDayBarNumber, but this isn't always working.
CODE:
double PriorDayClose = bars.Close[idx-(bars.IntradayBarNumber(idx)+1)]
Rename
Assuming it’s C# coded the most efficient way I can think of would be to declare a private variable and on the last bar of the day store the close value in the variable.
Your code is hitting the second bar of the day. You need to subtract 1, not add -
Also note that the intraday close often doesn't match the settled close - daily bars have the settled close. Here's how you'd get the settled close from Daily bars in an intraday chart.
If you want yesterday's close even on the last bar of the day, then change the Synch statement to this:
CODE:
double PriorDayClose = bars.Close[idx-(bars.IntradayBarNumber(idx) - 1)]
Also note that the intraday close often doesn't match the settled close - daily bars have the settled close. Here's how you'd get the settled close from Daily bars in an intraday chart.
CODE:
TimeSeries _priorSettledClose; public override void Initialize(BarHistory bars) { _priorSettledClose = GetHistoryUnsynched(bars.Symbol, HistoryScale.Daily).Close; _priorSettledClose = TimeSeriesSynchronizer.Synchronize(_priorSettledClose, bars); PlotTimeSeries(_priorSettledClose, "PriorClose", "Price", WLColor.Gold, PlotStyle.Dots); }
If you want yesterday's close even on the last bar of the day, then change the Synch statement to this:
CODE:
_priorSettledClose = TimeSeriesSynchronizer.Synchronize(_priorSettledClose, bars) >> 1;
That makes sense. Thank you very much.
Your Response
Post
Edit Post
Login is required