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

Real-time & Multi-threading Support in N7

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

    Real-time & Multi-threading Support in N7

    My strategy is based on tick by tick data:

    1) if I have method(s) that I would like to run multi-thread mode without stopping the main exeuction or not able to respond to N7 tick data, will I be able to do this? Will N7 support?

    2) I haven't tested my self yet, but I was reading on web some folks had issues (performance, hanging etc.,) by runing the stratgies on real-time with tick by tick data, Do you guys tested with streaming real-time data? anyone had prior experience here?

    Thanks

    #2
    rc554, can you please clarify #1? I believe if you call new threads, they will still be ran inside the main NinjaTrader thread, but I will have someone get back to you tomorrow to clarify.

    For #2, we have indeed run strategies on tick-by-tick data and have not experienced any performance issues.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Austin is correct. You will always be in the main thread when using NinjaScript.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        thanks for the quick reply. One more clarification:

        let's say my strategy is running using tick-by-tick data, so i have code in
        OnBarUpdate().
        Also, I have some code respond to my Orders (example: like once the order is filled, I am placing profit target & stop loss orders). So, if I have some code to respond to events OnAccountUpdate, OnExecution,
        OnOrderUpdate, OnPositionUpdate, then Is it safe for me to assume these will be running parallely? or only one method will execution at any point of time? (meaning, if OnOrderUpdate is executing and OnBarUpdate will not execute untill OnOrderUpdate finishes)

        Please clarify. thanks in advance.


        Comment


          #5
          rc554,

          For the most part, nothing would run in parallel. There are exceptions when you start programming some fancy unsupported stuff like returning out of the Windows method and then jumping around, then it could execute a different NS method prior to returning back to that part of the code. These circumstances you would not run into if you are just doing normal stuff with NS code.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            ok, so what you are saying (in the example I provided), if OnOrderUpdate is executing and OnBarUpdate will not execute untill OnOrderUpdate finishes. Am I right? if so, Can I create a thread in my OnOrderUpdate so that it can run on its own thread thus yielding to OnBarUpdate for tick-by-tick data?

            Comment


              #7
              Making your own thread is an instance of something that is completely unsupported. Unfortunately we will not be able to comment on the behavior since it all depends on how exactly you code it. If you start jumping around in your code it is possible to trigger other events prior to the current method finishing processing.

              What I can tell you is if you stay within what we have documented in the Help Guide and standard usage models nothing will run in parallel and OnBarUpdate() will finish processing before OnOrderUpdate() begins and vice versa as well.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                If I have two separate strategies running simultanously in NT, are there ever occasions when they might be running on different threads?

                Comment


                  #9
                  Post #3 is still accurate, all your NS would run on the main thread.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    Post #3 is still accurate, all your NS would run on the main thread.
                    Many thanks!

                    I am doing something non-standard which involves separately running strategies communicating with each other. It seems that sometimes strategy A performs OnBarUpdate() (in relation to a given bar, say the bar that ends at 14h30 EST, for example) before strategy B does; at other times it seems that strategy B is first to perform OnBarUpdate().

                    Does that make sense that the order of which strategy is first and which is second could be changing over time?

                    Comment


                      #11
                      I would not be surprised to see that, as everything is done event based for real-time processing.

                      Would be curious how you determine the lead vs lag feedback for those scripts? Comparing a timestamp?
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Bertrand View Post
                        ... Would be curious how you determine the lead vs lag feedback for those scripts? Comparing a timestamp?...
                        Certain variables from the "other" strategy are made available in OnBarUpdate() within each strategy.
                        By checking the values of these variables at the beginning and end of each bar in each strategy, and comparing what's happening at a given time in both strategies, I can see that A is updating earlier than B in most cases, but that sometimes this order is reversed.
                        Last edited by AnotherTrader; 07-30-2013, 11:56 AM.

                        Comment


                          #13
                          Ok I see, thanks. You're running two individual instances here with the processing done strictly event based, so I would not depend on a specific reporting / calculation order. Generally spoken it's good practice to ensure you're custom code is thread safe.
                          BertrandNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by sugalt, 04-30-2024, 04:02 AM
                          2 responses
                          13 views
                          0 likes
                          Last Post sugalt
                          by sugalt
                           
                          Started by merc410, Today, 03:41 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post merc410
                          by merc410
                           
                          Started by Ndakotan1313, 03-14-2024, 05:02 PM
                          2 responses
                          60 views
                          0 likes
                          Last Post blaise_code  
                          Started by claxxical, 05-30-2017, 12:30 PM
                          37 responses
                          4,457 views
                          0 likes
                          Last Post Padan
                          by Padan
                           
                          Started by SugarDefwebsite, Today, 02:18 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post SugarDefwebsite  
                          Working...
                          X