Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars.GetDayBar - how to know I have enough data

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

    Bars.GetDayBar - how to know I have enough data

    hi, I am using the GetDayBar method. When the study loads, as the bars are being calculated, I get an "On Bar Update Error". I am guessing it is because I am referencing the Close values where GetDayBar is not returning an object because there is no 1 data one day back.

    this is my code:
    Code:
    double previousDayClose = Bars.GetDayBar(1).Close;
    How do I know that I have data to access the previous day bar? Can someone please share some code?

    thanks,
    Onn

    #2
    Hello onnb1,
    Correct, this error is because in OnBarUpdate() is trying to access the data series that does not have enough data to calculate. More information about making sure you have enough data can be found at the following link.


    This can be fixed by adding in a check to make sure we have enough data for the calculations in "OnBarUpdate()". Example:

    Code:
    protected override void OnBarUpdate()
    {
    	//Checks to make sure that there is a value for GetDayBar(1) before calculating
    if (Bars.GetDayBar(1) != null)
    {
    	double previousDayClose = Bars.GetDayBar(1).Close;
    }
    }
    Here is a link to our help guide that goes over GetDayBar() that you may read.



    Please let me know if I can be of further assistance.
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    599 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    344 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    558 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    557 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X