Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 kujista, Today, 06:23 AM
    4 responses
    13 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by traderqz, Yesterday, 09:06 AM
    2 responses
    15 views
    0 likes
    Last Post traderqz  
    Started by traderqz, Today, 12:06 AM
    3 responses
    6 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by RideMe, 04-07-2024, 04:54 PM
    5 responses
    28 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by f.saeidi, Today, 08:13 AM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X