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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      44 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      54 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      34 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      95 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      57 views
      0 likes
      Last Post PaulMohn  
      Working...
      X