logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
lilly  
#1 Posted : Monday, April 7, 2014 6:28:13 AM(UTC)
lilly

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2005(UTC)
Posts: 17

Can someone help in creating an indicator that calculates the trading days left in month.

I want to then calculate historical returns for each day (i.e. (C/ref(c,-1)-1)*100))

Thanks
wabbit  
#2 Posted : Monday, April 7, 2014 6:57:20 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Have a look at the Life() function.

Or, you can store the number of days in each month in a variable, then test the bar date vs the days for the month; then test to find the DayOfWeek() to compute the number of trading days remaining.


lilly  
#3 Posted : Monday, April 7, 2014 7:14:31 AM(UTC)
lilly

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2005(UTC)
Posts: 17

Thank s Wabbit but I ahve no idea how to compute your suggestion.
Can you do it for me ?

wabbit  
#4 Posted : Monday, April 7, 2014 8:04:12 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Nope. Have a genuine go at doing it yourself.
lilly  
#5 Posted : Monday, April 7, 2014 9:51:23 AM(UTC)
lilly

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2005(UTC)
Posts: 17

OK so how do I store the number of days in each month in a variable?
wabbit  
#6 Posted : Monday, April 7, 2014 5:51:42 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
What codes/methods did you try?

Code:

m:=Month();
y:=Year();

leap:=Mod(y,4)=0 AND Mod(y,100)<>0 OR Mod(y,400)=0;

daysInMonth:=
If(m=2,28+leap,
If(m=4,30,
If(m=6,30,
If(m=9,30,
If(m=11,30,
31)))));

{plot}
daysInMonth;


Laisze  
#7 Posted : Tuesday, April 22, 2014 9:08:27 AM(UTC)
Laisze

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 11/18/2007(UTC)
Posts: 96
Location: HK


Something like this?

I reference this very useful indicator for my monthly market projections. Extremely accurate, it includes a list of upcoming market holidays for the next 10 years.

Two years ago metastock support told me it was not possible in MSFL, but this professional programmer had no problem doing it. Maybe one of the local metastock forum gurus could put it together for you here, Lilly.


MS Support  
#8 Posted : Tuesday, April 22, 2014 5:26:39 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,960

Thanks: 92 times
Was thanked: 155 time(s) in 150 post(s)
You could try the following to see how it works for you:

Please note that this does not factor in holidays. I am sure there would be ways to factor this in. I did not write the formula below however, this was provided by our main formula writer here.

{includes current day in the count}

m30:= Month()=4 OR Month()=6 OR Month()=9 OR Month()=11;
m31:= Month()=1 OR Month()=3 OR Month()=5 OR Month()=7 OR Month()=8 OR Month()=10 OR Month()=12;
m28:= Month()=2 AND (Mod(Year(),4)<> 0 OR Mod(Year(),100)=0);
m29:= Month()=2 AND Mod(Year(),4)=0 AND Mod(Year(),100)<>0;
mbars:= If(m30, 30, 0) + If(m31, 31, 0) + If(m28, 28, 0) + If(m29, 29, 0);


days:= mbars-(DayOfMonth()-1);
weeks:= Int((days+(DayOfWeek()-1))/7);
lastweek:= Mod(days+(DayOfWeek()-1),7);
(weeks*5) + If(lastweek>5,5,lastweek) - (DayOfWeek()-1)
wabbit  
#9 Posted : Wednesday, April 23, 2014 5:28:33 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
I'm sure Roy had no problem achieving the task; the task itself is not that difficult (interesting, but certainly not impossible) (with the exception of defining all of the non-trading holidays because they change from exchange to exchange and can change year to year) but the essence of the forum is for people to have a go at writing the code for themselves, then asking for help if they get stuck.

If the OP makes a reasonable effort and fails then asks for assistance, one of the forum members will aid the discovery of the solution.

"Give a fish... Teach to fish..."

wabbit  
#10 Posted : Wednesday, April 23, 2014 7:58:15 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
...

wabbit attached the following image(s):
weekdays.png
Laisze  
#11 Posted : Wednesday, April 23, 2014 8:37:45 AM(UTC)
Laisze

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 11/18/2007(UTC)
Posts: 96
Location: HK

