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

Using SimpleFont as UserInput not saving in profiles?

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

    Using SimpleFont as UserInput not saving in profiles?

    howdy.

    So I've created a simplefont object, as a variable, and turned it into a user input. It works fine, but for some reason, it won't save under a template. So when reopening a template, it reverts back to its default value.

    I am wondering if I am doing something wrong here.

    At the class level, I declare a variable like this:

    Code:
    private SimpleFont                         myTextFont                     = new NinjaTrader.Gui.Tools.SimpleFont("Impact", 20);

    In my onRender() block, I create a text format via:
    Code:
    SharpDX.DirectWrite.TextFormat textFormat = myTextFont.ToDirectWriteTextFormat();


    In my properties section, I capture that user input via:
    Code:
    [XmlIgnore]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Text Type", Description = "", GroupName = "Parameters", Order = 0)]
    public SimpleFont MyTextFont
    {
    get {return myTextFont;}
    set {myTextFont = value;}
    }

    Is there something obvious I'm missing here? Is it due to me only manipulating this text layout in onRender(), that it just never gets stored anywhere? Does this somehow need to be initialized, or created in the state.configure block?

    #2
    Hello forrestang, thanks for your post.

    This SimpleFont public property works fine in my test script:

    Code:
    NinjaTrader.Gui.Tools.SimpleFont largeFont;
    
    [NinjaScriptProperty]
    [Display(Name="Large Font", Description="Font Size", Order=1, GroupName="Font")]
    public SimpleFont LargeFont
    {
        get{return largeFont;}
        set{largeFont = value;}
    }
    I attached my test script. Could you load this up and compare the differences between your custom script?

    Please let me know if I can assist any further.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post

      I attached my test script. Could you load this up and compare the differences between your custom script?

      Please let me know if I can assist any further.
      Thank you for the help. It looks like my issue was this bit of code...

      What I originally had was this:
      Code:
      [COLOR=#c0392b][XmlIgnore][/COLOR]
      [Display(ResourceType = typeof(Custom.Resource), Name = "Text Type", Description = "", GroupName = "Parameters", Order = 0)]
      public SimpleFont MyTextFont
      {
      get {return myTextFont;}
      set {myTextFont = value;}
      }

      What you have, and what I changed it to was this:
      Code:
      [COLOR=#c0392b][NinjaScriptProperty][/COLOR]
      [Display(ResourceType = typeof(Custom.Resource), Name = "Text Type", Description = "", GroupName = "Parameters", Order = 0)]
      public SimpleFont MyTextFont
      {
      get {return myTextFont;}
      set {myTextFont = value;}
      }

      I don't really understand what those two pieces do(the xmlignore vs ninjascriptproperty)... but that seems to be what was stopping the property from being saved in templates or workspaces?

      Also... I didn't set anything in state==state.setdefaults the way you did... but I changed that to match yours... but again, that didn't seem to be what was stopping it from being saved.

      Comment


        #4
        Hello forrestang, thanks for the follow up.

        It was the [XmlIgnore] property decorator that was causing the template to not save this property, sorry for not catching that in the first post. [XmlIgnore] means it will not save to workspace and template XML files.

        I initialized the font object in State.SetDefaults so the object gets initialized and is displayed in the property grid.

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kulwinder73, Today, 10:31 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by RookieTrader, Today, 09:37 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by terofs, Yesterday, 04:18 PM
        1 response
        24 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by CommonWhale, Today, 09:55 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Gerik, Today, 09:40 AM
        2 responses
        8 views
        0 likes
        Last Post Gerik
        by Gerik
         
        Working...
        X