• 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.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Create Chart Template with My Indicator - fail

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

    Create Chart Template with My Indicator - fail

    Hi
    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


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


    Code:
    		
                    [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); }
    		}

    Comment


      #3
      thx for the quick reply

      i checked my property list

      here is an example of one :

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

      [Browsable(false)]
      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

      Comment


        #4
        That code appears to be correct.

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

        Comment


          #5

          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

          Comment


            #6
            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

            Comment


              #7
              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.)

              Comment


                #8
                hi

                the indicator is in namespace
                NinjaTrader.NinjaScript.Indicators


                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

                thx

                Comment


                  #9
                  hi
                  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

                  Comment


                    #10
                    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

                    Comment


                      #11
                      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

                      Code:
                      [XmlIgnore]
                      public ChartBars chartBars;
                      http://ninjatrader.com/support/helpG...eattribute.htm
                      MatthewNinjaTrader Product Management

                      Comment


                        #12
                        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

                        Comment


                          #13
                          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:

                          https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
                          https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
                          MatthewNinjaTrader Product Management

                          Comment


                            #14
                            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

                            Comment


                              #15
                              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

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by lavalampmj, Today, 05:25 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post lavalampmj  
                              Started by Antares66, Today, 05:19 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Antares66  
                              Started by jmneto, Today, 05:18 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post jmneto
                              by jmneto
                               
                              Started by Bobbyj78, Today, 02:21 PM
                              2 responses
                              14 views
                              0 likes
                              Last Post bltdavid  
                              Started by EnveousColnago, Today, 02:10 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Ariana  
                              Working...
                              X