The month of March 2014 had 21 trading days in the ASX, and not 20 as shown on your chart.

FAIL.


wabbit  
#12 Posted : Wednesday, April 23, 2014 8:51:02 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Before making accusations -- please check your facts.

At the close of the first bar of March on 03 Mar 2014, there were 20 trading days REMAINING, so there was a total of 21 trading days (weekdays). At the end of the bar on 01 April 2014 there were 21 weekdays REMAINING, so 22 weekdays in the month. On the last weekday of the month, the return value is zero as there are no more weekdays REMAINING.


lilly  
#13 Posted : Wednesday, April 23, 2014 9:26:13 AM(UTC)
lilly

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2005(UTC)
Posts: 17

Thank you Wabbit and all others.
I think this one has to go to Wabbit.

Kai, you should ask your husband to help you out (J...?) if is not too lazy.

lilly  
#14 Posted : Wednesday, April 23, 2014 10:32:07 AM(UTC)
lilly

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2005(UTC)
Posts: 17

And you brilliant code is ...?

wabbit  
#15 Posted : Wednesday, April 23, 2014 10:33:58 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
There have been holidays, so on the chart of TLS these are taken into account, so the lines are not always straight.

Test : MS vs Excel
Date MS weekdaysRemaining =NETWORKDAYS(A2,EOMONTH(A2,0))-1 Are they Equal? 2/12/2013 21 21 TRUE 3/12/2013 20 20 TRUE 4/12/2013 19 19 TRUE 5/12/2013 18 18 TRUE 6/12/2013 17 17 TRUE 9/12/2013 16 16 TRUE 10/12/2013 15 15 TRUE 11/12/2013 14 14 TRUE 12/12/2013 13 13 TRUE 13/12/2013 12 12 TRUE 16/12/2013 11 11 TRUE 17/12/2013 10 10 TRUE 18/12/2013 9 9 TRUE 19/12/2013 8 8 TRUE 20/12/2013 7 7 TRUE 23/12/2013 6 6 TRUE 24/12/2013 5 5 TRUE 27/12/2013 2 2 TRUE 30/12/2013 1 1 TRUE 31/12/2013 0 0 TRUE 2/01/2014 21 21 TRUE 3/01/2014 20 20 TRUE 6/01/2014 19 19 TRUE 7/01/2014 18 18 TRUE 8/01/2014 17 17 TRUE 9/01/2014 16 16 TRUE 10/01/2014 15 15 TRUE 13/01/2014 14 14 TRUE 14/01/2014 13 13 TRUE 15/01/2014 12 12 TRUE 16/01/2014 11 11 TRUE 17/01/2014 10 10 TRUE 20/01/2014 9 9 TRUE 21/01/2014 8 8 TRUE 22/01/2014 7 7 TRUE 23/01/2014 6 6 TRUE 24/01/2014 5 5 TRUE 28/01/2014 3 3 TRUE 29/01/2014 2 2 TRUE 30/01/2014 1 1 TRUE 31/01/2014 0 0 TRUE 3/02/2014 19 19 TRUE 4/02/2014 18 18 TRUE 5/02/2014 17 17 TRUE 6/02/2014 16 16 TRUE 7/02/2014 15 15 TRUE 10/02/2014 14 14 TRUE 11/02/2014 13 13 TRUE 12/02/2014 12 12 TRUE 13/02/2014 11 11 TRUE 14/02/2014 10 10 TRUE 17/02/2014 9 9 TRUE 18/02/2014 8 8 TRUE 19/02/2014 7 7 TRUE 20/02/2014 6 6 TRUE 21/02/2014 5 5 TRUE 24/02/2014 4 4 TRUE 25/02/2014 3 3 TRUE 26/02/2014 2 2 TRUE 27/02/2014 1 1 TRUE 28/02/2014 0 0 TRUE 3/03/2014 20 20 TRUE 4/03/2014 19 19 TRUE 5/03/2014 18 18 TRUE 6/03/2014 17 17 TRUE 7/03/2014 16 16 TRUE 10/03/2014 15 15 TRUE 11/03/2014 14 14 TRUE 12/03/2014 13 13 TRUE 13/03/2014 12 12 TRUE 14/03/2014 11 11 TRUE 17/03/2014 10 10 TRUE 18/03/2014 9 9 TRUE 19/03/2014 8 8 TRUE 20/03/2014 7 7 TRUE 21/03/2014 6 6 TRUE 24/03/2014 5 5 TRUE 25/03/2014 4 4 TRUE 26/03/2014 3 3 TRUE 27/03/2014 2 2 TRUE 28/03/2014 1 1 TRUE 31/03/2014 0 0 TRUE 1/04/2014 21 21 TRUE 2/04/2014 20 20 TRUE 3/04/2014 19 19 TRUE 4/04/2014 18 18 TRUE 7/04/2014 17 17 TRUE 8/04/2014 16 16 TRUE 9/04/2014 15 15 TRUE 10/04/2014 14 14 TRUE 11/04/2014 13 13 TRUE 14/04/2014 12 12 TRUE 15/04/2014 11 11 TRUE 16/04/2014 10 10 TRUE 17/04/2014 9 9 TRUE 22/04/2014 6 6 TRUE 23/04/2014 5 5 TRUE

