How would i code the following theory
"Trading days left in month = 2"
So i know how to work out the current Trading Day Of Month
that is
if (Month(date) <> Month(date[1]) TDOM = 0
if date <> date[1] then TDOM = TDOM + 1
Now this is DIFFERENT to DayOfMonth function, because that simply gives the current day date.
What i am referring to here is trading days (so ignoring weekends).
In a month there can be 18 or 19 or even 23 trading days.
Now what i would like to know is, if today is that day when the number of trading days left in the month is 2
I tried things like date[-1] buy then i get errors of "trying to access future data"
The logic i was thinking of was something like
Month(Date) <> Month(Date[-2]) ... this gave the error of trying to access future data
Trading days left in month
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Trading days left in month
I'd make a function that uses a loop that begins with the current day (t), adds one day (while skipping Saturdays and Sundays), and then checks to see if that new date (t + 1) has a different month or not. Keep doing this until there is a different month between both dates. If it is a different month, then return the number of times the starting date (t) had been incremented to arrive in a different month.How would i code the following theory
(...)
I tried things like date[-1] buy then i get errors of "trying to access future data"
The logic i was thinking of was something like
Month(Date) <> Month(Date[-2]) ... this gave the error of trying to access future data
Then you use only Date[0] as begin point, and workaround the "trying to access future data"-error.
Re: Trading days left in month
Well thats the challenge,
How would you check the new date, because as soon as you do date[-1] or date[t+1], your going to get the error "trying to access future data"
Your theory is the same as mine, where i am checking month of new date
hence i was using Month(date) <> Month(date[-2])
Even in your loop, as soon as you add one (t+1), and then use the Month function on that
Month(date[t+1]), your going to get "trying to access future data" error
How would you check the new date, because as soon as you do date[-1] or date[t+1], your going to get the error "trying to access future data"
Your theory is the same as mine, where i am checking month of new date
hence i was using Month(date) <> Month(date[-2])
Even in your loop, as soon as you add one (t+1), and then use the Month function on that
Month(date[t+1]), your going to get "trying to access future data" error
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Trading days left in month
I did not say use the index of `Date` to retrieve the next date. I said "add one day". That makes it a arithmetic solution that is separate from the `Date` data.Well thats the challenge,
How would you check the new date, because as soon as you do date[-1] or date[t+1], your going to get the error "trying to access future data"
Your theory is the same as mine, where i am checking month of new date
hence i was using Month(date) <> Month(date[-2])
Even in your loop, as soon as you add one (t+1), and then use the Month function on that
Month(date[t+1]), your going to get "trying to access future data" error
So I mean something like this (untested):
Code: Select all
Variables:
startingDay(0),
futureDay(0),
futureDayToDate(0);
startingDay = DateToJulian(Date);
futureDay = startingDay + 1; // add one to the date
futureDayToDate = JulianToDate(futureDay)
if (Month(Date) <> Month(futureDayToDate)) then begin
// The month of the future day differs from the starting day
end;