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

NT7 to NT8 Hilbert Sinewave Indicator Conversion

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

    NT7 to NT8 Hilbert Sinewave Indicator Conversion

    I've been converting some indicators from NT7 to NT8. I'm currently stuck on this one and perhaps some fresh eyes and better brain can help me identify the issue.

    I've run through and changed all the code. The file now compiles. I can run it on a chart but nothing shows on the chart and I get an Output error:
    Indicator '____John Elhers SineWave-NT8': Error on calling 'OnBarUpdate' method on bar 3: Object reference not set to an instance of an object.

    I've identified the general area of the error in the code but can't find a solution. I've commented it in green in the code (if (CurrentBar < 3) return ; ///////THIS SEEMS TO BE RELATED TO THE ERROR)

    The indicator should paint support and resistance lines on the chart plus a crossover sinewave in the second panel.

    I also can't get the plots to show up in the Properties of the indicator. (to select color, type and size of plot line). I've compared it to another indicator that does work but am stumped.

    I've included the indicator code for whomever has the time to help. Would really appreciate it.
    Attached Files

    #2
    Hello fling_wing,

    Thank you for writing in and welcome to the NinjaTrader Support Forum!

    I would highly suggest taking a look at the NinjaTrader 8 help guide's Code Breaking Changes section as there have been code breaking changes between NinjaTrader 7 and 8: http://ninjatrader.com/support/helpG...ng_changes.htm

    It doesn't look like you are properly initializing your Series within State.Configure. You'll need to do this in order to use them within your logic and not get an Object reference not set to an instance of an object error.

    Example:
    Code:
    private Series<double> Smooth;
    private Series<double> Cycle;
    // additional series below
    
    protected override void OnStateChange()
    {
         if (State == State.SetDefaults)
         {
              // State.SetDefaults logic
         }
    }
         else if (State == State.Configure)
         {
              Smooth = new Series<double>(this);
              Cycle = new Series<double>(this);
              // additional series below
         }
    }
    I would suggest taking a look at the Series section of the help guide for information on this: http://ninjatrader.com/support/helpG...s/?seriest.htm

    Adding plots should be done in State.SetDefaults. This will allow your plots to be customized from within the Indicators menu.

    For information about the different states, I would suggest taking a look at the help guide at this link: http://ninjatrader.com/support/helpG...tatechange.htm

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Hi Zachary,
      Thanks for getting back to me.
      I've made the changes to State.SetDefaults and State.Configure plus moved the AddPlot to the State.SetDefaults section. I get the second panel now but the chart and panel are blank.

      I've looked through the Code Breaking Changes page at great length but am struggling to tie down what specifically is causing the issue.
      I am usually used to indicators not Compiling and then finding the error but in this case the indicator Compiles just fine, it just spits out the error in the Output Window: Object reference not set to an instance of an object.

      Could it be something in the Properties section where 'method' is set and method is ending up as null and hence erroring in the switch(method)?
      [XmlIgnore()]
      [NinjaScriptProperty] [Display(Name = "Sine Method",
      Description = "Determines what method to use when calculating the sine.",
      GroupName = "Parameters", Order = 0)]
      public NinjaTrader.NinjaScript.Indicators.__HilbertSinewa ve.SineWaveCRSMethodEnum Method
      {
      get { return method; }
      set { method = value; }
      }

      [Browsable(false)]
      public String MethodSerialize
      {
      get { return method.ToString(); }
      set { method = (SineWaveCRSMethodEnum)Enum.Parse(typeof(SineWaveC RSMethodEnum), value, true); }
      }
      This indicator runs fine in NT7 (which it was written for). I know the problem is staring me in the face but I I'm struggling to target in on the error.

      Comment


        #4
        Hello fling_wing,

        In my quick debug test, you are getting the "Object reference not set to an instance of an object" because you are attempting to assign a value to a Series that has not yet been initialized.

        I have made the changes I have specified in my previous post and am able to get the plots to appear within the Indicators window as well as have the indicator plot on your chart without issue.

        Is this not the case on your end?
        Attached Files
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Thanks, Zachary.
          It would seem that 'thickhead' here put a { in the wrong place with regard to the State.Configure section. Sometimes I wonder! I had starred at that for an hour or more after you made the suggestions and I made the changes.
          Like you suggested, reading the 'State' section for NT8 and having a better understanding of it would have helped me track that down.
          So yep, it now works. Thank you so much for helping out with that.

          I have another query. What's the best way to use another indicators output ie: Plot or a Yaxis double and use it in another indicator?

          In my case I've tried using:
          OtherIndicatorName.Plot[0];
          and have also tried:
          OtherIndicatorName.YaxisVariable;
          but that doesn't work either.
          I receive this error:
          "An object reference is required for the non-static field, method, or property 'NinjaTrader.NinjaScript.Indicators.OtherIndicator Name.YaxisVariable"

          Do I need to declare the same variable in this indicator as in the other one providing the output? If so, where should that be?

          Many thanks.

          Comment


            #6
            Hello fling_wing,

            You'll need to make sure you create an instance of the indicator you wish to access values from before being able to use its values within another script.

            I've created two sample scripts: TestIndicator is the indicator to call values from, TestIndicator2 is the indicator trying to pull values from TestIndicator.
            Attached Files
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              G'day Zachary,
              Thanks for that example. Unfortunately it throws an error when it's Compiled.
              I've attached a screen shot of it.
              Attached Files

              Comment


                #8
                Hello fling_wing,

                Please take a look at the NinjaScript File column shown in the errors.

                This is referring to a TestStrategy.cs script, not the scripts I have provided.

                I would suggest removing the script or resolving the compile errors for that particular script.

                Note that all scripts are compiled when you compile one script.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Zachary,
                  That's why working on this stuff is not a good idea at 3am

                  Your examples work great. But once I apply them to the indicators I have, there is an error. In your code you don't have (or need) overloads in your "ti = TestIndicator()" part of the code. When I put mine in there it asks for them- of course they would because my OuputIndicator has them.
                  So I think this is where my error is. I input them as per the Ninjatrader help (mouse hover over the Indicator name) but I think the problem comes when it asks for the 'enum' variables that are in the other indicator Properties section.
                  Running a Print() on the ti = TestIndicator() but my version (swi = __MyIndicator(overload,overload, overload,overload,overload); has the overloads jumbled up and taken from the first switch() case list buried in the main code rather than the public declared variable in the Properties section.

                  The indicators Compile fine but the output window says:
                  Indicator '__OutputIndicator': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.
                  swi.TestPlot[0]: 2043
                  swi.YAxis: 0

                  Indicator '__InputIndicator': Error on calling 'OnBarUpdate' method on bar 1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
                  The swi.TestPlot[0] and swi.YAxis are supposed to print out on every OnBarUpdate like your examples do but it only gets as far as the first bar.
                  I'm assuming I have to declare the 'overloads' in the InputIndicator but am not sure and if they must be, or where to put them. I've already tried various versions.

                  I've tried Print() on just the YAxis but that is 0 in the Output window. Is it not making the journey from the Output Indicator to the Input Indicator?

                  I'm using the indicator I posted on here earlier plus another one just like your TestIndicator2 to receive the data and print to the Output window.
                  Eventually, once the data can travel between the two indicators I will drag out specific data and print to a second indicator panel instead of the output window.

                  Thanks again for your time and help.

                  Comment


                    #10
                    Ok, I fixed the error. It was nothing to do with those items I listed below.
                    I just had to add:
                    if(CurrentBar <1) return;
                    at the top of the OnBarUpdate. The errors then disappeared. I presume the code needed more than 0 bars to work?
                    Will leave my post below as all this rambling may help someone else in the future.

                    I am still working on bringing variables from the Output Indicator to the Input Indicator to be used in logic checking etc. However, I can't get some variables to make the journey across.

                    Comment


                      #11
                      Hello fling_wing,

                      Can you please clarify what issues you are running into?
                      Zachary G.NinjaTrader Customer Service

                      Comment


                        #12
                        Add a try catch block to OnBarUpdate and see if the HilbertSinewave will plot.

                        Trying to develop indicators without including error handlers is nuts.

                        After getting it to plot you can figure out what the error is being caused by. If necessary add more try catch blocks until you can isolate the error.

                        I will take a look at it.

                        Fortunately you started with the only NT7 version of the sine wave that I know of that is correct.

                        Regards,

                        Zondor
                        Last edited by Ricam; 04-09-2016, 11:54 PM.

                        Comment


                          #13
                          It took me all of ten minutes to fix it. Lots of useless tail chasing here and ultimately much ado about nothing. There were other problems besides the bar filtering. Plus, the use of series double objects to hold such small numbers of values is very wasteful when arrays can be used.

                          Every NT8 indicator starts backfilling at CurrentBar -1, which causes problems more often than not.

                          Didn't finish fixing the feature that prints the backfill time to the Output window, you can do that as homework.
                          Attached Files
                          Last edited by Ricam; 04-10-2016, 12:24 AM.

                          Comment


                            #14
                            Zonda,
                            Excellent, I believe you contributed to this NT7 indicator back when? Indeed, I chose it because it is the closest to Barry Taylors, Better Sinewave which is true to Elhers. Yes, I trade with his indicators.

                            You are a whiz of greatness, a whole 10 mins. I wish I had the expertise to create and fix code like you- alas, I do not. So I ask questions, sometimes they seem dumb to an expert like you, however, it's all part of the joy of learning something.

                            With Zachary's assistance I've managed to move on from the stages you mention and have it all working just fine. Thanks for your input too. I did indeed use try/catch to assist in the later stages.
                            Yes, some "tail chasing", but I learnt something and perhaps my ramblings will help someone else in the future. Searching for NT solutions in Google often bring up these forum threads, so future troubled folks might benefit.

                            I did make a change to the 'Dot' sine wave lines however. I found the Draw.Text using the Windings font made the chart choppy when scrolling. So I changed them to Plots instead and that fixed the choppy scrolling.
                            I had to make two indicators though as I wanted Plots on the price panel and also the sine wave plots in panel 2. Unless there is a way in NT8 to drive Plots to two different panels from the same indicator I'll have to stick with the two. Is it possible to achieve this?
                            I had to change OnBarUpdate < 1 instead of -1 as the Sinewave indicator didn't plot.

                            Thank you for your input.

                            Comment


                              #15
                              Sine Wave further cleanup

                              It was really messed up so I put some more time into fixing it. Note that the name has been changed.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              44 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              180 views
                              0 likes
                              Last Post jeronymite  
                              Started by DanielSanMartin, Yesterday, 02:37 PM
                              2 responses
                              13 views
                              0 likes
                              Last Post DanielSanMartin  
                              Working...
                              X