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

Replay vs Live error

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

    Replay vs Live error

    I have an indicator I've built which works fine with my Live Zenfire data feed, but when I connect to Playback, the indicator causes a "Object reference not set to an instance of object" error.

    I would prefer not to post the code publicly. Is there a way I can get assistance with this error?

    Thanks,

    Safetrading

    #2
    You will want to ensure you do a CurrentBar check at the start to prevent the null reference. This will stop it from trying to reference data that isn't yet loaded onto the chart.



    if working with a multi series indicator:
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thanks, but I have that in place. My indicator only looks 9 bars back, so I added this as the first line in OnBarUpdate;
      if(CurrentBar < 10)return;

      Any other thoughts?

      Comment


        #4
        I would suggest increasing this to a large number like 50 or 100 to test.

        If you still receive this error:

        Your NinjaScript / C# Code will always be logically processed and evaluate according to your set logic – this can of course lead to unexpected results at times, thus we would suggest to simplify and debug your code to better understand the event sequence it would go through - if you provide me with a sample script that replicates this error I can look into it but if requires in depth debugging unfortunately we cannot offer such debug or code modification services here, but please see the provided resources below to help you proceed productively :

        First of all you would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.

        It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.

        If you would prefer the debug assist of a professional NinjaScript consultant, please check into the following listings - Click here for a list of certified NinjaScript Consultants
        LanceNinjaTrader Customer Service

        Comment


          #5
          I tried extending the CurrentBar look back, but that didn't help. Here is a piece of the code that NT seems to have issue with;

          if(CurrentBar < 10)return;

          if( Closes[1][0] < Opens[1][0] && Closes[1][1] < Opens[1][1] && Closes[1][2] < Opens[1][2]
          ||
          Closes[1][0] > Opens[1][0] && Closes[1][1] > Opens[1][1] && Closes[1][2] < Opens[1][2] && (Closes[1][0]-Lows[1][0])/(Highs[1][0]-Lows[1][0]) >= 0.67
          ||
          Closes[1][0] > Opens[1][0] && Closes[1][1] < Opens[1][1] && Closes[1][2] < Opens[1][2] && (Closes[1][0]-Lows[1][0])/(Highs[1][0]-Lows[1][0]) >= 0.67)
          {
          // do something
          }

          Thanks for your help.

          Comment


            #6
            When working with multi series like this you have to use CurrentBars


            Example if you had 3 series
            Code:
            // Checks to ensure all Bars objects contain enough bars before beginning
                if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired)
                    return;
            LanceNinjaTrader Customer Service

            Comment


              #7
              Thanks a lot, that did it. I'll be sure to add this to my notes. Have a great day.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              603 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              23 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              22 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Working...
              X