Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-threading Ninja

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

    Multi-threading Ninja

    Hello

    Can I have some idea on how Ninja organizes its threads that execute the strategy?

    I do know that single instance of running strategy uses single thread but I have an idea and would like to see if I can execute strategy on multiple instruments simultaneously in same NinjaTrader execution instance.

    Reason I am asking this is because I want to implement lock / PulseAll constructs to thread safe update trade info into some 3rd party. What this means is that I'd have in OnBarUpdate and OnOrder overrides.


    Code:
    lock (this)
    {
       // Do Something
       Monitor.PulseAll(this);
    }
    P.S:I already have a feeling that this question is going to flagged away as "unsupported" but I'd like to still give it a try

    #2
    cdjindia, implementing a custom threading would not be somewthing we could support, however architecture wise the realtime data will see on a single thread, while NinjaScript and orders are processed in the separate thread.

    Comment


      #3
      Bars.TickCount does not work as expected

      Print( CurrentBar.ToString() + "." + Bars.TickCount.ToString());

      In one of my strategy where above Print statement was invoked 56 times, it produced
      this 56 times,

      22432.1

      I do have CalculateOnBarClose set to false. There are only two possibilities for this to occur.
      1) TickCount is somehow not getting updated 2) OnBarUpdate() is being called even when there is no new tick.

      Comment


        #4
        This was for realtime use / Market Replay? Which symbol and chart and connection (if not replay) were you working on?

        Comment


          #5
          It was in Market Replay. Instrument CL 12-13.

          Time stamp 9/11/2013 3:33:58 AM. Sydney, AU time.
          Last edited by cdjindia; 02-21-2014, 04:42 AM.

          Comment


            #6
            Ok but what chart were you using there? This was for a live bar and not for any historical data preloaded bar in replay, correct? On those COBC = false wouldn't be effective and you should not see the tickcount be dynamically updated.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              Ok but what chart were you using there? This was for a live bar and not for any historical data preloaded bar in replay, correct? On those COBC = false wouldn't be effective and you should not see the tickcount be dynamically updated.
              I don't quite get your first question about chart. Do you mean Bar type of the Series? It was one of the paid-for custom Renko. Do you mean, that it could be a bug in that Renko thingy?

              Preloaded; No, I don't think so. But, I am not 100% certain about this. How do I verify this?

              I have used flag of FirstTickOfBar which I presume is logical equivalent of
              Bars.TickCount == 1. Or are they two separate things?

              if tick count is not being updated, why does OnBarUpdate keep getting called again and again?

              Should I (Can I) implement my own tick count to handle excessive calling on same bar?

              Comment


                #8
                Could definitely be a bar type issue as well, would doublecheck against our default types for example on truly live / L1 replay data not historical (so historical flag would report false).

                OnBarUpdate() false - you see a call for each tick that would trigger OnBarUpdate(), this does not guarantee though this property would be reported correctly for the custom type.

                You can of course run your own tick counter as well.

                Comment


                  #9
                  Hallo,
                  I devlop strategies.
                  Are the Print- and Alert- Function threadsave?

                  Thank You
                  Rolf Theus
                  Last edited by RolfTheus; 07-28-2014, 08:59 AM.

                  Comment


                    #10
                    Originally posted by RolfTheus View Post
                    Hallo,
                    I devlop strategies.
                    Are the Print- and Alert- Function threadsave?

                    Thank You
                    Rolf Theus
                    Rolf

                    I develop strategies too. Just so I am on same page with you, can you please explain "Why do you need thread safe behavior on Print and Alert ?"

                    Comment


                      #11
                      Hallo,
                      i use Print, and Alert in OnBarUpdate, OnOrderUpdate, OnExecution, OnPositionUpdate. I use a timer (with TimerEventProcessor) who calls OnBarUpdate after specified timeintervall (e.e. 100 milliseconds ) to be undependent from a tick so i can react at once. The strategy is controlled from the outside by lines and text in the chart. OnBarUodate is locked by a lockObject so only the timer can call it or NT. When i start a stresstest with many orders, after a while NT gets frozen and i have to kill NT by the taskmanager.
                      I have tried to lock the other function too but no success.

                      I am searching the error and therefore my question to eliminate this possibility eventually.

                      Thank You
                      Rolf Theus
                      Last edited by RolfTheus; 07-28-2014, 11:15 AM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      656 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      371 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      109 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      574 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      579 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X