Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 yertle, Today, 08:38 AM
    6 responses
    25 views
    0 likes
    Last Post ryjoga
    by ryjoga
     
    Started by algospoke, Yesterday, 06:40 PM
    2 responses
    24 views
    0 likes
    Last Post algospoke  
    Started by ghoul, Today, 06:02 PM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    46 views
    0 likes
    Last Post jeronymite  
    Started by Barry Milan, Yesterday, 10:35 PM
    7 responses
    23 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X