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 Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              656 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              371 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              109 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              574 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              579 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X