Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do i serialize a Stroke public property?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How do i serialize a Stroke public property?

    I have created a public property to hold a stroke but am unable to serialize it. Can anyone help with this?

    Code:
    [Display(Name="Outline", GroupName="Rectangles", Order = 2)]
    public Stroke rectOutlineStroke
    { get; set; }
    I tried this but i get an error:

    Code:
    [XmlIgnore()]
    [Display(Name="Outline", GroupName="Rectangles", Order = 2)]
    public Stroke rectOutlineStroke
    { get; set; }
    [Browsable(false)] //prevents this property from showing up on the UI
    public string rectOutlineStrokeSerializable
    {
    get { return Serialize.PenToString(rectOutlineStroke); }
    set { rectOutlineStroke = Serialize.StringToPen(value); }
    }

    #2
    Hello trendisyourfriend,

    Thank you for your post.

    Strokes do not need to be serialized - with Strokes, you will be using our own implementation (NinjaTrader.Gui.Stroke), and we are doing our own serialization logic on its properties under the hood, so no helper method is needed in this specific case.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello trendisyourfriend,

      Thank you for your post.

      Strokes do not need to be serialized - with Strokes, you will be using our own implementation (NinjaTrader.Gui.Stroke), and we are doing our own serialization logic on its properties under the hood, so no helper method is needed in this specific case.

      Please let us know if we may be of further assistance to you.
      Thanks, i appreciate your prompt help.

      Not related to this subject but would appreciate your opinion on this, i have seen cases where some add "ResourceType = typeof(Custom.Resource)" in the Display attribute:

      [Display(ResourceType = typeof(Custom.Resource),...]

      I have not found a definition for this. Is there any reason for doing this?
      Last edited by trendisyourfriend; 04-08-2021, 09:38 AM.

      Comment


        #4
        Hello trendisyourfriend,

        Thank you for your reply.

        The custom resources are used for internal strings in the platform and are not for assignment. These should generally not be used in your own files. You will see these in stock indicators properties and names, but items you may find online may contain them as well. Using invalid resource names can lead to performance impacts so it would be a good idea to just use a string instead.

        For example, this would be invalid because MyPeriod is not a custom resource:

        Code:
        [Display(ResourceType = typeof(Custom.Resource), Name = "MyPeriod", GroupName = "NinjaScriptParameters", Order = 0)]
        public int MyPeriod {get;set;}
        Instead, you can remove the resource type all together:

        Code:
        [Display(Name = "MyPeriod", GroupName = "NinjaScriptParameters", Order = 0)]
        public int MyPeriod {get;set;}
        Another example would be in file naming. These would be valid for the SMA, because they provide a string for the Description and Name specifically for the SMA:

        Code:
        if (State == State.SetDefaults)
        {
        Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionSMA;
        Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameSMA;
        }
        For a custom item, you would instead use a string:

        Code:
        if (State == State.SetDefaults)
        {
        Description = "Some Description";
        Name = "MyCustomName";
        }
        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        566 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X