• 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

Ninjascript generated code missing

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

    Ninjascript generated code missing

    I'm having issues getting NT8 to generate the "NinjaScript generated code. Neither change nor remove."

    I have indicators derived from one another. I also put the indicators in a subfolder under Indicators.

    I also appended to the namespace
    namespace NinjaTrader.NinjaScript.Indicators.ATS.VolumeProfi le


    In this structure there's no generated code.

    If I move the indicators to the root Indicators folder there's no generated code.

    Leaving them back in there sub-folders, if I remove the namespace appendage I get generated code but it does not compile.

    If I move the indicators back to the root Indicators folder with no namespace appendage I don't get any generated code.

    I'm attaching 2 of the indicators.

    Can you advise what is supported and why I may be getting this error?
    Attached Files

    #2
    I have more info on this. I tried to hand write the Ninjascript generated code by copying it from another indicator and changing the names as appropriate. I did this in VS 2015. It compiled fine in VS but after VS saved the file, Ninja picked up the file change and, surprisingly, it appended it's own Ninjascript generated code. The only problem with it is that the code it generated does not compile!
    Here's the code that I append to t he end of the AtsVolumeLadder.cs file that I posted earlier:
    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
       public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
       {
          private Indicators.AtsVolumeLadder[] cacheAtsVolumeLadder;
          public Indicators.AtsVolumeLadder AtsVolumeLadder()
          {
             return AtsVolumeLadder(Input);
          }
    
          public Indicators.AtsVolumeLadder AtsVolumeLadder(ISeries<double> input)
          {
             if (cacheAtsVolumeLadder != null)
                for (int idx = 0; idx < cacheAtsVolumeLadder.Length; idx++)
                   if (cacheAtsVolumeLadder[idx] != null && cacheAtsVolumeLadder[idx].EqualsInput(input))
                      return cacheAtsVolumeLadder[idx];
             return CacheIndicator<Indicators.AtsVolumeLadder>(new Indicators.AtsVolumeLadder(), input, ref cacheAtsVolumeLadder);
          }
       }
    }

    Comment


      #3
      Another update. I've been able to coax NT into leaving my manually entered NinjaScript generated code alone.
      In my previous post I showed how I got NT to start generating code, although the NT gen'd code did not compile. Picking up from there, I deleted the code I had entered manually and edited the code that NT gen'd such that it would compile. See below for that which ended up appended to the AtsVolumeLadder.cs file.

      With that in place NT was happy and I could finally construct instances of my indicator from a strategy using the AtsVolumeLadder() method. However! . See more after code block...

      Code:
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
         public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
         {
            private Indicators.AtsVolumeLadder[] cacheAtsVolumeLadder;
            public Indicators.AtsVolumeLadder AtsVolumeLadder()
            {
               return AtsVolumeLadder(Input);
            }
      
            public Indicators.AtsVolumeLadder AtsVolumeLadder(ISeries<double> input)
            {
               if (cacheIndicator != null)
                  for (int idx = 0; idx < cacheIndicator.Length; idx++)
                     if (cacheIndicator[idx] != null && cacheIndicator[idx].EqualsInput(input))
                        return cacheIndicator[idx];
               return CacheIndicator<AtsVolumeLadder>(new AtsVolumeLadder(), input, ref cacheAtsVolumeLadder);
            }
         }
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
         public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
         {
            public Indicators.AtsVolumeLadder AtsVolumeLadder()
            {
               return AtsVolumeLadder(Input);
            }
      
            public Indicators.AtsVolumeLadder AtsVolumeLadder(ISeries<double> input)
            {
               return AtsVolumeLadder(input);
            }
         }
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
         public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
         {
            public Indicators.AtsVolumeLadder AtsVolumeLadder()
            {
               return indicator.AtsVolumeLadder(Input);
            }
      
            public Indicators.AtsVolumeLadder AtsVolumeLadder(ISeries<double> input)
            {
               return indicator.AtsVolumeLadder(input);
            }
         }
      }
      
      #endregion
      Unfortunately it doesn't work at runtime.

      The problem is that in the OnStateChange OnConfigure state method of the strategy, the strategy calls
      else if (State == State.Configure)
      {
      m_indyVolumeLadderVector = AtsVolumeLadder();
      AddChartIndicator(m_indyVolumeLadderVector);
      The AtsVolumeLadder() kicks off the construction of the indicator and before that call returns the OnStateChange methods of the indicator class hierarchy is called.
      Within that call chain the indicator is referencing MasterInstrument.Instrument and it is null !!!
      It's not null when referenced in the callstack from the strategy ( tested in VS immediate window ).
      The null reference causes the strategy to not load.
      Since I already had trouble getting the NinjaScript generated code to be generated automatically, I'm really needing some help here.
      I'm now attaching the strategy.

      All my strats and indys use more source code that's in other files in the AddOns folder. YOu should be able to remove any references to that and still repro the issue as that code is not even executing. They are simple data structures and collections... that's all.
      Attached Files
      Last edited by Brillo; 10-25-2016, 08:19 PM.

      Comment


        #4
        Just to be clear: I continue to have issues with the Ninjascript generated code. My previous post contains a lot of detail (too much?) and it may appear at first glance that it's solved.

        Comment


          #5
          Hello,

          Thank you for the posts.

          I tried to import the files but do see that some of the namespaces used are missing. Do you have a version of this script that was able to compile prior to making the changes you had mentioned? If so can you revert to that version and post an Export so we could review the specific changes that cause the error with that file? Otherwise do you have a more simple example that excludes the extra logic and properties and only demonstrates the structure causing the error?

          In general manually editing the ninjascript generated portion is not supported / suggested as this process is automatic based on the file contents. I wouldn't want to continue trying to troubleshoot the manual changes with the generated code, instead If there is a case where the code is not being generated, we would need to look at the specific syntax that causes that to see if it would be expected or not. Generally you can locate the problem by working backwords until the file is able to successfully generate the region. This may entail commenting out all logic and properties and starting from scratch, then uncommenting 1 item at a time to find the cause.

          In the case you can show this in a simple example of just structure without any other properties or logic, that may be how the platform is interpreting the file and we could look further into it. Instead if you are using some specific syntax that controls this problem, we would need to look at that syntax to see what could be done or how it could be correctly structured.


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

          Comment


            #6
            Hi Jesse,

            I worked on it more and have some more info.

            I can not get the Ninjascript generated code to work in a small example indicator if I derive the indicator from any another indicator. For my example, I tried deriving a do nothing indicator from the Ninja RSI indy and no code generated. When I switch to deriving from type Indicator NinjaTrader generates the code.

            I attached the single file example. It's set to derive from RSI. Compile it. See no generated script.Change inheritance to Indicator and compile. See generated script.

            Putting this problem aside for a moment: Is the generated code actually necessary? My indicators work fine without the generated script when run. However I've been trying to use my indicator from a strategy and it is there that I have a problem.

            Since I have no generated script I can't call the constructor method that it provides. I'm not sure what that does aside from returned cache instances that match all property choices.

            To get around this my strategy is constructing my indicator using C# operator new in the OnState configure event and add it to the chart with AddChartIndicator:

            Code:
            else if (State == State.Configure)
                     {
                        m_indyVolumeLadder = new Indicators.ATS.VolumeLadder.AtsVolumeLadderSwing();
                        AddChartIndicator(m_indyVolumeLadder);
            In OnBarUpdate I call m_indyVolumeLadder.Update()

            But I have runtime problems. The indicator does not draw right away. If I refresh the chart it usually starts drawing. However the values that the indicator puts into public dictionaries are not available. The dictionaries are empty. This seems impossible since the indy draws using the same data that's in the dictionaries. And the instance used in the strategy matches the instance in the chart. I checked the GetHashCode() value of the indicator from within the indicator's code and from the strategy's reference to the indicator. It's a match.

            Maybe I have some logic problem and I'm not asking for help with that.

            I want to know at this point if the usage pattern that I'm using is something that's supported:

            The guidance from the Ninja help files on using an indicator from a strategy is to use the generated script to construct in the OnState Configure event, and also call the same method OnBarUpdate. And since I can't do that I want do know if my alternative approach is supported. Specifically -

            Is it okay to for a Strategy use construct an indicator using operator new, add it to the chart and call indy.Update() rather than use generated Ninjascript to construct and update???

            I re-sent you the full package to your email after fixing the issue with the missing namespace so you can see the entire organization.

            Kind Regards,
            Tim
            Attached Files

            Comment


              #7
              Deriving Indicators from other Indicators

              Hello Jesse,

              I got your email about the fact that it's been confirmed that this is a defect. It's good to know that it will be fixed in SFT-1704.

              we have to work around it in the mean time.

              For the community, I've found a temporary solution.
              Hand write the code that would otherwise be generated for you and put it in another file and not at the end of the indicator as it would normally be. I put mine at the end of the strategy that I use the indicator from.

              You can reference any other auto generated script, copy and past and then change the namespace, class and parameters list to match yours. It is not too difficult IMO.

              With that in place I'm able to construct and use the indicator from my strategy. The strategy can add it to a chart with AddChartIndicator.

              i have attached an example indicator, indicator factory ( containing the manually generated script ) and strategy to demonstrate. The indicator derives from RSI and the strategy uses the derived version.
              Attached Files

              Comment


                #8
                Hello,

                Thank you for the reply.

                I just wanted to comment regarding our email, I had noted that this was received as a feature request and is not scheduled for any type of fix, this is not a bug but is instead an expected behavior currently. Unfortunately inheriting from another base would not generate the wrapper code and would be expected at this point in time.

                The SFT provided is for you to track this feature request via the change log in the help guide in the case this was changed in a future release.

                Please let me know if i may be of additional assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Understood. I just hope that it gets priority. Inheritance is so useful. But as you pointed out in your email, factoring out the code into plain classes would allow me to accomplish the decomposition. It's a little more involved but manageable. Hopefully all needed props of Indicator are public access.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by manugarc, Today, 01:15 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post manugarc  
                  Started by JMont1, Today, 11:42 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post JMont1
                  by JMont1
                   
                  Started by Steve L, Yesterday, 10:04 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Steve L
                  by Steve L
                   
                  Started by marianfed, Yesterday, 09:47 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post marianfed  
                  Started by hir04068, Yesterday, 09:29 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post hir04068  
                  Working...
                  X