Trading days left in month

Questions about MultiCharts and user contributed studies.
rkhan
Posts: 65
Joined: 16 Mar 2014
Has thanked: 1 time
Been thanked: 2 times

Trading days left in month

Postby rkhan » 18 May 2014

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

User avatar
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

Postby JoshM » 18 May 2014

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
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.

Then you use only Date[0] as begin point, and workaround the "trying to access future data"-error.

rkhan
Posts: 65
Joined: 16 Mar 2014
Has thanked: 1 time
Been thanked: 2 times

Re: Trading days left in month

Postby rkhan » 18 May 2014

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

User avatar
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

Postby JoshM » 18 May 2014

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
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.

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;


Return to “MultiCharts”