Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing Indicator values from another thread?

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

    Accessing Indicator values from another thread?

    I have a complex strategy that includes a custom indicator amongst other things. In this strategy I also include a simple ATR indicator but keep a reference to it as:

    Code:
    private ATR Atr;
    
    // in my State.DataLoaded I do this
    Atr = ATR(ATRPeriod);
    
    // I then create an object that takes the ATR object in it's constructor for use later
    private SomeObject obj = new SomeObject(Atr);
    I can access the values of the Atr object no problem. I have internal events that fire through my integration with Sterling Trader that pass messages back and forth on order status updates. When a certain event fires in my framework a method in my SomeObject is called which tries to reference the Atr indicator. I get:

    Index was out of range. Must be non-negative and less than the size of the collection.
    I am accessing index 1 for the last bar (yes I make sure my CurrentBar is > 1 etc).

    I can also do Atr.Count and get a large number in the hundreds to thousands but can't seem to access the data at an index.

    My only thought is that because I am most likely accessing from a separate thread that the indicator was created on this is an issue (although it shouldn't be). Anything I'm missing here??

    #2
    Hello fxRichard,

    Thank you for your note.

    While unsupported, the following would allow you to test your hypothesis the other thread has not finished the task yet.

    Prior to calling the method which is getting the error, try

    Code:
    Thread.Sleep(3000);
    Which will cause the current thread to sleep 3 seconds.

    You will need to add the following using references,

    Code:
    using System.Threading;
    using System.Threading.Tasks;
    Does doing the above resolve the issue?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    44 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    65 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X