Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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:
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
Can you help answer these questions from other members on NexusFi?
Without checking (i.e. it might need adjusting - I'm not sure if "m" is for minute or month), you need something like this:
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
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
DateTime myDate = Time[0]; // DateTime type
int day = myDate.DayOfWeek; // DayOfWeek type
aventeren
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.
Broker: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Trading: Futures
Posts: 202 since Mar 2013
Thanks Given: 428
Thanks Received: 202
Adamus
Without checking (i.e. it might need adjusting - I'm not sure if "m" is for minute or month), you need something like this:
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
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.