IsLastTradingDayOfMonth
Author: cicerotullius
Creation Date: 7/25/2015 3:40 PM
profile picture

cicerotullius

#1
Hi,

I want to trade something on the Last Trading day of the month, but with EOD. Meaning I need to know on the second last Trading Day of the month already the signal.

if I use the funcation

if(DateRules.IsLastTradingDayOfMonth(Bars.Date[bar]))

I can only enter on the same day, I do not get any signal on the day before to enter with BAR+1

If I try:
if(DateRules.IsLastTradingDayOfMonth(Bars.Date[bar+1]))

I only get errors.

thx
profile picture

Eugene

#2
QUOTE:
Last Trading day of the month, but with EOD

WealthLab.Rules.DateRules work with EOD data for sure.

QUOTE:
the second last Trading Day of the month

There can only be one and only last trading day of month, not second. Could you rephrase so it all would make better sense?

QUOTE:
I only get errors.

Index out of bounds, I guess? Make sure your condition is not being processed when bar == Bars.Count-1.
profile picture

cicerotullius

#3
Hi Eugene,

Yes I know there can only be one last trading day of the month.

The point of my question is: if I want to buy at market on the last trading day of the month and trigger this with EOD data a day before, I need a possibility to a day earlier when is the last trading day of the month:

Example:
Last day is the 30th
My data update runs late in the evening with data of the 29th, now I want to create a signal for the 30th to buy at market. (Tomorrow)

But the function does not allow me to say "if last trading day of the month is tomorrow" it seems to work only with bar not bar+1.

Thx
profile picture

Eugene

#4
Hi Gernot,

For live trading, you can use GetRemainingTradingDays as follows:

CODE:
Please log in to see this code.


Hope this helps.
profile picture

Panache

#5
When I compile the above code, I get:

error CS1061@(18,27):'System.DateTime' does not contain a definition for 'GetRemainingTradingDays' and no extension method 'GetRemainingTradingDays' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly

What am I missing?
profile picture

Eugene

#6
You don't have Community Components installed (that's where GetRemainingTradingDays is contained). By the way, since GetRemainingTradingDays is an extension method, adding "using Community.Components" is no longer required. Nice syntactic sugar.
profile picture

Panache

#7
I know this is a little off topic, but is there a function that returns the next trading day, checking for market holidays as well as weekends?
profile picture

Eugene

#8
You're going to like Community Components. ;) It contains what you're looking for: DateOfNextTradingDay.
profile picture

cicerotullius

#9
Thx a lot this code helped.
profile picture

Panache

#10
Excellent! Thanks Eugene.

btw - I'm not sure why this isn't working for cicerotullius:

CODE:
Please log in to see this code.


It avoids the problem with GetRemainingTradingDays not taking into account holidays, ie. Thanksgiving in the U.S.

CODE:
Please log in to see this code.
profile picture

Eugene

#11
QUOTE:
btw - I'm not sure why this isn't working for cicerotullius:


Try it this way :)

CODE:
Please log in to see this code.


As he told, he's looking to execute it on the last bar.
profile picture

Panache

#12
I thought I had it working yesterday, but obviously I hadn't tested it enough. I believe if you add bar < Bars.Count - 1 && it works.

CODE:
Please log in to see this code.
profile picture

Eugene

#13
QUOTE:
I believe if you add bar < Bars.Count - 1 && it works.

No, this code will not work for topic starter who is looking to use it precisely when bar == Bars.Count - 1. This condition simply excludes the last bar from processing and prevents any alerts from being triggered in live trading.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).