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 pjsmith, Today, 01:00 AM
    1 response
    10 views
    0 likes
    Last Post NT-Roland  
    Started by alejandro888, Yesterday, 08:41 PM
    0 responses
    9 views
    0 likes
    Last Post alejandro888  
    Started by UltraNIX, Today, 02:14 AM
    0 responses
    6 views
    0 likes
    Last Post UltraNIX  
    Started by augustfay, Yesterday, 12:06 PM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by klaus w, Yesterday, 12:13 PM
    2 responses
    24 views
    0 likes
    Last Post klaus w
    by klaus w
     
    Working...
    X