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

AddHeikenAshi Method generates error in Market Analyzer

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

    AddHeikenAshi Method generates error in Market Analyzer

    Hi,

    I have the following code in one of my indicators that I load into Market Analyzer:

    Code:
    else if (State == State.Configure)
    {
         AddHeikenAshi(this.Instrument.FullName, BarsPeriodType.Minute, BarsPeriod.Value, MarketDataType.Last);                
    }
    I get the following message when I load the indicator from a Market Analyzer window:

    "Indicator 'Signal': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object."

    #2
    Hello maltese,

    If you are getting the error when using specifically this line of code it is likely expected. The error is noting that something being used is null, this could relate to the variables you are using in the adding of data. We have a note about using variables with adding of data in the AddDataSeries page:


    Arguments supplied to AddDataSeries() should be hard coded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error...
    I would suggest to remove the variables you have used, replace them with hard coded values and then remove the column/re apply the column to test.

    If the problem is not specifically related to what you provided, the error just indicates something used was null. You could look for any objects you use in OnStateChange and check if they are null using a Print.

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

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello maltese,

      If you are getting the error when using specifically this line of code it is likely expected. The error is noting that something being used is null, this could relate to the variables you are using in the adding of data. We have a note about using variables with adding of data in the AddDataSeries page:




      I would suggest to remove the variables you have used, replace them with hard coded values and then remove the column/re apply the column to test.

      If the problem is not specifically related to what you provided, the error just indicates something used was null. You could look for any objects you use in OnStateChange and check if they are null using a Print.

      I look forward to being of further assistance.

      There something going on behind the scenes that I'm not fully aware of but I've isolated the problem down to the fact that you have to be careful how you call ===> "this.Instrument.FullName" or Instrument.MasterInstrument.Name for that matter from within State.Configure if you plan to use the indicator in a Market Analyzer. I was able to fix the problem by employing a try-catch:

      Code:
      try
      {
          AddHeikenAshi(this.Instrument.FullName, BarsPeriodType.Minute, BarsPeriod.Value, MarketDataType.Last);    
      }
      catch
      {
      
      }
      I'm documenting this for any poor soul that encounters this problem.

      Comment


        #4
        Hello maltese,

        Originally posted by maltese View Post

        Code:
        try
        {
        AddHeikenAshi(this.Instrument.FullName, BarsPeriodType.Minute, BarsPeriod.Value, MarketDataType.Last);
        }
        catch
        {
        
        }
        I'm documenting this for any poor soul that encounters this problem.

        I just wanted to provide an additional comment surrounding this. This is not a valid solution for AddHeikenAshi or any of the Add data series methods. it is not expected to be able to use the Instrument variable or any runtime variable with adding of data.

        This is documented in the help guide AddHeikenAshi page along with AddDataSeries, I wanted to mention this as this is not a solution and is known to fail. We don't suggest using variables for adding data as it is not consistent in all tools/use cases. If you choose to use this type of logic in your script you certainly can at your own risk.

        For anyone who comes across this post, the correct way to add data is to instead hard code the values as shown in the help guide, this ensures it works correctly in all tools.

        https://ninjatrader.com/support/help...=AddHeikenAshi
        https://ninjatrader.com/support/help...ghtsub=adddata


        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello maltese,




          I just wanted to provide an additional comment surrounding this. This is not a valid solution for AddHeikenAshi or any of the Add data series methods. it is not expected to be able to use the Instrument variable or any runtime variable with adding of data.

          This is documented in the help guide AddHeikenAshi page along with AddDataSeries, I wanted to mention this as this is not a solution and is known to fail. We don't suggest using variables for adding data as it is not consistent in all tools/use cases. If you choose to use this type of logic in your script you certainly can at your own risk.

          For anyone who comes across this post, the correct way to add data is to instead hard code the values as shown in the help guide, this ensures it works correctly in all tools.

          https://ninjatrader.com/support/help...=AddHeikenAshi
          https://ninjatrader.com/support/help...ghtsub=adddata


          Please let me know if I may be of further assistance.
          Well then your solution also doesn't make sense. How are you supposed to "hard-code" in an instrument name for an indicator that will be used in Market Analyzer. What if I'm loading several symbols at once? You can't do it. Unless you know of another way to pass the instrument name to AddHeikenAshi then you're essentially saying that you can't use AddHeikenAshi or any method that requires the instrument name as a parameter, for that matter, in Market Analyzer. I'm pretty certain that's not NinjaTrader's intent. So, do you know of a better way to do this?...because my way is working.

          Comment


            #6
            Hello maltese,

            For that use case the suggestion is to create a script for each instrument that you plan to use. There is currently no means to dynamically add data from the primary with AddHeikenAshi. Only AddDataSeries has overloads which can inherit from the primary instrument, AddHeikenAshi is not currently developed in a way to be dynamic and has 3 overload sets which all require an instrument.

            With the AddHeikenAshi the suggestion would be to add it just like its shown in the help guide:

            Code:
            AddHeikenAshi("ES 03-18", BarsPeriodType.Minute, 1, MarketDataType.Last);
            This would work with an ES 03-18 column specifically, another separate script could be made for a different instrument.



            Please let me know if I may be of further assistance.

            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello maltese,

              For that use case the suggestion is to create a script for each instrument that you plan to use. There is currently no means to dynamically add data from the primary with AddHeikenAshi. Only AddDataSeries has overloads which can inherit from the primary instrument, AddHeikenAshi is not currently developed in a way to be dynamic and has 3 overload sets which all require an instrument.

              With the AddHeikenAshi the suggestion would be to add it just like its shown in the help guide:

              Code:
              AddHeikenAshi("ES 03-18", BarsPeriodType.Minute, 1, MarketDataType.Last);
              This would work with an ES 03-18 column specifically, another separate script could be made for a different instrument.



              Please let me know if I may be of further assistance.
              No Thank you. I think I'll stick with my, one line of code, unsupported version that works dynamically.

              In the mean time, could you at least mention to your "higher-ups" that this is something that should be fixed in later versions because you obviously shouldn't have to create a hundred different scripts (and on top of that create a hundred different market analyzer windows) in order to to run AddHeikenAshi on a hundred different symbols in Market Analyzer. That is comical and the AddHeikenAshi method is clearly broken. The mark of a good company with good employees is that they fix things that are broken instead of ignoring them and touting the company line. Regards.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kempotrader, Today, 08:56 AM
              0 responses
              6 views
              0 likes
              Last Post kempotrader  
              Started by kempotrader, Today, 08:54 AM
              0 responses
              4 views
              0 likes
              Last Post kempotrader  
              Started by mmenigma, Today, 08:54 AM
              0 responses
              2 views
              0 likes
              Last Post mmenigma  
              Started by halgo_boulder, Today, 08:44 AM
              0 responses
              1 view
              0 likes
              Last Post halgo_boulder  
              Started by drewski1980, Today, 08:24 AM
              0 responses
              4 views
              0 likes
              Last Post drewski1980  
              Working...
              X