Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with error in ninjascript code

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

    Help with error in ninjascript code

    I have ninjascript strategy code I could use some help with (NT8). I keep getting an error saying "Error on calling "OnBarUpdate" method on bar 1: Object reference not set to an instance of an object.". I am not able to "enable" the strategy or backtest it because of this. Because of the nature of the code, I would prefer to keep it private and not post it here. Would anyone be able to take a look and see if they can figure out what is going on?

    Thank you!!

    #2
    Hello gf1992,

    Thanks for your post.

    "Error on calling "OnBarUpdate" method on bar 1: Object reference not set to an instance of an object."

    The error message "Object reference not set to the instance of an object" means that something in the script is returning null at the time you are accessing it. Debugging steps would need to be taken to determine what exactly is returning null in the strategy.

    Below is a link to a forum post that demonstrates using debugging prints to understand the behavior of a script.
    https://ninjatrader.com/support/foru...121#post791121

    Also, see the help guide documentation below about making sure there are enough bars processed before the script begins its calculations:
    Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you for your reply. One more question for you. When I try to import the ninjascript (which was made using NinjaTrader 8), I get the error message attached. It was not made using an older version on NinjaTrader, so do you know why I am getting this error? I am only able to get this code into NT8 through ninjascript editor, but can't import it.

      Thanks!

      Comment


        #4
        Hello gf1992,

        Thanks for your note.

        If this is a NinjaScript that you created, please share the file that you are attempting to import so that we may look into this further.

        If this is a NinjaScript created by a third-party developer, please reach out to the developer of th script directly and inform them of the import error message you are recieving.

        I look forward to further assisting.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Should I email you the code or post it here?

          Comment


            #6
            Hello gf1992,

            Thanks for your note.

            You could attach the file to your response here on the Forums if you are comfortable doing so.

            Otherwise, you could send the file to scriptingsupport[AT]ninjatrader.com for us to review. Note that if you choose to do this, in the subject of the email, include ATTN Brandon H. In the body of the email, include the ticket number 3593314 and a link to this forum thread.

            I look forward to assisting further.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              I actually figured it out! One more question. I want to set an $100 trailing stop loss on my orders. In other words, -$100 P/L on my position. Is there a way to set that specific stop loss in P/L like that? I was able to do it on TradeStation. Thank you!

              Comment


                #8
                Hello gf1992,

                Thanks for your note.

                Unfortunately, Currency and Price are not a CalculationMode that could be used when calling the SetTrailStop() method. This is seen in the Warnings section of the SetTrailStop() help guide page. To use these CalculationModes for a stop loss, you would need to use the SetStopLoss() method and add logic to the script that trails the stop loss.

                From the help guide: CalculationMode.Price and CalculationMode.Currency are irrelevant for trail stops. Attempting to use one of these modes will log a message and the stop order be ignored. Please use SetStopLoss() for these modes instead.

                See the help guide documentation and reference sample linked below.
                SetTrailStop(): https://ninjatrader.com/support/help...ttrailstop.htm
                SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm
                SamplePriceModification: https://ninjatrader.com/support/help...of_stop_lo.htm

                Let us know if we may further assist.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                58 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                133 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                73 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                50 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X