How to obtain trading day of month (not calendar day)

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

How to obtain trading day of month (not calendar day)

Postby rkhan » 13 May 2014

Hi Guys,

I have a strategy where i may want to buy the emini sp at say the 9th trading day of the month.

Now

DayOfMonth(Date) will give me calendar day, so how can i make a function which does not count weekends, and hence gives me trading day of month

Thanks
Riz

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: How to obtain trading day of month (not calendar day)

Postby arnie » 13 May 2014

Hi Guys,

I have a strategy where i may want to buy the emini sp at say the 9th trading day of the month.

Now

DayOfMonth(Date) will give me calendar day, so how can i make a function which does not count weekends, and hence gives me trading day of month

Thanks
Riz

There are two functions that might help you achieve your goals, LastDateOfMonth and LastWorkDayOfMonth

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

Re: How to obtain trading day of month (not calendar day)

Postby rkhan » 13 May 2014

Arnie,

Thanks for your reply, where can i get help on these functions, because i checked the EasyLanguage reference and these functions are not in that reference guide.

Is there another reference guide which you are using?

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

Re: How to obtain trading day of month (not calendar day)

Postby rkhan » 13 May 2014

The functions you have listed dont seem to exist,

I've even tried to type them into the code, and they are not recognised, are you using some special library or something?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How to obtain trading day of month (not calendar day)

Postby TJ » 13 May 2014

Hi Guys,
I have a strategy where i may want to buy the emini sp at say the 9th trading day of the month.
Now
DayOfMonth(Date) will give me calendar day, so how can i make a function which does not count weekends, and hence gives me trading day of month
Thanks
Riz
The best way to do it is to set up a counter...

1. reset the counter to zero (0) when a new month begins.
2. increment the counter on each new day on the chart.
3. when the counter=9, you have found your 9th trading day.

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

Re: How to obtain trading day of month (not calendar day)

Postby rkhan » 13 May 2014

TJ

What your saying can be achieved by just using the dayofmonth(Date) function

What I want is trading days (so excluding weekend).

So although it might be the 9th calendar day of the month this may only be 6th or 7th trading day of month

OZ Trade
Posts: 39
Joined: 08 Nov 2013
Has thanked: 11 times
Been thanked: 18 times

Re: How to obtain trading day of month (not calendar day)

Postby OZ Trade » 14 May 2014

Rough concept:

Code: Select all


Var: Counter (0);

If month(date) <> month(date) [1] then Counter= 1;

If sessionlastbar then Counter= Counter +1;

If Counter= 9 then begin

............
............
............

End;
Should work for intraday and daily bar charts..

Sessions need to be configured correctly in QuoteManager..

OZ Trade
Posts: 39
Joined: 08 Nov 2013
Has thanked: 11 times
Been thanked: 18 times

Re: How to obtain trading day of month (not calendar day)

Postby OZ Trade » 14 May 2014

Correction.. previous only works well for intraday..

Concept for daily bars:

Code: Select all


Var: Counter (0);

If month(date) <> month(date) [1] then Counter= 0;

If date <> date [1] then counter= counter +1;

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

Re: How to obtain trading day of month (not calendar day)

Postby rkhan » 14 May 2014

Hi Oztrade

I was thinking something similar, but what is the loop for the counter ?

While dayofmonth < dayofmonth [1]?

OZ Trade
Posts: 39
Joined: 08 Nov 2013
Has thanked: 11 times
Been thanked: 18 times

Re: How to obtain trading day of month (not calendar day)

Postby OZ Trade » 14 May 2014

When counter=9 you are on the ninth trading day of the month with either intraday or daily bars using the following:

Code: Select all


Var: Counter (0);

If bartype=1 then begin

If month(date) <> month(date) [1] then Counter= 1;

If sessionlastbar then Counter= Counter +1;

End;

If bartype=2 then begin

If month(date) <> month(date) [1] then Counter= 0;

If date <> date [1] then counter= counter +1;

End;
Maybe even an easier way.. can easily complete your signal using this though

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: How to obtain trading day of month (not calendar day)

Postby furytrader » 14 May 2014

RKhan, there is no loop for the counter - or, to put it more accurately, because this code is run for every bar, the "loop" is the number of bars you have on your chart.


Return to “MultiCharts”