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 arvidvanstaey, Today, 02:19 PM
    0 responses
    3 views
    0 likes
    Last Post arvidvanstaey  
    Started by mmckinnm, Today, 01:34 PM
    3 responses
    5 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by f.saeidi, Today, 01:32 PM
    2 responses
    6 views
    0 likes
    Last Post f.saeidi  
    Started by alifarahani, 04-19-2024, 09:40 AM
    9 responses
    55 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Conceptzx, 10-11-2022, 06:38 AM
    3 responses
    60 views
    0 likes
    Last Post NinjaTrader_SeanH  
    Working...
    X