• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Create Chart Template with My Indicator - fail

  • Filter
  • Time
  • Show
Clear All
new posts

    Create Chart Template with My Indicator - fail

    When I try to make a chart template with my indicator in it I get the following message :
    Could not save indicator 'Ace:' There was an error reflecting type 'NinjaTrader.NinjaScript.Indicators.Ace'.
    The template is created but without my indicator

    source of indicator will be sent in mail to ninja support

    If you have any non-serializable properties, you will get the problem you describe, unless you apply the [XmlIgnore] attribute to the property. Example:

                    [Display(Name = "Some Brush-valued property:", 
    		Description = "A property whose type is not serializable.", 
    		GroupName = " Preferences>Colors", 
    		Order = 1)]
    		[XmlIgnore]			// <========= IMPORTANT: Indicator will not work correctly unless this is included in front of any Brush property
            public Brush SomeBrush
                get { return someBrush; }
                set { someBrush= value; }
    		[Browsable(false)]	// this line prevents the property from being displayed in the indicator properties dialog, do not remove
    		public string SomeBrushSerialize
    			get { return Serialize.BrushToString(SomeBrush); }
    			set { SomeBrush= Serialize.StringToBrush(value); }


      thx for the quick reply

      i checked my property list

      here is an example of one :

      [Display(Name = "ColorUp", Description = "General up Color", Order = 26, GroupName = "Parameters")]
      public System.Windows.Media.Brush ColorUp
      { get; set; }

      public string ColorUpSerializable
      get { return Serialize.BrushToString(ColorUp); }
      set { ColorUp = Serialize.StringToBrush(value); }

      Do you see any problem in above definition ?

      btw this definition was created by ninja indicator wizard

      Any how , source of my code was sent to support


        That code appears to be correct.

        Were all of the properties of your indicator generated by the wizard?



          rehi strategesis
          i think almost all parameters were generated by wizard except one

          any how i removed all brush parameters from indicator and the problem remain

          indicator is called BB now

          i send you in mail the source


            hi again

            I made another test in order to verify if the problem is related to to properties definition as follows:
            i created a new indicator with the wizard
            i copied all my properties from "old indicator" and added them to the new and fresh indicator
            i added the new indicator with the properties to a chart and succeeded to save a chart template

            i conclude the the problem does not relate to the properties


              I just realized that the error message says "There was an error reflecting type 'NinjaTrader.NinjaScript.Indicators.Ace'."

              I had misread/misinterpreted that to mean something else. But it refers to a problem with reflection.

              In what namespace does your indicator reside? It should be in the namespace NinjaTrader.NinjaScript.Indicators. If it's not, that might be your problem. If it is, I would try removing and reinstalling NT8 from scratch (be sure to save your source code.)



                the indicator is in namespace

                the source of the indicator was sent to support
                ( i can send it again if needed )

                can someone test this in your side

                just import it and save template



                  I found the problem

                  If i define a variable at indicator level

                  ChartBars chartBars;

                  The indicator can not be saved as template

                  this is obviously a bug - please correct it

                  i suggest that you verify that the same problem does not relates to other NT8 objects/variables


                    well as i suspected the problem exist for more variables or reasons

                    i fully proved that probelm exist for ChartBars chartBars;

                    and problem disappears when this command does not exist

                    but still other things prevent to save a chart with indicator as template


                      There are always going to be objects which cannot be serialized.

                      I reviewed your script and see that you have a public chart bars object. If you're using that to communicate with other scripts which is why it is public, you should add [XmlIgnore] since there is no property that is being persisted on the UI level

                      public ChartBars chartBars;
                      MatthewNinjaTrader Product Management


                        thank you

                        the addition of [XmlIgnore]

                        really solved the problem

                        i understand that this attribute should be used while declaring brush as part of properties of indicator.

                        In what other cases this attribute should be used and why

                        What is the effect of using it

                        I suggest that when creation of chart template fail - add to the error message the name of the first property that cause the problem

                        It is very very difficult to find it


                          When you save an indicator to a chart either via a workspace file, or in a chart template, it saves all of the public properties from the indicator via an XML file.

                          There are complex objects like Brushes, ChartObjects, or even .NET types like TimeSpan which cannot be serialized like a simple type of string or int, etc. These are just a few examples and you need to take precautions if you're using these publicly.

                          When you add XmlIgnore you're telling the XML Serializer to skip that property and not save it into the workspace or template file.

                          There is no reasonable way we can catch that and modify your code at run time. You need to be aware of what objects you're using publicly and handled them as necessary.

                          More information on this .NET concept can be found here:

                          MatthewNinjaTrader Product Management


                            i did not suggested to correct or modify the code at run time
                            i suggested that when creation of chart template fail - add to the error message the name of the first property that cause the problem.
                            or at least add explain in the message what might cause the problem

                            you can not imagine how much time it took me to identify the problem


                              I have logged a feature request so that we can begin to track user demand to provide information about this type of exception when it is caught and handled, so that developers can see exactly what is causing the unexpected results when this particular issue arises. The request is traced with ID # SFT-930.
                              Dave I.NinjaTrader Product Management


                              Latest Posts


                              Topics Statistics Last Post
                              Started by lavalampmj, Today, 05:25 PM
                              0 responses
                              Last Post lavalampmj  
                              Started by Antares66, Today, 05:19 PM
                              0 responses
                              Last Post Antares66  
                              Started by jmneto, Today, 05:18 PM
                              0 responses
                              Last Post jmneto
                              by jmneto
                              Started by Bobbyj78, Today, 02:21 PM
                              2 responses
                              Last Post bltdavid  
                              Started by EnveousColnago, Today, 02:10 PM
                              1 response
                              Last Post NinjaTrader_Ariana