• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Close[BarsAgo] fails

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

    Close[BarsAgo] fails

    I'm converting my indicators from NT7 to NT8 and trying to reference OHLC Volume or Time using the typical Close[BarsAgo] is only working on the most recent 3 bars.

    Below is from the Visual Studio Immediate Window.

    Trying to access 39 bars ago fails as does anything over 2.

    ?Close.Count
    439
    ?BarsAgo
    39
    ?Close[BarsAgo]
    'Close[BarsAgo]' threw an exception of type 'System.NullReferenceException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147467261
    HelpLink: null
    InnerException: null
    Message: "Object reference not set to an instance of an object."
    Source: "NinjaTrader.Core"
    StackTrace: " at NinjaTrader.Data.BarsSeries.GetClose(Int32 index)\r\n at NinjaTrader.Data.Bars.GetClose(Int32 index)\r\n at NinjaTrader.NinjaScript.PriceSeries.get_Item(Int32 barsAgo)"
    TargetSite: {Double GetClose(Int32)}
    ?Close[0]
    53.96
    ?Close[1]
    53.92
    ?Close[2]
    53.92
    ?Close[3]
    'Close[3]' threw an exception of type 'System.NullReferenceException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147467261
    HelpLink: null
    InnerException: null
    Message: "Object reference not set to an instance of an object."
    Source: "NinjaTrader.Core"
    StackTrace: " at NinjaTrader.Data.BarsSeries.GetClose(Int32 index)\r\n at NinjaTrader.Data.Bars.GetClose(Int32 index)\r\n at NinjaTrader.NinjaScript.PriceSeries.get_Item(Int32 barsAgo)"
    TargetSite: {Double GetClose(Int32)}
    ?CurrentBar
    437




    #2
    Hello ctrent,

    I'm not certain about the Visual Studio errors, but are there errors in NinjaTrader on the Log tab of the Control Center?

    What is the line of code causing the error?

    Is there a null object?

    Is there an invalid index or barAgo value used?

    Is there a CurrentBar check needed?

    https://ninjatrader.com/support/help...currentbar.htm


    if you make a new indicator and add only the code:

    if (CurrentBar < 5)
    return;

    Print(string.Format("{0} | Time[5]: {1}, Close[5]: {2}, Volume[5]: {3}", Time[0], Time[5], Close[5], Volume[5]));

    Does this error?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      That simple code in OnBarUpdate works fine in a new indicator as well as in the one I'm seeing the other behavior.

      My indicator doesn't really run OnBarUpdate. It is even driven. What I'm doing is using the selecting a Historical Bar by placing a DrawingTool on it then walking forward from there to get Theoretical Trade Results. In NT7 this worked fine. Get the BarsAgo value of the DrawingTool then using Close[BarsAgo] step forward and cacluate the results.

      In NT8 only the most recent 3 bars were returning price data even though as seen in the VisualStuido output above there were 439 bars of data with CurrentBar = 437.

      Oddly enough Today it is returning values until Close[13] before returning the error below.

      I have reworked by NT8 code to use Close.GetValueAt(BarIndex) and it works fine maybe better. But this is unexpected behavior I'd like to understand.

      Comment


        #4
        Hello ctrent,

        If you are attempting to access bar data outside of a data driven method, you must use TriggerCustomEvent() to synchronize the series first.

        May I confirm you are using TriggerCustomEvent()?

        Below is a link to the help guide.
        https://ninjatrader.com/support/help...ustomevent.htm

        Using .GetValueAt() is an alternative to using TriggerCustomEvent.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          That explains it.

          I was not aware of this and was not using the TriggerCustomEvent() methods.

          Thanks
          Chris

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NinjaCustomer, Today, 01:48 AM
          0 responses
          2 views
          0 likes
          Last Post NinjaCustomer  
          Started by aligator, Yesterday, 10:11 PM
          0 responses
          2 views
          0 likes
          Last Post aligator  
          Started by psquare, Yesterday, 03:11 PM
          4 responses
          20 views
          0 likes
          Last Post psquare
          by psquare
           
          Started by ballboy11, Yesterday, 03:20 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by tonynt, Yesterday, 02:18 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_JoshG  
          Working...
          X