- ago
Is there currently a way to check if a specific DateTime is within post-market trading hours? I see that there is MarketDetails.IsPostMarket which uses the current system time, but I'm trying to detect if the post-market trading hours are nearly over.

I suppose I could manually set up an entry in the "Markets and Symbols" tool with the post-market hours, but I'd be worried I might mishandle certain days where the market closes early. If I create a copy of the "US Stocks" market, will it handle those special cases?
0
441
Solved
2 Replies

Reply

Bookmark

Sort
Glitch8
 ( 8.38% )
- ago
#2
Something like this should do it:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using System.Drawing; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //Initialize public override void Initialize(BarHistory bars) {          bool isPostMarket = IsPostMarket(bars, DateTime.Now);          DrawHeaderText("Is Post Market? " + isPostMarket, Color.Black, 12, "Price"); } //Execute public override void Execute(BarHistory bars, int idx) { }       //is specified time post market?       public bool IsPostMarket(BarHistory bars, DateTime dt)       {          MarketDetails mkt = bars.Market;          dt = mkt.ConvertLocalTimeToMarketTime(dt);          MarketHours hours = mkt.GetHoursMarketTime(dt);          if (mkt.IsTradingDayMarketTime(dt))             if (dt.TimeOfDay >= hours.CloseTime)                return true;          return false;       } } }
1
Best Answer

Reply

Bookmark

Sort