Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to access Time or High values properly in mouse click event

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

    Unable to access Time or High values properly in mouse click event

    Hi,

    I've been working with some posts to implement capturing the time and price under a mouse click. That much works. However, in the indicator, when I access values of either Time[] or High[] more than a few bars back, I get an object reference error. I'm testing it on a simple 3-min chart with only one data series. It's got to be something pretty basic that I'm missing, but I'm at a loss as to why I could not use the arrays as I normally would or at least had been used to using them in NT7. I've attached the indicator in case anyone spots that something obvious. Meanwhile, the output shows that there are 3,706 bars on the chart, but an error gets thrown when trying to retrieve the value of Time[8]. In addition, the values for time for the first few that are returned are all incorrect.

    Number of bars on chart: 3706

    Time test 0: 11/13/2019 6:03:00 PM
    Time test 1: 11/13/2019 4:43:00 PM
    Time test 2: 11/13/2019 4:43:00 PM
    Time test 3: 11/13/2019 4:43:00 PM
    Time test 4: 11/13/2019 4:43:00 PM
    Time test 5: 11/13/2019 4:43:00 PM
    Time test 6: 11/13/2019 4:43:00 PM
    Time test 7: 11/13/2019 4:42:00 PM

    Time test didn't work: Object reference not set to an instance of an object.

    The first line outputs the value of Time[0] - which I had thought was the barsAgo value from the last bar on the chart. But the output is the date/time of the very first bar on the chart. Is there something about working with NT8 that I just fundamentally don't understand? Thanks.

    Regards,

    Gordon
    Attached Files

    #2
    Hello Gordon,

    To use series in any non data driven method TriggerCustomEvent() must be used or Series.GetValueAt()/Bars.GetClose()/Bars.GetOpen/etc.
    https://ninjatrader.com/support/help...ustomevent.htm
    https://ninjatrader.com/support/help...getvalueat.htm
    https://ninjatrader.com/support/help...8/getclose.htm

    Below is a link to an example script that returns the time and price from a mouse click x and y.
    https://ninjatrader.com/support/foru...624#post792624

    After using TriggerCustomEvent, any index used in a series must be less than the CurrentBars value for that series.
    Meaning if CurrentBar is greater than 8, then Time[8] may be used.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, Chelsea. NT8 does work differently in that regard. I appreciate the pointer.

      Regards,

      Gordon

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      666 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      377 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      110 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      575 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      580 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X