Laisze  
#16 Posted : Wednesday, April 23, 2014 11:34:33 AM(UTC)
Laisze

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 11/18/2007(UTC)
Posts: 96
Location: HK

wabbit wrote:
There have been holidays, so on the chart of TLS these are taken into account, so the lines are not always straight.


You just don't get it - we are only counting trading days, so weekends and holidays are not part of this. Your attempt at obfuscation is irrelevant - using your own posted chart as reference, we find the following disparities:

Month - bar count - actual trading bars
Dec - 21 - 20
Jan - 21 - 21
Feb - 19 - 20
Mar - 20 - 21
Apr - 21 - 21

Although somewhat inaccurate, the code posted by MS support does a better job than yours, because they understand we are counting trading days.


MS Support  
#17 Posted : Wednesday, April 23, 2014 1:52:33 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,960

Thanks: 92 times
Was thanked: 155 time(s) in 150 post(s)
It is more precise to state that the formula I posted counts the remaining weekdays left in the month, it does not specifically identify whether there is data on these dates (since the data hasn't occurred yet), whether it is a holiday, etc.
mstt  
#18 Posted : Saturday, April 26, 2014 9:49:19 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Lily

Based on the code supplied earlier in this thread by MS Support (thank you for doing the hard part guys), I've added several modules that account for all holidays observed by the NYSE for the years 2008 through 2020. For obvious reasons I've not tested this indicator beyond the current date. Also note that there are two missing bars for my 2012 data that do not relate to normal holidays, so I've simply treated those days as holidays anyway.

This indicator is not intended for other markets, but if you required an indicator for the TSE, for example, it would an easy enough task to modify the annual holiday modules if past, present and future national holiday data was available. I hope the final forum post displays the same as the Preview I get at this point.

Hope this helps.

Roy


{Days Remaining in Month}
{2008-2020}

Q:=Input("Last Day Value, 0 or 1",0,1,0);
M:=Month();D:=DayOfWeek();
Y:=Year();A:=DayOfMonth();B:=2000;
M30:= M=4 OR M=6 OR M=9 OR M=11;
M31:= M=1 OR M=3 OR M=5 OR M=7 OR M=8 OR M=10 OR M=12;
M28:=M=2 AND (Mod(Y,4)<>0 OR Mod(Y,100)=0);
M29:=M=2 AND Mod(Y,4)=0 AND Mod(Y,100)<>0;
Mbars:=If(M30,30,0)+If(M31,31,0)+ If(M28,28,0)+If(M29,29,0);

Days:=Mbars-(A-1);
Weeks:=Int((Days+D-1)/7);
LastWeek:=Mod(Days+D-1,7);
R:=Weeks*5+If(Lastweek>5,5,LastWeek)-D+Q;

Result:=R
-(Y=B+8 AND (M=1 AND A<20 OR M=2 AND A<17 OR M=3
AND A<21 OR M=5 AND A<26 OR M=7 AND A<4 OR
M=9 AND A<1 OR M=11 AND A<27 OR M=12 AND A<25))

-(Y=B+9 AND (M=1 AND A<19 OR M=2 AND A<16 OR
M=4 AND A<10 OR M=5 AND A<25 OR M=7 AND A<3 OR
M=9 AND A<7 OR M=11 AND A<26 OR M=12 AND A<25))

-(Y=B+10 AND (M=1 AND A<18 OR M=2 AND A<15 OR
M=4 AND A<2 OR M=5 AND A<31 OR M=7 AND A<3 OR
M=9 AND A<7 OR M=11 AND A<26 OR M=12 AND A<25))

-(Y=B+11 AND (M=1 AND A<17 OR M=2 AND A<21 OR
M=4 AND A<22 OR M=5 AND A<30 OR M=7 AND A<3 OR
M=9 AND A<5 OR M=11 AND A<24 OR M=12 AND A<25))

-(Y=B+12 AND (M=1 AND A<16 OR M=2 AND A<20 OR
M=4 AND A<6 OR M=5 AND A<28 OR M=7 AND A<4 OR
M=9 AND A<3 OR M=11 AND A<22 OR M=12 AND A<25))
-2*(Y=B+12 AND (M=10 AND A<27))

-(Y=B+13 AND (M=1 AND A<21 OR M=2 AND A<18 OR
M=3 AND A<29 OR M=5 AND A<27 OR M=7 AND A<4 OR
M=9 AND A<2 OR M=11 AND A<28 OR M=12 AND A<25))

-(Y=B+14 AND (M=1 AND A<20 OR M=2 AND A<17 OR
M=4 AND A<18 OR M=5 AND A<26 OR M=7 AND A<4 OR
M=11 AND A<27 OR M=12 AND A<25))

-(Y=B+15 AND (M=1 AND A<19 OR M=2 AND A<16 OR
M=4 AND A<3 OR M=5 AND A<25 OR M=7 AND A<3 OR
M=9 AND A<7 OR M=11 AND A<26 OR M=12 AND A<25))

-(Y=B+16 AND (M=1 AND A<18 OR M=2 AND A<15 OR
M=3 AND A<25 OR M=5 AND A<30 OR M=7 AND A<4 OR
M=9 AND A<5 OR M=11 AND A<24 OR M=12 AND A<26))

-(Y=B+17 AND (M=1 AND A<16 OR M=2 AND A<20 OR
M=4 AND A<14 OR M=5 AND A<29 OR M=7 AND A<4 OR
M=9 AND A<4 OR M=11 AND A<23 OR M=12 AND A<25))

-(Y=B+18 AND (M=1 AND A<15 OR M=2 AND A<19 OR
M=3 AND A<30 OR M=5 AND A<28 OR M=7 AND A<4 OR
M=9 AND A<3 OR M=11 AND A<22 OR M=12 AND A<25))

-(Y=B+19 AND (M=1 AND A<21 OR M=2 AND A<18 OR
M=4 AND A<19 OR M=5 AND A<27 OR M=7 AND A<4 OR
M=9 AND A<2 OR M=11 AND A<28 OR M=12 AND A<25))

-(Y=B+20 AND (M=1 AND A<20 OR M=2 AND A<17 OR
M=4 AND A<10 OR M=5 AND A<25 OR M=7 AND A<3 OR
M=9 AND A<7 OR M=11 AND A<26 OR M=12 AND A<25));

{Result}
ValueWhen(1,Y>=B+8,Result);
mstt  
#19 Posted : Monday, April 28, 2014 10:33:28 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
I've placed a text file with three different versions of the "Days left in month" indicator on my website. The link is : http://www.metastocktips.co.nz/days_left_in_month.txtnt interest I'll look at other markets with a view to adding them to the text file.

Roy


[edit by wabbit : fixed url format]
Laisze  
#20 Posted : Wednesday, April 30, 2014 8:16:28 AM(UTC)
Laisze

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 11/18/2007(UTC)
Posts: 96
Location: HK


Another evolutionary effort in the right direction, but unfortunately still short of the aim to correctly count down ALL months' trading days - Roy's (red) indicator only works from 2008, which severely limits its backtesting usefulness.


Users browsing this topic
Guest (Hidden)
2 Pages12>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.