Date and Time Formatting; Day of Week - NinjaTrader Programming | futures io social day trading
futures io futures trading


Date and Time Formatting; Day of Week
Updated: Views / Replies:2,652 / 3
Created: by aventeren Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Date and Time Formatting; Day of Week

  #1 (permalink)
Patient Discipline
Bellingham, WA USA
 
Futures Experience: Beginner
Platform: NT
Broker/Data: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Favorite Futures: Futures
 
aventeren's Avatar
 
Posts: 202 since Mar 2013
Thanks: 426 given, 191 received

Date and Time Formatting; Day of Week

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

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received



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.
Reply With Quote
The following user says Thank You to Adamus for this post:
 
  #4 (permalink)
Patient Discipline
Bellingham, WA USA
 
Futures Experience: Beginner
Platform: NT
Broker/Data: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Favorite Futures: Futures
 
aventeren's Avatar
 
Posts: 202 since Mar 2013
Thanks: 426 given, 191 received


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

Reply With Quote

Reply



futures io > > > > > Date and Time Formatting; Day of Week

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Day of week edge? Tundi Commodities Futures Trading 9 May 13th, 2017 02:10 PM
(Coding Help Request) Week To Date New High/Low Indicator - Alert Nothing Done ThinkOrSwim Programming 0 May 17th, 2012 06:02 AM
SMA with Discretionary Start Time and Start Date for MC tradernovice EasyLanguage Programming 4 July 29th, 2011 07:50 PM
Formatting the Y-Axis Fat Tails NinjaTrader Programming 12 January 26th, 2011 06:32 AM
first day of the week/month - requesting last day of the week/month SARdynamite NinjaTrader Programming 3 July 15th, 2010 07:25 AM


All times are GMT -4. The time now is 04:17 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-14 in 0.09 seconds with 19 queries on phoenix via your IP 54.91.38.173