NexusFi: Find Your Edge


Home Menu

 





How to obtain the day of year and the week of year in EasyLanguage


Discussion in EasyLanguage Programming

Updated
    1. trending_up 1,555 views
    2. thumb_up 7 thanks given
    3. group 3 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

How to obtain the day of year and the week of year in EasyLanguage

  #1 (permalink)
futurenow
Earth planet
 
Posts: 49 since Feb 2017
Thanks Given: 38
Thanks Received: 13

Hello

I need help to have a way to get the number of day of the year (1-365) and also the number of week of the year (1-53) in EasyLanguage, because as I can see it seems the language doesn’t come with these 2 built-in functions and I can’t find examples about it.


About the day of year, for now the closest I’ve gotten is to work at the same time with the month of year and the day of month `Month(Date) = n1 And DayOfMonth(Date) = n2` that is a two step process that I think this could be done in a more efficient and direct way, like maybe defining a starting date of the year and adding the n days needed, to in this way to go to a specific day of the year, but I haven’t found how to cover the situation to have the year not specified, i.e. in a general way that works for any year, where for example maybe you only specify a Jan fixed date (YYYY0101) as starting point and then adding n days to that date, but this working in a general way for any year.


Anyways, this is just an idea because those who are more familiar with EasyLanguage maybe have other ways to get this and other alternatives are more than welcome.


And about the week of the year I haven’t found much information, but as with the day of the year calculation, the idea is to get this in an efficient way that keeps the logic running as smooth as possible


Thank you in advance for the help!

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Increase in trading performance by 75%
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
36 thanks
Tao te Trade: way of the WLD
24 thanks
Spoo-nalysis ES e-mini futures S&P 500
20 thanks
Bigger Wins or Fewer Losses?
19 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #2 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,384
Thanks Received: 10,206

Haven't tested this but this should work
 
Code
Var: Day(0), Week(0);

If intportion(DATE/10000) <> intportion(DATE[1]/10000) then Day = 0;
if DATE <> DATE[1] then Day = Day + 1;
If DayOfWeek(DATE) < DayOfWeek(DATE[1]) then Week = Week + 1;
If intportion(DATE/10000) <> intportion(DATE[1]/10000) then Week = 1;

Reply With Quote
Thanked by:
  #3 (permalink)
futurenow
Earth planet
 
Posts: 49 since Feb 2017
Thanks Given: 38
Thanks Received: 13



SMCJB View Post
Haven't tested this but this should work
 
Code
Var: Day(0), Week(0);

If intportion(DATE/10000) <> intportion(DATE[1]/10000) then Day = 0;
if DATE <> DATE[1] then Day = Day + 1;
If DayOfWeek(DATE) < DayOfWeek(DATE[1]) then Week = Week + 1;
If intportion(DATE/10000) <> intportion(DATE[1]/10000) then Week = 1;


About the Week, it seems to work OK.

But about the Day, I can see it skips the weekends/holidays, what maybe was the purpose, but, would it be possible to take into account every calendar day of the year including weekends/holidays, where for example yesterday Sunday Feb 12, 2023 was the day 43, and today is the day 44, ...

Thank you @SMCJB for your time!

Reply With Quote
  #4 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,384
Thanks Received: 10,206

I had assumed (incorrectly) you wanted a trading day count not a calendar day count.

Using Calendar Day makes calculating week easier. Haven't tested this but this should work
 
Code
Var: Day(0), Week(0);

If intportion(DATE/10000) <> intportion(DATE[1]/10000) then Day = 0;
if DATE <> DATE[1] then Day = Day + DATE - DATE[1];
Week = intportion(Day/7) + 1;

Reply With Quote
Thanked by:
  #5 (permalink)
futurenow
Earth planet
 
Posts: 49 since Feb 2017
Thanks Given: 38
Thanks Received: 13


SMCJB View Post
Using Calendar Day makes calculating week easier. Haven't tested this but this should work
 
Code
Var: Day(0), Week(0);

If intportion(DATE/10000) <> intportion(DATE[1]/10000) then Day = 0;
if DATE <> DATE[1] then Day = Day + DATE - DATE[1];
Week = intportion(Day/7) + 1;


Thank you @SMCJB, but I made some tests and I see this other solution doesn't calculate the calendar day or the week number.

For example, for today Feb 15, it shows Day = 8985 and Week = 1284, so maybe it could be some consideration not applied to the calculation.

Reply With Quote
  #6 (permalink)
TurtleInTheSky
Minneapolis
 
Posts: 2 since Feb 2021
Thanks Given: 0
Thanks Received: 1

Use Datetojulian

Reply With Quote
Thanked by:
  #7 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,384
Thanks Received: 10,206

Thank You @TurtleInTheSky your right need to use Datetojulian.
Problem was
 
Code
if DATE <> DATE[1] then Day = Day + DATE - DATE[1];
worked for most days but when the month changed (ie 1230131 to 1230201) it was adding 70 odd to the day count and not 1 etc!

This definitely works. (Have tested it).
 
Code
Var: DayNum(0), WeekNum(0);

if DATE <> DATE[1] then DayNum = DayNum + Datetojulian(DATE) - Datetojulian(DATE[1]);
If intportion(DATE/10000) <> intportion(DATE[1]/10000) then DayNum = dayofmonth(DATE);
WeekNum = intportion(DayNum/7) + 1;
Note I changed the variable names to avoid conflicts with reserved words.

Reply With Quote
Thanked by:
  #8 (permalink)
futurenow
Earth planet
 
Posts: 49 since Feb 2017
Thanks Given: 38
Thanks Received: 13

Now it is getting correct values.

Thank you for your time and for the help @SMCJB

Reply With Quote




Last Updated on February 16, 2023


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts