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

information on serializing indicators

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

    information on serializing indicators

    Hello Support,

    I've developed some indicator. When I attached it to a chart, seems all work, but when I shut down the platform it says me about some error.

    Next time when I open the platform there is no my indicator attached to the chart. I looked into the log and foun the following entry

    Indicator 'NinjaTrader.Indicator.ntScreens' could not be serialized. Please refer help for more information on serializing indicators.

    I've looked through the help, but found nothing about serializing indicators.

    Please, help!

    Regards.

    #2
    Hello alex_bbfg,

    Thank you for writing in.

    Are you utilizing any user defined color inputs in your indicator?

    Some additional extra code that is required for creating a color input is to serialize the color. Serialization is necessary for NinjaTrader to use the color input throughout the program. Please note that serialization is a general concept not exclusive to color inputs. There may be other struct/classes (e.g. TimeSpan) that you could use in your code that would also need to have their "value" properties serialized.

    I would suggest taking a look at this post on our support forum detailing further about serialization: http://ninjatrader.com/support/forum...38&postcount=1

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Hello ZacharyG,

      thank you for the help.

      You know a have the script of more then 1300 code lines. I use Color objects and work with dates, but I used them in the same way in others of my script and there are no such problem.

      Is there any way to catch what can not be serialised? I have no idea how to find the objact.
      My I send my script to you for examination.

      Regards.

      Comment


        #4
        Hello,

        Thank you for the reply.

        While you could send in the script for us to look at, it would be best for you to find the error yourself as to prevent it going forward in the future. Additionally our support does not offer debugging services so in general we would not be able to debug your entire script to find the error. If you can instead limit the code to just the properties causing the error, I could certainly review those specific properties to check the syntax.

        To locate this error, you would likely need to look at each individual property that is a complex object like a DateTime, Color, or custom object that would need to be serialized. Simple objects like double, int, bool can all be serialized without adding any other logic.

        If the property is complex and should be saved with the workspace, you need to manually serialize it like colors: http://ninjatrader.com/support/forum...38&postcount=1

        For other objects which may need to be hidden from serialization, you would need to add [XmlIgnore] to the property to prevent it from being serialized.

        There is no easy way I am aware of for error checking properties aside from going through and verifying the serialization attributes are correct for each property.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          thank you for the help.

          My this code can help to catch the Exception. Where it should use?

          try
          {
          }
          catch (Exception ex)
          {MessageBox.Show(ex.Message);

          Regards.

          Comment


            #6
            Hello,

            I would not suggest using try/catch at all in NinjaScript as often this will suppress exceptions you would want to still see.

            Again the primary way to really locate a problem with a Property would be to inspect each of the properties you created and make sure they are completely correct. You can also try to check the Documents\NinjaTrader 7\trace files to look for exceptions related to this, if there is any additional information it would be there.

            One process you could try would be to comment out the code you have in OnBarUpdate, Initialize, or any of the other override methods. Next comment out all of the properties, basically just make the script a shell.

            Now uncomment one property and any associated variables or logic it may require and test the script to see if you have the serialization error. You can likely bypass simple properties like bool, string, int, double and focus on other items like Colors, DateTimes or other complex types.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello Jesse,

              thank you for the reply. Here is my script Properties region

              #region Properties

              #endregion

              no any custom variable

              but I look through the trace file and I've found the following

              2016-02-06 14:02:01:253 Gui.Chart.ChartControl.SaveToXml: indicator=NinjaTrader.Indicator.ntScreens: System.InvalidOperationException: Возникла ошибка при отражении типа "NinjaTrader.Indicator.ntScreens". ---> System.InvalidOperationException: Возникла ошибка при отражении поля "label1". ---> System.InvalidOperationException: Возникла ошибка при отражении типа "System.Windows.Forms.Label". ---> System.InvalidOperationException: Не удается сериализовать член "System.ComponentModel.Component.Site" типа "System.ComponentModel.ISite". Дополнительные сведения см. во внутреннем исключении. ---> System.NotSupportedException: Невозможно сериализовать член System.ComponentModel.Component.Site типа System.ComponentModel.ISite, т.к. он является интерфейсом.

              also there was exceptions about my datagridview1 control in the script.

              Regards.

              Comment


                #8
                If any of your properties use something other than these primitive types,
                • int
                • double
                • bool
                • string
                • enum types

                then chances are good that it needs to be serialized.

                The point is: simple properties defined using simple primitive types don't need any special code for serialization. Conversely, almost all other properties (ie, complex properties of some class type) will need extra code for serialization.

                The classic examples of properties with class types that need serialization are,
                • Color
                • Font
                • Pen

                but almost any property with any class type most certainly needs serialization.

                Comment


                  #9
                  ok.

                  What is the Property?

                  Is it a variable defined in Properties region or any veriable which I create in my script?

                  Comment


                    #10
                    Originally posted by alex_bbfg View Post
                    ok.

                    What is the Property?

                    Is it a variable defined in Properties region or any veriable which I create in my script?
                    Aiyeeh ... sorry.

                    Those questions imply a greater lack of C# knowledge than I first thought.

                    Can you attach your script?

                    [If you wish not to reveal the logic, create a copy of the your indicator with critical methods (such as OnBarUpdate) removed, and attach that instead.]

                    Comment


                      #11
                      the script is attached

                      it connects to database
                      string conStr = "Data Source=\"C:\\Users\\alex.bbfg\\Documents\\NinjaTra der 7\\db\\NinjaTrader.sdf\"";

                      you have to change the line for the script works

                      thank you for any help
                      Attached Files

                      Comment


                        #12
                        I've installed the script & references (changed it to point to my own NinjaTrader.sdf file)
                        and everything compiled fine.

                        As you eluded to in a prior post, you don't seem to have any properties in this indicator. Yep, none at all.

                        Let me try to reproduce your error, but I don't want to shutdown NT just yet ... will investigate asap when my trading day is over.

                        Btw, I do apologize, it looks to me this script shows a higher level of development skill than I was expecting. If you lack knowledge of specifics of .NET programming in C# regarding properties, this can be easily rectified.

                        My suggestions:



                        Will reply again shortly.

                        Comment


                          #13
                          Try changing these variables,

                          Code:
                                  public System.Windows.Forms.Label label1;
                                  public System.Windows.Forms.Label label2;
                                  public System.Windows.Forms.Label label3;
                                  public System.Windows.Forms.Label label4;
                                  public System.Windows.Forms.Label datelabel1;
                          to private.

                          Comment


                            #14
                            now it works

                            thank you very much.

                            I am autodidact of C# coding, just google code examples and use them in my way. the more I code the more theoretical knowledge required))

                            thanks again!

                            Comment


                              #15
                              Originally posted by alex_bbfg View Post
                              now it works

                              thank you very much.

                              I am autodidact of C# coding, just google code examples and use them in my way. the more I code the more theoretical knowledge required))

                              thanks again!
                              You're welcome. Self taught is hard won knowledge!

                              Let me help you a bit. See this:


                              The first link is this one:
                              Serialization converts an object into a form that can be transported. This article provides an overview of XML serialization and the XmlSerializer class.


                              Which states "XML serialization serializes only the public fields and property values of an object into an XML stream."

                              That is why you had to change those fields from public to private (to avoid having them subject to XML serialization, which apparently causes an error).

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              942 views
                              0 likes
                              Last Post spwizard  
                              Started by Max238, Today, 01:28 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by rocketman7, Today, 01:00 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post rocketman7  
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              28 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, 02-22-2024, 01:11 AM
                              5 responses
                              33 views
                              0 likes
                              Last Post wzgy0920  
                              Working...
                              X