Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is DataSeries access restricted by Thread context?

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

    Is DataSeries access restricted by Thread context?

    I have a strategy that uses a custom control with a button to invoke order logic. Either the strategy, via OnBarUpdate, or the user, via the button click, can cause an order to be submitted.
    When submitting the order, the calculations to determine where to place the order utilize various indicators and DataSeries. When this logic is called via OnBarUpdate it works. When the logic is called via a button click it throws an exception whenever a DataSeries is touched saying: 'Index was out of range...'. The exception occurs on a line like this:
    long vol = Volume[barsAgo];

    I am familiar with this error and have verified that the index is within range. I have also verified that the DataSeries.Count is valid. When I call the method Volume.IsValidDataPoint(barsAgo) fails with the same exception.

    My theory is that DataSeries instances may only be accessed by certain thread contexts, specifically those initiated or controlled by Ninja. So when I click on the button, which is now the general GUI thread, the context is not correct and the access to Volume[barsAgo] fails.

    Is this theory correct?

    My button logic currently uses strategy.Dispatcher.InvokeAsync to invoke the logic.
    So that attempt to get on the correct thread is not working.

    Does Ninja provide a way to get my logic to process on a Ninja thread with the proper context?
    Is the threading theory wrong?

    Can anyone shed some light on this problem?

    Thanks,
    Gary

    #2
    There are internal pointers that will be set during core events to help ensure they are up to date on the current bar being processed, but this not happen for custom events. You can either use an absolute index by using Bars.GetVolume() or you can also consider using TriggerCustomEvent() which will help sync the pointers to the current bar:

    MatthewNinjaTrader Product Management

    Comment


      #3
      perfect, thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      663 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      376 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