Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Time span values not saved when restarting
Collapse
X
-
Hello Conceptzx,
Thank you for reaching out.
Is the automated strategy you are working with, a strategy coded by yourself using the Strategy Builder, or was it acquired from a 3rd party?
If it is your own coded strategy, please contact our engineering team at
[email protected]
and they will be able to guide you in this matter.
If it is a 3rd party strategy, you would want to contact the developer for assistance with their software.
Please let us know if you have any other questions.Erick P.NinjaTrader Customer Service
-
Thanks for your patience.Originally posted by Conceptzx View PostIt's coded by myself. Is there a way I can retain the settings, or at least get them to go back to what's defined as default within the strategy?
I have moved this thread to the Strategy Development topic in the forum rather than Platform Technical Support. In the future, if you are requesting NinjaScript support for scripts that you have developed, please be sure to post in one of the development topics for the most timely and accurate assistance. Thank you for your understanding.
With that said, I suspect there is an issue happening with the serialization of your TimeSpan inputs. A TimeSpan object may not be serialized normally, so you must make some changes in the Properties region of your script to ensure the values will be saved and restored properly from either the default values within State.SetDefaults or a saved template of the strategy/workspace. First, you must include the XmlIgnore attribute:
Then, you must use a simple type with the NinjaScriptProperty attribute. The final example on this page demonstrates serialization of a TimeSpan input:
This page covers serialization of brush colors that are user inputs, though the same ideas apply when using other object types that may not be serialized normally like TimeSpans:
Please let us know if we may be of further assistance.
Comment
-
Not quite; please see the following example I mentioned from the NinjaScriptProperty Attribute page:Originally posted by Conceptzx View PostSo something like this?
Code:[XmlIgnore] [Display(Name = "Trade End Time HH:mm:ss", Order = 2003, GroupName = "02.0. Time")] public TimeSpan TradeEndTime { get { return tradeEndTime; } set { tradeEndTime = value; } }
Thanks for your time and patience.Code:[XmlIgnore] // cannot serialize type of TimeSpan, use the BeginTimeSpanSerialize object to persist properties [Browsable(false)] // prevents this property from showing up on the UI public TimeSpan BeginTimeSpan { get; set; } // users will configure this "string" as the TimeSpan which will be set as a TimeSpan object used in data processing [NinjaScriptProperty] [Display(Name = "Begin TimeSpan", GroupName = "NinjaScriptStrategyParameters", Order = 1)] public string BeginTimeSpanSerialize { get { return BeginTimeSpan.ToString(); } set { BeginTimeSpan = TimeSpan.Parse(value); } }
Comment
-
Converting the TimeSpan object to a string is the idea behind Serialization. In an XML template, such as the workspace file or a strategy template file, a TimeSpan does not save properly due to its type. That is why you must use XmlIgnore on the TimeSpan object itself. Strings, however, do save into an XML template properly. By converting the TimeSpan object into a "string" it can be serialized when you save a template/workspace, and then when that template or workspace is opened again the string object gets converted back into its TimeSpan counterpart. The whole idea and explanation about why this is necessary is mentioned in the help guide resources I shared with you and yes, there is a sample script that serializes brush color inputs on the following page:Originally posted by Conceptzx View PostDo you have an example script that contains this?
The way you showed would require me to change the time span definitions to strings? Is there a better method for defining time frames?
The same idea behind serializing brushes, which can not be saved as-is into an XML document, applies to serializing TimeSpan objects and other objects that are not a simple type which saves into an XML file without issues.
Thank you for your time and patience.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
54 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
72 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment