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.GetBar Exception

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

    Bars.GetBar Exception

    Hello, I am testing an indicator and in the debugger a NullException is thrown for the below


    int startBarsAgo = Bars.GetBar(startDateTime); EXCEPTION on this line

    int endBarsAgo = Bars.GetBar(endDateTime);


    This indicator is used on both time based and non time based charts.
    I have a custom bar type which is a variation of a range bar.

    Would you expect for a non time based bar it to return the prior bar?

    What is interesting is that i have been running this for some time and it wasnt apparent til running through debugger that this could have been issue on occassion.

    In looking at the documentation it doesnt say that this is only for time based bars but wondered what logic would return a null. Of course in non time based there will not necessarily be a bar at that specific time.

    The indicator draws horizontal lines between a start time and end time for each trading day.

    thanks

    #2
    Hello soulfx, and thank you for your query.

    To debug this strategy, we should first examine whether startDateTime and endDateTime are ever null before being passed in to GetBar, and whether your Bars object has been initialized. Please add these lines of code before the ones you sent us, and let us know what results you get in your New -> NinjaScript Output Window.

    Code:
    [FONT=Courier New]Print("TEST 1 : Bars is" + (Bars == null ? "" : "n't") + " null");
    Print("TEST 2 : startDateTime is" + (startDateTime == null ? "" : "n't") + " null");
    Print("TEST 3 : endDateTime is" + (endDateTime == null ? "" : "n't") + " null");
    Print("TEST 4 : startDateTime is" + (startDateTime is DateTime ? "" : "n't") + " a DateTime object");
    Print("TEST 5 : endDateTime is" + (endDateTime is DateTime ? "" : "n't") + " a DateTime object");
    [/FONT]
    Thank you in advance, this information will aid us in seeing the same thing you are seeing. For reference, this is the desired output.

    TEST 1 : Bars isn't null
    TEST 2 : startDateTime isn't null
    TEST 3 : endDateTime isn't null
    TEST 4 : startDateTime is a DateTime object
    TEST 5 : endDateTime is a DateTime object
    Jessica P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,605 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    8 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    4 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    13 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X