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

Strategy template does not save value

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

    Strategy template does not save value

    Hi I have this parameter in strategy

    Code:
            [Display(ResourceType = typeof(Custom.Resource), Name = "Session A Begin", GroupName = filterTradingTimeGroup, Order = filterTradingTimeOrder + 2)]
            [Description("Počáteční čas seance")]
            public TimeSpan FilterTTSessionABegin {
                get { return tFilterTTSessionABegin; }
                set { tFilterTTSessionABegin = value; }
            }
    ​
    when i try to save template of strategy it does not save value. Do I have to do some serialization or why is that?
    Thanks for help
    Paul

    #2
    Do you get an error message in the Ninja log window?

    You could also try looking directly in the log file, by going
    into the 'log' folder and using notepad to look at the most
    recent log file with today's date.

    In fact, check the 'trace' folder, sometimes error messages
    show up there.

    The newest error messages would be at the bottom, since
    NinjaTrader just appends log/trace messages as it goes.

    My point is:
    The answer to your question about needing to do serialization
    is something you can answer yourself if you see such error
    messages inside the log and/or trace file.

    -=o=-

    Xml serialization is pretty easy. As an experiment to see if
    the error goes away, why not try it?

    Comment


      #3
      Hello kujista,

      Thank you for your post.

      A TimeSpan may not be Xml serialized in the same way as other types, so you could use a simple type against the TimeSpan to serialize it, just like the example at the bottom of the following page:
      Brushes are another type that may not be serialized directly into the .xml file. For more details that serve as an additional explanation of this concept and how it works, please see the following links:Please let us know if we may be of further assistance.
      Emily C.NinjaTrader Customer Service

      Comment


        #4
        Don't use the TimeSpan example in the first link.

        That code is clumsy and incorrect.

        Or, to put it another way, it creates really stupid code
        in the automatic 'generated' magic code section.

        -=o=-

        Here is the correct way NinjaTrader's TimeSpan Xml
        serialization example should have been coded,

        Code:
        [XmlIgnore] // cannot serialize type of TimeSpan, use the BeginTimeSpanSerialize object to persist properties
        [NinjaScriptProperty]
        [Display(Name = "Begin TimeSpan", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
        public TimeSpan BeginTimeSpan
        { get; set; }
        
        [Browsable(false)] // prevents this property from showing up on the UI
        public string BeginTimeSpanSerialize
        {
            get { return BeginTimeSpan.ToString(); }
            set { BeginTimeSpan = TimeSpan.Parse(value); }
        }​

        Comment


          #5
          Emily, you should submit a bug report and have the example code
          on that help page corrected.

          Comment


            #6
            Originally posted by kujista View Post
            why is that?
            A good question.

            The answer can be difficult to grasp, for newbies and intermediate
            programmers alike. Even experienced programmers may not be that
            familiar with the big picture. To help our discussion, let's make one up.

            What I'm about to explain is unique from my brain to yours. I've never
            seen it explained this way -- so, I hope it makes sense.

            Let's start with this graphic ...

            [To continue reading, see attached file.]
            Attached Files
            Last edited by bltdavid; 04-27-2023, 05:07 PM.

            Comment


              #7
              Originally posted by bltdavid View Post
              What I'm about to explain is unique from my brain to yours. I've never
              seen it explained this way -- so, I hope it makes sense.
              Very nice. Good job with this.
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #8
                Originally posted by bltdavid View Post
                Emily, you should submit a bug report and have the example code
                on that help page corrected.
                Hello bltdavid,

                Thank you for your feedback and for pointing out the error. The example in the help guide has now been edited:
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Emily View Post
                  Thank you for your feedback and for pointing out the error. The example in the help guide has now been edited:
                  https://ninjatrader.com/support/help...yattribute.htm
                  You sure?
                  I've used Chrome and Firefox, cleared cache on both.

                  With regards to the TimeSpan example,

                  1. The [Browsable[false] attribute needs to be moved to the bottom property,
                  aka, the BeginTimeSpanSerialize property.

                  2. The [NinjaScriptProperty] and the [Display(...)] property need to be
                  moved to the top property, which is the BeginTimeSpan property.

                  Do you agree with these corrections?

                  My point is:
                  I'm pretty sure my suggested corrections are, in fact, correct.
                  But I don't yet see these corrections reflected on that help page.

                  Comment


                    #10
                    Hello bltdavid,

                    I apologize for the confusion and miscommunication.

                    The edit has been submitted pending review; it has not been reflected yet in the help guide but it should be resolved in the near future.
                    Emily C.NinjaTrader Customer Service

                    Comment


                      #11
                      Ah-hah!

                      Ok, thanks for letting me know

                      Comment


                        #12
                        Hi thanks for help, i have problem when i add serialization to existing fielad it does not work.. is there some cache or do I have to do some magic?

                        Comment


                          #13
                          Does not work how?
                          No, there is no cache.

                          Did you try this?
                          Open NinjaScript editor, then open the indicator file
                          in question, make a very small change such as adding
                          a comment, recompile (the small change will force the
                          indicator in the editor window to get new magic code
                          at the bottom), then exit Editor, exit NT, restart NT,
                          in brand new chart, load indicator, try to save chart
                          template, get any errors? If not, open new chart,
                          load new chart template (with indicator embedded),
                          do you get any errors when chart is created?

                          Fastest option:
                          Just post your code, let us take a look at it.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by strategist007, Today, 07:51 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post strategist007  
                          Started by StockTrader88, 03-06-2021, 08:58 AM
                          44 responses
                          3,968 views
                          3 likes
                          Last Post jhudas88  
                          Started by rbeckmann05, Today, 06:48 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post rbeckmann05  
                          Started by rhyminkevin, Today, 04:58 PM
                          4 responses
                          58 views
                          0 likes
                          Last Post dp8282
                          by dp8282
                           
                          Started by iceman2018, Today, 05:07 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post iceman2018  
                          Working...
                          X