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
Size:
Color:
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.
Size:
Color:
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
Size:
Color:
Hi Gernot,
For live trading, you can use
GetRemainingTradingDays as follows:
CODE:
Please log in to see this code.
Hope this helps.
Size:
Color:
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?
Size:
Color:
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.
Size:
Color:
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?
Size:
Color:
You're going to like Community Components. ;) It contains what you're looking for:
DateOfNextTradingDay.
Size:
Color:
Thx a lot this code helped.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color: