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

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

                  my addon compiles usually.. and it does access an external dll. However, I added one call to the dll.. one line.. and every time I try to compile this it hangs the


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

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by BarzTrading, Today, 07:25 AM
                  2 responses
                  15 views
                  1 like
                  Last Post BarzTrading  
                  Started by devatechnologies, 04-14-2024, 02:58 PM
                  3 responses
                  19 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by tkaboris, Today, 08:01 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post tkaboris  
                  Started by EB Worx, 04-04-2023, 02:34 AM
                  7 responses
                  162 views
                  0 likes
                  Last Post VFI26
                  by VFI26
                   
                  Started by Mizzouman1, Today, 07:35 AM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Working...
                  X