Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enumerators, Folders and error in auto Generated Code.

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

    Enumerators, Folders and error in auto Generated Code.

    This test indicator compiles, but I cannot get it to compile it when I place it in a folder.

    And precisely:
    If I place it in the namespace GG, then Ninjatrader changes the line of its namespace into "NinjaTrader.NinjaScript.Indicators.GG" which is ok.

    But then it doesn't compile because apparently the Ninja Generated Code forgets to specify that the class is in the namespace GG of NinjaTrader.NinjaScript.Indicators.

    I figured out that the offending line in the Ninja Generated Code is triggered by the enumerator being placed in the namespace NinjaTrader.NinjaScript namespace.

    It seems to me that I have to place the enumerator in this namespace because it has to be seen globally and also by the cache of MarketAnalyzerColumns and Strategies

    The error is "The type or namespace name "AATest could not be found" in the indicator cache section.

    Can someone clarify?
    Best
    G


    On the Ninja generated code at line 50 it says. GG is missing !
    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private AATest[] cacheAATest;
            public AATest AATest(AATest2Tag colorBars)
            {
    ​



    I attached it as a zip but the code is here also: This code compiles correctly
    Code:
    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    
    namespace NinjaTrader.NinjaScript
    {
        public enum AATest2Tag
        {
            Neither = 0, Body = 1, Outline = 2, BodyAndOutline = 3
        }
    }
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class AATest : Indicator
        {
    
            protected override void OnStateChange()
            {
                switch (State)
                {
                    case State.SetDefaults:
                        Name = "AATest";
                        Description = "AATest";
                        break;
    
                    case State.DataLoaded:
                        break;
                 }
            }
    
            protected override void OnBarUpdate()
            {
            }
    
        [NinjaScriptProperty]
        [Display(Name = "ColorBars", Description = "", GroupName = "Plot Colors", Order = 1)]
        public AATest2Tag ColorBars { get { return this.colorBars; } set { this.colorBars = value; } }  //{  get; set ;  }
        private AATest2Tag colorBars = AATest2Tag.Neither;
        }
    }

    The code once moved into the GG folder becomes as follows and does not compile !
    Code:
    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    
    namespace NinjaTrader.NinjaScript
    {
        public enum AATest2Tag
        {
            Neither = 0, Body = 1, Outline = 2, BodyAndOutline = 3
        }
    }
    
    namespace NinjaTrader.NinjaScript.Indicators.GG
    {
        public class AATest : Indicator
        {
    
            protected override void OnStateChange()
            {
                switch (State)
                {
                    case State.SetDefaults:
                        Name = "AATest";
                        Description = "AATest";
                        break;
    
                    case State.DataLoaded:
                        break;
                 }
            }
    
            protected override void OnBarUpdate()
            {
            }
    
        [NinjaScriptProperty]
        [Display(Name = "ColorBars", Description = "", GroupName = "Plot Colors", Order = 1)]
        public AATest2Tag ColorBars { get { return this.colorBars; } set { this.colorBars = value; } }  //{  get; set ;  }
        private AATest2Tag colorBars = AATest2Tag.Neither;
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private AATest[] cacheAATest;
            public AATest AATest(AATest2Tag colorBars)
            {
                return AATest(Input, colorBars);
            }
    
            public AATest AATest(ISeries<double> input, AATest2Tag colorBars)
            {
                if (cacheAATest != null)
                    for (int idx = 0; idx < cacheAATest.Length; idx++)
                        if (cacheAATest[idx] != null && cacheAATest[idx].ColorBars == colorBars && cacheAATest[idx].EqualsInput(input))
                            return cacheAATest[idx];
                return CacheIndicator<AATest>(new AATest(){ ColorBars = colorBars }, input, ref cacheAATest);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.AATest AATest(AATest2Tag colorBars)
            {
                return indicator.AATest(Input, colorBars);
            }
    
            public Indicators.AATest AATest(ISeries<double> input , AATest2Tag colorBars)
            {
                return indicator.AATest(input, colorBars);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.AATest AATest(AATest2Tag colorBars)
            {
                return indicator.AATest(Input, colorBars);
            }
    
            public Indicators.AATest AATest(ISeries<double> input , AATest2Tag colorBars)
            {
                return indicator.AATest(input, colorBars);
            }
        }
    }
    
    #endregion
    ​
    Attached Files
    Last edited by giogio1; 10-10-2024, 02:25 AM.

    #2
    Hi giogio1,

    Please remove the namespace 'NinjaTrader.NinjaScript' and place the enum 'AATest2Tag' outside the 'NinjaTrader.NinjaScript.Indicators.GG' namespace.

    I hope this helps to solve your problem.

    Regards,
    William
    ninZa
    NinjaTrader Ecosystem Vendor - ninZa.co

    Comment


      #3
      Hello giogio1,

      I agree the enum declaration should be moved a custom namespace declared below the indicator class block.
      Use the fully qualified namespace to reference the enum.

      The SampleUniversalMovingAverage reference sample provides sample code.


      If this does work, I recommend you comment out all public variables and then move the script to the folder, compile, then uncomment the public variables.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Yes, both solutions are correct,thank you!.
        Yes, in the sleep I thought that the namespace had to be moved after the indicator block because likely the Ninjatrader Code Generation probably uses the first one. I consider it a minor imperfection, it should use the one of the indicator itself. All good then.

        Chelsea, I do not understand the purpose of comment out and uncomment the public variables. Can you clarify? Thank you.
        Giovanni

        Comment


          #5
          Hello Giovanni,

          Sometimes the overload generator becomes stale when changing public properties.
          Commenting out the public properties then compiling, can often allow the auto generated code to generate correctly.
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          581 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          338 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X