Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 DJ888, Yesterday, 10:57 PM
        0 responses
        6 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        158 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        7 views
        0 likes
        Last Post Belfortbucks  
        Started by zstheorist, Yesterday, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        151 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Working...
        X