NexusFi: Find Your Edge


Home Menu

 





Creating a Time Zone drop down property


Discussion in NinjaTrader

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




 
Search this Thread

Creating a Time Zone drop down property

  #1 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505

Dunno if it's already been posted, but anyways here's what you can do to add a Time Zone property on your indy, using Linq and TypeConverters

1. Add System.Linq namespace
 
Code
using System.Linq;

2. Add TypeConverter class

 
Code
public class TZListConverter : TypeConverter
{
	public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
	{
		return true;
	}
	
	public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
	{
		return new StandardValuesCollection((TimeZoneInfo.GetSystemTimeZones()).Select(x=>x.DisplayName).ToList());
	}
}

3. Add a TimeZoneInfo element that will hold your selected Time Zone
 
Code
TimeZoneInfo tzi=TimeZoneInfo.Local;

4. Add your property
 
Code
[Description("Time Zone")]
[Category("User defined values")]
[Gui.Design.DisplayNameAttribute("Time Zone")]
[TypeConverter(typeof(TZListConverter))]
public string TZI
{
	get
	{
		return tzi.StandardName;
	}
	set
	{
		tzi = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault<TimeZoneInfo>(x=>((x.DisplayName==value)||(x.StandardName==value)));
	}
}

5. Done


6. And it serializes correctly !

Started this thread Reply With Quote




Last Updated on October 11, 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