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 pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      148 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      5 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,282 views
      0 likes
      Last Post Leafcutter  
      Working...
      X