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

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 frankthearm, Today, 09:08 AM
      3 responses
      9 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by yertle, Today, 08:38 AM
      5 responses
      15 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by adeelshahzad, Today, 03:54 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by bill2023, Yesterday, 08:51 AM
      6 responses
      27 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
      80 responses
      19,667 views
      5 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X