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

Bars.GetDayBar(1).Open - How to assign it to a variable

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

    Bars.GetDayBar(1).Open - How to assign it to a variable

    Bars.GetDayBar(1).Open - I'm able to print the value in out put window, when trying to assign this value to a variable getting error

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

    Appreciate your inputs on this.

    #2
    Hello nurushaik,

    There is a sample of how to use this method in the help guide, the error you are getting is caused by not checking for null like the help guide shows:



    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      I've checked the link,
      i'm able to print the values as mentioned in the help guide:
      Print( Bars.GetDayBar(1).Open.ToString () + " " + Bars.GetDayBar(1).High + " " + Bars.GetDayBar(1).Low );

      when i'm trying to assign these values to a variable then i'm getting error...

      double Op_Price = Bars.GetDayBar(1).Open;

      Overall my goal is to perform and store/leverage the Bars.GetDayBar(1).Open - Bars.GetDayBar(1).Low values ...

      is there any way I can assign or compute above and use in...

      thanks in advance.

      Comment


        #4
        Hello nurushaik,

        The code you have shown is valid, the error you mentioned in post 1 is specifically because you don't have a null check condition surrounding that code.


        Code:
          if(Bars.GetDayBar(1) != null)
        {
            //use your code here
        }
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          That's what I did. still throwing errors.

          1.PNG = working fine.. (only used with print)
          2.PNG = error ... ( when tried to assign to a variable).
          Attached Files

          Comment


            #6
            Hello nurushaik,

            The if condition you have checking for null is not valid, you have the condition terminating after your print with the closing brace }

            The lines after your print are outside the null check condition.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks Jessy. You are correct.

              My bad, I didn't noticed.

              It works now.

              Regards,
              Nuru Shaik

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by fx.practic, 10-15-2013, 12:53 AM
              5 responses
              5,404 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by Shai Samuel, 07-02-2022, 02:46 PM
              4 responses
              95 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by DJ888, Yesterday, 10:57 PM
              0 responses
              7 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by MacDad, 02-25-2024, 11:48 PM
              7 responses
              159 views
              0 likes
              Last Post loganjarosz123  
              Started by Belfortbucks, Yesterday, 09:29 PM
              0 responses
              8 views
              0 likes
              Last Post Belfortbucks  
              Working...
              X