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