hi, I'm developing a intraday strategy which will run from pre-market all the way to post-market. It will need to look at data from the daily series, so I'm using BarHistory.BarHistoryCompressor to create the daily series out of the intraday series.
The problem is the original intraday data includes pre/post market data (intentionally), but for the compressed daily series I'd like to FILTER OUT PRE/POST MARKET DATA. Is there a way to accomplish that?
An example is the intraday strategy will need to compare the each intraday bar's price to the previous day closing price... which needs to be the closing price for the regular market, NOT including the post market data/closing.
Thanks in advance for any ideas!
The problem is the original intraday data includes pre/post market data (intentionally), but for the compressed daily series I'd like to FILTER OUT PRE/POST MARKET DATA. Is there a way to accomplish that?
An example is the intraday strategy will need to compare the each intraday bar's price to the previous day closing price... which needs to be the closing price for the regular market, NOT including the post market data/closing.
Thanks in advance for any ideas!
Rename
Access the Daily bars directly like this -
Be aware that the intraday "last trade" price can differ from the daily "settled close" - usually not more than a penny or two, but sometimes more (especially in the last week).
CODE:
using System; using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript5 { public class MyStrategy : UserStrategyBase { private BarHistory _daily; public override void Initialize(BarHistory bars) { // gets all Daily bar available _daily = GetHistoryUnsynched(bars.Symbol, HistoryScale.Daily); // synchronize it _daily = BarHistorySynchronizer.Synchronize(_daily, bars); // plot the Close PlotTimeSeries(_daily.Close, "Day Close", "Price", WLColor.Blue, PlotStyle.Dots); StartIndex = 20; } public override void Execute(BarHistory bars, int idx) { double yestClose = _daily.Close[idx]; } } }
Be aware that the intraday "last trade" price can differ from the daily "settled close" - usually not more than a penny or two, but sometimes more (especially in the last week).
Well, the synchronization works fine when the Pre/Post Filter is enabled, but unfortunately there's a synch problem when the filter is disabled. Let's see if we can find a workaround for that...
... actually, it's okay as long as you're comparing bars during market hours. It just looks strange. Since Daily bars don't have a "time part" it's synchronized by Date - you don't see the change for the close until the next morning.
... actually, it's okay as long as you're comparing bars during market hours. It just looks strange. Since Daily bars don't have a "time part" it's synchronized by Date - you don't see the change for the close until the next morning.
Thanks for the quick reply Cone! I will give it a try tomorrow and report back. Thanks again.
Solution 2
If you want to use the intraday closing value, you need to do a little more work to determine the regular market closing time from the holiday calendar due to short days and rare irregular closes. You also get a better synchronization for the plot.
Your intraday must have a timestamp precisely at the market closing time each day for this to work. Usually that's not a problem when the Pre/Post filter is enabled.
If you want to use the intraday closing value, you need to do a little more work to determine the regular market closing time from the holiday calendar due to short days and rare irregular closes. You also get a better synchronization for the plot.
CODE:
using System; using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript6 { public class MyStrategy : UserStrategyBase { private TimeSpan _regularClose = new TimeSpan (16, 0, 0); private TimeSeries _closes; public override void Initialize(BarHistory bars) { _closes = new TimeSeries(bars.DateTimes, true); PlotTimeSeries(_closes, "Day Close", "Price", WLColor.Blue, PlotStyle.Dots); StartIndex = 20; } public override void Execute(BarHistory bars, int idx) { TimeSpan regCloseToday = bars.Market.HolidaySet.SpecialHours.TryGetValue(bars.DateTimes[idx].Date, out MarketHours marketHours) ? marketHours.CloseTime : _regularClose; _closes[idx] = bars.DateTimes[idx].TimeOfDay == regCloseToday ? bars.Close[idx] : _closes[idx - 1]; double yestClose = _closes[idx]; } } }
Your intraday must have a timestamp precisely at the market closing time each day for this to work. Usually that's not a problem when the Pre/Post filter is enabled.
Hey Cone, I spent some time playing with this today and the first solution you provided addresses exactly the use case I was looking for. Thanks for your help, much appreciated!
Your Response
Post
Edit Post
Login is required