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

BUG custom enum prevents saving a chart as a template

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

    BUG custom enum prevents saving a chart as a template

    I have a simple code, where I put a custom enum in a namespace, the code compiles. Then I add the indicator to a generic chart and save as a template

    the Log says
    21/03/2023 14:33:33 Default Could not save indicator 'bbb:' There was an error generating the XML document.

    what is going on? I took the tip to put the enum like this from this video
    Part II that covers making your new indicator the way you want the properties to appear. We also talk about how to finish the implementation of an enumerate...


    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    using bbb_ENUM;
    #endregion
    
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace bbb_ENUM
    {
    public enum enum_test
    {
        test_1=1,
        test_2=3,
    }
    }
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class bbb : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "bbb";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = false;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                //Add your custom indicator logic here.
            }
    
            #region Properties
    
    
     [NinjaScriptProperty]
                         [Display(Name="KOP", Description="weweKOP", Order=9, GroupName="IOOIUOIUI")]
     public enum_test KOP
     {get; set;}
            #endregion
    
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private bbb[] cachebbb;
            public bbb bbb(enum_test kOP)
            {
                return bbb(Input, kOP);
            }
    
            public bbb bbb(ISeries<double> input, enum_test kOP)
            {
                if (cachebbb != null)
                    for (int idx = 0; idx < cachebbb.Length; idx++)
                        if (cachebbb[idx] != null && cachebbb[idx].KOP == kOP && cachebbb[idx].EqualsInput(input))
                            return cachebbb[idx];
                return CacheIndicator<bbb>(new bbb(){ KOP = kOP }, input, ref cachebbb);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.bbb bbb(enum_test kOP)
            {
                return indicator.bbb(Input, kOP);
            }
    
            public Indicators.bbb bbb(ISeries<double> input , enum_test kOP)
            {
                return indicator.bbb(input, kOP);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.bbb bbb(enum_test kOP)
            {
                return indicator.bbb(Input, kOP);
            }
    
            public Indicators.bbb bbb(ISeries<double> input , enum_test kOP)
            {
                return indicator.bbb(input, kOP);
            }
        }
    }
    
    #endregion
    ​

    #2
    Hello alanlopen,

    As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript Add-on...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm

    Then you would be able to just include the few lines of code in interest in the post and attach the export without having to put the code of the entire script in the post and require others to copy and paste and a make a new script.


    Below I am providing a link to the reference sample in the help guide on enums.



    Have you set a value for the KOP?

    Note, you should be setting a default value for any public property in the State.SetDefaults of OnStateChange().

    Testing on my end, I am seeing after selecting a value, a template for this script saves, and restores without issue.

    Below is a link to a video of the test.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes I do not set a default value because in my code, even though the public property is outside the precompiler directives I use for the particular instance of the indicator I want, the initiliazation of this public property is not relevant for the code when I activate the precomipler directive.


      Also in your video, you sav the template for the settings of the indicator. The template i am talking about is the Chart template, ie you right click on a chart after adding the indicator and save the template.

      Comment


        #4
        Hello alanlopen,

        If the value is not set, then the value is null. You cannot save a null value in xml. You have to select a value.

        Set a default.

        Can you reproduce with a default value set?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          it is fine with a default value

          Comment


            #6
            Try this.

            Since your enum is defined in a separate Namespace (which is
            a very good idea) try using the fully qualified enum name when
            that enum is used as a public property type,

            That is, change this code,

            public enum_test KOP
            {get; set;}​


            to this,

            public bbb_ENUM.enum_test KOP
            {get; set;}​



            Despite 'using bbb_ENUM;' a fully qualified name can prevent
            a lot of Xml serialization issues when defining public properties,
            especially if you're compiling this into an external assembly, say,
            with Ninja's own 'export' feature.

            The corollary is, if it's not a public property, I don't bother to fully
            qualify the custom enum -- too much unnecessary typing -- I just
            rely on the 'using' statement for everything but public properties.

            Last edited by bltdavid; 03-26-2023, 10:50 AM.

            Comment


              #7
              Btw, the massive delay with email notification of new threads (I'm subscribed
              to the Indicator Development forum) is still present.

              I just now saw this thread via an email sent to me by the forum software, and
              I have responded in my own real time -- but, I'm still 5 days late for the OP.

              Why are emails from the forum subscription still arriving so late?

              This all started with the new 8.1 rollout, I think others noticed this, too.

              Is this problem still happening?
              Is anyone else seeing this issue?
              Last edited by bltdavid; 03-26-2023, 10:22 AM.

              Comment


                #8
                Originally posted by bltdavid View Post
                Btw, the massive delay with email notification of new threads (I'm subscribed
                to the Indicator Development forum) is still present.
                It definitely is still broken. I have learned to just ignore the forum notifications because they come in every day and it's always for something days ago. That is not my email or a delay on my side - all of my other emails arrive and work perfectly.

                Bruce DeVault
                QuantKey Trading Vendor Services
                NinjaTrader Ecosystem Vendor - QuantKey

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by alifarahani, Today, 09:40 AM
                3 responses
                15 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by RookieTrader, Today, 09:37 AM
                4 responses
                18 views
                0 likes
                Last Post RookieTrader  
                Started by PaulMohn, Today, 12:36 PM
                0 responses
                5 views
                0 likes
                Last Post PaulMohn  
                Started by love2code2trade, 04-17-2024, 01:45 PM
                4 responses
                40 views
                0 likes
                Last Post love2code2trade  
                Started by junkone, Today, 11:37 AM
                3 responses
                26 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X