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

Object reference not set to an instance of an object (multi-time frame On Render)

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

    Object reference not set to an instance of an object (multi-time frame On Render)

    Hello

    I have written an indicator with several series and it works ok with these lines in OBU:

    if (CurrentBars[0] < 1
    || CurrentBars[1] < 1
    || CurrentBars[2] < 1
    || CurrentBars[3] < 1)

    return;

    In order to get better performance and smart results, I want to draw to use onRender method.

    What changes should I do over my previous only one-serie code to avoid "Object reference not set to an instance of an object"? Any help or example is apreciated.

    Thanks in advanced

    #2
    Hi Impeesa, thanks for writing in.

    The reason for the exception needs to be known before seeking a resolution. Use Visual Studio debugging to find the line that is throwing this error:



    Turn on debug mode through the editor, open the Visual Studio project and attach it to the NinjaTrader.exe process, then run the indicator to cause the exception and Visual Studio will then break at the line causing the exception.

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello Chris

      Maybe there is an easy answer before debugging. The code attached draws DeltaPercentValue above or below a bar if is greater or lower to a predefined value called LimitPercDelta. It works ok.

      All I want is to add a new data serie (for example Range = 40) and wait till this new data serie has two bar closed.

      I just add lines highlighted as I have done before in an indicator using Draw method instead Sharp.DX.

      //================================================== ============
      else if (State == State.Configure)
      {
      AddVolumetric(null, BarsPeriodType.Tick, tickOne, VolumetricDeltaType.BidAsk, 1);
      AddDataSeries(BarsPeriodType.Range, 40);
      }

      protected override void OnBarUpdate()
      {
      if (CurrentBars[0] <= BarsRequiredToPlot
      || CurrentBars[2] < 2)

      return;

      //================================================== ============

      As a result, Message "Error on triggering custom event for NinjaScript `myRenderTest´on bar 26: Object reference not set to an instance of an object"

      Obviously that is not the way to go. How should I add new data serie and wait till this new data serie has two bar closed?

      Sincerely,

      Attached Files

      Comment


        #4
        Hi Impeesa, thanks for your reply.

        The error means an uninitialized (null) object is being accessed. If the issue were a barsAgo error we would get a specific message about it. You will need to use Visual Studio to know what line the exception occurs on. The OnRender method is using the High array so it can be either the primary or secondary series. If the script is now multiseries it will need to target a series e.g. Highs[0].GetValueAt. TriggerCustomEvent should also not be used in OnRender, just use GetValueAt to access a bar index.

        Best regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello Chris

          Thanks a lot for your reply. I am a bit confused.

          I tried to follow your advide in post #4 using TriggerCustomEvent and it does work ok, but maybe I did not in a right way...

          In which method should have I use TriggerCustomEvent in that situation?

          And why using a secondary data serie in new script attached is not advisable?

          I am learning a lot in this forum with your team help and I appreciate your patience.

          Sincerely,

          Comment


            #6
            Hi Impeesa, thanks for your reply.

            TriggerCustomEvent is used to ensure all data points are up to date before executing a command. It can cause performance issues if you are doing this within OnRender. I do not see any script attached, could you upload again?

            Best regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hello Chris

              Script is attached in post #3, and now again.

              Please, have a look at your reply #4 in topic "plotting delta values onrender".

              Sincerely,
              Attached Files

              Comment


                #8
                Hi Impeesa, thanks for your reply.

                It's not that using multiple series is not advisable. The script's OnRender method is using High.GetValueAt so this can be referencing either the primary or secondary data series depending on the BarsInProgress context. If you want to target a specific price series use Highs[0].GetValueAt(0 or Highs[1].GetValueAt().

                Best regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by kaywai, Today, 06:26 AM
                1 response
                6 views
                0 likes
                Last Post kaywai
                by kaywai
                 
                Started by ct, 05-07-2023, 12:31 PM
                6 responses
                205 views
                0 likes
                Last Post wisconsinpat  
                Started by kevinenergy, 02-17-2023, 12:42 PM
                118 responses
                2,780 views
                1 like
                Last Post kevinenergy  
                Started by briansaul, Today, 05:31 AM
                0 responses
                10 views
                0 likes
                Last Post briansaul  
                Started by traderqz, Yesterday, 12:06 AM
                11 responses
                28 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X