how to know next trading day's date?  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
rokanten
Posts: 48
Joined: 29 Jul 2010
Location: south korea
Has thanked: 15 times

how to know next trading day's date?

Postby rokanten » 01 Oct 2019

hi

i'm trying to do some seasonal trading.
what i need to get is that next trading day's date.

for example,

there's saturday and sunday between 6.28 friday and 7.1 monday.
so how can i get date information of 7.1 monday when i am on 6.28 friday?
is there any function for this other than date[-3]?

and if there's holiday, then i need to skip one more day,
and i can't find how to do that.

regards.

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: how to know next trading day's date?  [SOLVED]

Postby rrams » 01 Oct 2019

Greetings rokanten,
You have to add a variable for every holiday. You can hard code this year's day and month for every holiday or you can do it the difficult way and lookup online the formula to calculate the day of the holiday for any year. For instance, in the U.S., markets are closed for Thanksgiving holiday so we can eat a large flightless bird in celebration.

The formula for this would be:

Code: Select all

// Add Thanksgiving holiday 4th Thursday in November
vars: TH(28-Mod(Floor(4+YearFromDateTime(ComputerDateTime)*5/4), 7)),
Add another variable for next trading day's date and do all date arithmetic in Julian format:

Code: Select all

// First convert today's date to Julian and add one.
TD(DateToJulian(CurrentDate)+1); // tomorrow's date in Julian
Now check for that Thanksgiving day holiday and if so add 1 day then check if weekend:

Code: Select all

if Month(JulianToDate(TD))=11 and DayOfMonth(JulianToDate(TD))=TH then TD=TD+1;
// Last check if next day is weekend add more days until Monday
switch(DayOfWeek(JulianToDate(TD)))
begin
case 0: TD=TD+1; { Sunday add 1 days }
case 6: TD=TD+2; { Saturday add 2 days }
end;
print("Next trading day is: ", FormatDate("M/d/y", ELDateToDateTime(JulianToDate(TD))));

User avatar
rokanten
Posts: 48
Joined: 29 Jul 2010
Location: south korea
Has thanked: 15 times

Re: how to know next trading day's date?

Postby rokanten » 13 Oct 2019

to rrams
i've been working for some other project and i saw your reply so late.
i wish there's some other convinient way other than hard code, but thanks for your reply :)


Return to “MultiCharts”