• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Addon Positions Orders and lock

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

    Addon Positions Orders and lock

    Hello,
    In my application/Addon I am checking on Positions for the Account and the orders on the account too. In the Help pages the example of iterating over Positions :
    it uses the lock statement

    lock (Account.Positions)
    {

    }

    whereas the example of the Orders in help does not

    I am iterating over these with the foreach and wondered if it was recommended to use the lock if i am just 'read only' of these values to get a current snapshot? In what instance would the lock be recommended ie if attempt to update Position information during a read.

    Will this cause any issue (not using lock or using lock) as my strategy/addon runs which will then update position / order information?

    thanks

    #2
    Hello, soulfx.

    Thanks for the post.

    The locks are used to prevent access violation exceptions/in-flight changes to the property. It is recommended to use locks wherever possible to prevent these violations since you might have other strategies that access the Accounts class. The issues that could arise from not using locks would be the inability to read the data. So using a lock on Account's properties being read would be the best way to prevent errors, even though some examples do not use locks.

    More information about these multithreading considerations can be found here:
    https://ninjatrader.com/support/help...-threading.htm

    Please let us know if we may be of any further assistance.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by vpzdcv, Today, 02:31 AM
    0 responses
    7 views
    0 likes
    Last Post vpzdcv
    by vpzdcv
     
    Started by YevhenShynkarenko, Today, 01:22 AM
    0 responses
    13 views
    0 likes
    Last Post YevhenShynkarenko  
    Started by ttodua, Today, 12:52 AM
    0 responses
    6 views
    0 likes
    Last Post ttodua
    by ttodua
     
    Started by ttodua, Today, 12:50 AM
    0 responses
    5 views
    0 likes
    Last Post ttodua
    by ttodua
     
    Started by mulshah, Yesterday, 11:12 PM
    0 responses
    6 views
    0 likes
    Last Post mulshah
    by mulshah
     
    Working...
    X