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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by max333, Today, 02:22 AM
        2 responses
        6 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by mnbowursw, Today, 02:59 AM
        0 responses
        2 views
        0 likes
        Last Post mnbowursw  
        Started by ndimtyry, Today, 02:50 AM
        0 responses
        1 view
        0 likes
        Last Post ndimtyry  
        Started by cincai, Today, 12:55 AM
        3 responses
        11 views
        0 likes
        Last Post cincai
        by cincai
         
        Started by cincai, Today, 12:51 AM
        1 response
        11 views
        0 likes
        Last Post s.kinra
        by s.kinra
         
        Working...
        X