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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    31 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    9 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    17 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X