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 michi08, 10-05-2018, 09:31 AM
                  5 responses
                  741 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by The_Sec, Today, 02:29 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post The_Sec
                  by The_Sec
                   
                  Started by tsantospinto, 04-12-2024, 07:04 PM
                  4 responses
                  62 views
                  0 likes
                  Last Post aligator  
                  Started by sightcareclickhere, Today, 01:55 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post sightcareclickhere  
                  Started by Mindset, 05-06-2023, 09:03 PM
                  9 responses
                  259 views
                  0 likes
                  Last Post ender_wiggum  
                  Working...
                  X