Announcement

Collapse
No announcement yet.

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:



    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
        }

        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.

            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 CarlTrading, 03-31-2026, 09:41 PM
              1 response
              43 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by CarlTrading, 04-01-2026, 02:41 AM
              0 responses
              20 views
              0 likes
              Last Post CarlTrading  
              Started by CaptainJack, 03-31-2026, 11:44 PM
              0 responses
              29 views
              1 like
              Last Post CaptainJack  
              Started by CarlTrading, 03-30-2026, 11:51 AM
              0 responses
              46 views
              0 likes
              Last Post CarlTrading  
              Started by CarlTrading, 03-30-2026, 11:48 AM
              0 responses
              38 views
              0 likes
              Last Post CarlTrading  
              Working...
              X