I'm looking for some help on writing code to buy on a specific day of the week, i.e. Wednesday or Thursday. I am using
(bars.DateTimes[idx].GetNextTradingDate(bars).IsLastTradingDayOfWeek(bars))
to buy on Friday (or Thursday in certain weeks) but I can't find code that will identify other days.
(bars.DateTimes[idx].GetNextTradingDate(bars).IsLastTradingDayOfWeek(bars))
to buy on Friday (or Thursday in certain weeks) but I can't find code that will identify other days.
Rename
If you don't mind not being 100% accurate you can even do it in Building Blocks. Use the DayOfWeek indicator, and if you want to buy on a Wed for example, use DayOfWeek == 2 (Tuesday.) I say it's not 100% accurate because if there happens to be a holiday on a particular Wednesday then you'll get the entry on the following day.
If you want to be 100% accurate let me know and I can share some example code.
If you want to be 100% accurate let me know and I can share some example code.
Thanks, Glitch. I tried the Building block code and it's very close, but I'd like to see the sample code you referenced - it will help me test it against some manual analysis I've done.
3/4 of the answer is in your question. Just GetNextTradingDate and test for the DayOfWeek. It will be 100% accurate.
Alternatively,
CODE:
if (bars.DateTimes[idx].GetNextTradingDate(bars).DayOfWeek == DayOfWeek.Wednesday) { Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market); }
Alternatively,
CODE:
if (bars.GetNextTradingDate(bars.DateTimes[idx]).DayOfWeek == DayOfWeek.Wednesday) { Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market); }
Your Response
Post
Edit Post
Login is required