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 KavinBase, Today, 02:43 AM
    0 responses
    1 view
    0 likes
    Last Post KavinBase  
    Started by szferi, Today, 02:04 AM
    0 responses
    4 views
    0 likes
    Last Post szferi
    by szferi
     
    Started by MidenThur, Today, 12:52 AM
    0 responses
    6 views
    0 likes
    Last Post MidenThur  
    Started by seseoraf, Today, 12:51 AM
    1 response
    6 views
    0 likes
    Last Post charmingishagarg  
    Started by Rosario, Today, 12:50 AM
    0 responses
    4 views
    0 likes
    Last Post Rosario
    by Rosario
     
    Working...
    X