• 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

running code when the trading buttons are pressed

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

    #16
    just to be clear, locking wouldn't interfere with manual trading being executed? I understand what a lock is, I just don't understand how NinjaTrader handles it. I can avoid locks for now since I will use the events for what I need to do, however I'd still like to understand this in case I need to use it in the future.

    Comment


      #17
      Hello NinjaCustomer,

      Within our documentation, we advise to lock the collection when reading and support its access. There should not be instances where reading the account positions would interfere with trade execution and I have not observed any such issue yet.

      If you come across a case, please let us know.
      JimNinjaTrader Customer Service

      Comment


        #18
        is it ok to use async / await?

        Comment


          #19
          Hello NinjaCustomer,

          NinjaTrader 8 is a multi threaded application and you are welcome to create asynchronous code to be used with your NinjaScript project, although I would typically advise against making NinjaTrader wait for asynchronous operations to complete. We will not be able to provide direction for creating asynchronous code as these concepts are outside the context of NinjaScript itself, but we do have documented Multi Threading Considerations which I will link below.

          Multi Threading Considerations - https://ninjatrader.com/support/help...-threading.htm

          We look forward to being of any further assistance.
          JimNinjaTrader Customer Service

          Comment


            #20
            thanks, yeah async / await doesn't seem to be useful for me - I was going to use ThreadPool.QueueUserWorkItem until I read your link.. how does one use ChartControl.Dispatcher.InvokeAsync in an addon? I mean, what should be used instead of ChartControl? I just want run something to process the open positions asynchronously (reading them only, not manipulating them)

            Comment


              #21
              my code seems to work fine with ThreadPool.QueueUserWorkItem, would there be any problems using this instead of Dispatcher.Invoke ?

              note to self: I'll stick with ThreadPool since Globals can't be accessed from OnStateChange() and this way I don't have to find an Instrument object to access
              Last edited by NinjaCustomer; 02-13-2019, 12:58 AM.

              Comment


                #22
                Hello NinjaCustomer,

                There aren't any best practice tips or advisories I could provide for using ThreadPools. If you find something works for you, you are welcome to use it.

                If you would like to use a Dispatcher from an AddOn you could use Globals.RandomDispatcher.InvokeAsync. You can also use a Dispatcher on an Instrument object.

                I look forward to being of any further assistance.
                JimNinjaTrader Customer Service

                Comment


                  #23
                  Multi-Threading Consideration for NinjaScript:

                  https://ninjatrader.com/support/help...-threading.htm

                  and

                  https://ninjatrader.com/support/foru...le-of-an-addon

                  for my reference
                  Last edited by NinjaCustomer; 03-06-2019, 12:54 PM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NinjaCustomer, Today, 12:29 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post NinjaCustomer  
                  Started by Steve L, Today, 11:32 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post Steve L
                  by Steve L
                   
                  Started by prabbala, Today, 10:41 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post prabbala  
                  Started by bebbus, Today, 10:36 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post bebbus
                  by bebbus
                   
                  Started by edmata1109, Today, 10:18 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post edmata1109  
                  Working...
                  X