NexusFi: Find Your Edge


Home Menu

 





Date and Time Formatting; Day of Week


Discussion in NinjaTrader

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




 
Search this Thread

Date and Time Formatting; Day of Week

  #1 (permalink)
 
aventeren's Avatar
 aventeren 
Bellingham, WA USA
 
Experience: Beginner
Platform: NT
Broker: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Trading: Futures
Posts: 202 since Mar 2013
Thanks Given: 428
Thanks Received: 202

Howdy All--

I've built myself an indi that when a trade occurs, it prints various things about the trade to several lists, that I then print out to the output window for use in Excel.

I'm currently using the following code to add the date and time of the trade:

 
Code
listDate.Add(ToDay(Time[0]));
listTime.Add(ToTime(Time[0]));
Which in turn output:

20130907 (ie, 09/07/2013)
155759 (ie, 3:57:59p)

I was curious if anyone had a slick way of formatting the above code to format the outputs accordingly:

ToDay(Time[0]) --> mm/dd/yyyy --> EX: 9/7/2013 (ie, not 09/07/2013)
ToTime(Time[0]) --> hh:mm am/pm --> EX: 11:15 am or 2:13 pm (ie, no seconds and not 02:13 pm)

Also, I was curious if anyone knew of a way to grab the day of week from the Time[0] property.

Finally, I would need to know what list type the newly formatted items would be (ie, int, double, string). For instance, ToDay() and ToTime() are current lists of type int, but would the newly formatted lists be of type string? Also, would the weekday list be a type string?

I know, pretty boring stuff, but I appreciate your help if you have the time.

Thanks for your help!

Aventeren

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Exit Strategy
NinjaTrader
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789



aventeren View Post
Howdy All--

I've built myself an indi that when a trade occurs, it prints various things about the trade to several lists, that I then print out to the output window for use in Excel.

I'm currently using the following code to add the date and time of the trade:

 
Code
listDate.Add(ToDay(Time[0]));
listTime.Add(ToTime(Time[0]));
Which in turn output:

20130907 (ie, 09/07/2013)
155759 (ie, 3:57:59p)

I was curious if anyone had a slick way of formatting the above code to format the outputs accordingly:

ToDay(Time[0]) --> mm/dd/yyyy --> EX: 9/7/2013 (ie, not 09/07/2013)
ToTime(Time[0]) --> hh:mm am/pm --> EX: 11:15 am or 2:13 pm (ie, no seconds and not 02:13 pm)

Without checking (i.e. it might need adjusting - I'm not sure if "m" is for minute or month), you need something like this:

 
Code
DateTime myDate = Time[0];  // DateTime type
string prettyDate = myDate.ToString("M/d/yyyy"); //string type
//or something like this:
Print("My time is " + myDate.ToString("hh:mm"));
There are lots of different ways of doing this and using "yyyy-MM-dd HH:mm" is my favourite, but there are some named shortcuts which are simpler. Just google "c# DateTime format pattern yyyy" or similar.


aventeren View Post
Also, I was curious if anyone knew of a way to grab the day of week from the Time[0] property.

It's a function of DateTime class - something like

 
Code
DateTime myDate = Time[0];  // DateTime type
int day = myDate.DayOfWeek; // DayOfWeek type


aventeren View Post
Finally, I would need to know what list type the newly formatted items would be (ie, int, double, string). For instance, ToDay() and ToTime() are current lists of type int, but would the newly formatted lists be of type string? Also, would the weekday list be a type string?

I know, pretty boring stuff, but I appreciate your help if you have the time.

As you say, this is really run-of-the-mill stuff. The Microsoft online documentation is great for simple reference like this. Just google "c# DateTime DayOfWeek" and you should see a link to the MSDN libraries in the first few search results, which will give you explanations and examples and links to other functionality in this area.

You can discover what your enemy fears most by observing the means he uses to frighten you.
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
aventeren's Avatar
 aventeren 
Bellingham, WA USA
 
Experience: Beginner
Platform: NT
Broker: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Trading: Futures
Posts: 202 since Mar 2013
Thanks Given: 428
Thanks Received: 202


Adamus View Post
Without checking (i.e. it might need adjusting - I'm not sure if "m" is for minute or month), you need something like this:

 
Code
DateTime myDate = Time[0];  // DateTime type
string prettyDate = myDate.ToString("M/d/yyyy"); //string type
//or something like this:
Print("My time is " + myDate.ToString("hh:mm"));
There are lots of different ways of doing this and using "yyyy-MM-dd HH:mm" is my favourite, but there are some named shortcuts which are simpler. Just google "c# DateTime format pattern yyyy" or similar.



It's a function of DateTime class - something like

 
Code
DateTime myDate = Time[0];  // DateTime type
int day = myDate.DayOfWeek; // DayOfWeek type



As you say, this is really run-of-the-mill stuff. The Microsoft online documentation is great for simple reference like this. Just google "c# DateTime DayOfWeek" and you should see a link to the MSDN libraries in the first few search results, which will give you explanations and examples and links to other functionality in this area.

Thanks, Adamus; I figured out a slick way to do it, and perhaps this will help other users in the future.

I had been adding dates to the trade list, which I had initially created as an int type list, by:

listDate.Add(ToDate(Time[0]));

However, what that did was created a yyyymmdd format (ie, 20130910), which wasn't very useful. A little googling revealed that I could instead create the list as a string type list, and then use:

listDate.Add(Time[0].ToShortDateString());

The above then formatted the dates as mm/dd/yyyy format (ie, 9/10/2013), which is what I was after.

Also, although I ended up binning my trades using the C# hhmmss format as the logical reference, I understand that the onboard C# DateTime Method has a similar way to clean up the time formatting via:

listTime.Add(Time[0].ToShortTimeString());

--although it should be noted that I did not try the time formatting.

So in any event, perhaps other users will find this interesting if they are working on a similar problem in the future.

All best,

Aventeren

Started this thread Reply With Quote




Last Updated on September 10, 2013


© 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