- ago
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.
1
116
3 Replies

Reply

Bookmark

Sort
Glitch8
 ( 8.11% )
- ago
#1
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.
0
- ago
#2
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.


0
Cone8
 ( 13.35% )
- ago
#3
3/4 of the answer is in your question. Just GetNextTradingDate and test for the DayOfWeek. It will be 100% accurate.

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);    }
1

Reply

Bookmark

Sort