- ago
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)]
0
88
Solved
3 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.29% )
- ago
#1
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.
1
Cone8
 ( 7.89% )
- ago
#2
Your code is hitting the second bar of the day. You need to subtract 1, not add -
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;
1
Best Answer
- ago
#3
That makes sense. Thank you very much.
1

Reply

Bookmark

Sort