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

Threading Indicator Calculations

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

    Threading Indicator Calculations

    Does anyone have any experience working with threads within NT? I've written a class within the Ninja IDE that grabs a few indicator values and price data from OnBarUpdate() eventHandler and stores them a queue then pass them off to worker threads for processing and inserting the results into a database...

    It complies fine and I'm 99% sure that my code is correct. I've written this design pattern 1000x's (Multi-Threaded Producer Consumer Queue) for some reason whenever I attempt to added the indicator a char my threads keep crashing NT.

    Can someone please let me know what I'm doing wrong?
    Last edited by d.allen101; 12-11-2011, 08:47 PM.

    #2
    d.allen, this is beyond the level of support we can provide. A coworker will get back to you on your other thread tomorrow with some clarification.

    I'm pretty sure all indicator calculations are done in a single thread, so spawning more threads and trying to get them synchronized just might not work in the main thread.
    AustinNinjaTrader Customer Service

    Comment


      #3
      I'm aware that someone from your support team will getting back w/ me tomorrow but I was just curious/wondering if some outside (NT user) might have come across this issue before and had an explanation and/or solution rather then wait until Monday.

      Never hurts to ask is my moto...

      Comment


        #4
        Originally posted by d.allen101 View Post
        Does anyone have any experience working with threads within NT? I've written a class within the Ninja IDE that grabs a few indicator values and price data from OnBarUpdate() eventHandler and stores them a queue then pass them off to worker threads for processing and interesting the results into a database...

        It complies fine and I'm 99% sure that my code is correct. I've written this design pattern 1000x's (Multi-Threaded Producer Consumer Queue) for some reason whenever I attempt to added the indicator a char my threads keep crashing NT.

        Can someone please let me know what I'm doing wrong?
        If you want to spin off threads, then you have to create the necessary mutexes/exclusion flags to ensure that only valid data is passed back, and returned in correct synchrony. You may have to use Try/Catch exception handling to see where the problem lies.

        Comment


          #5
          the threads are synchronized with the lock() and the thread signals are controlled with EventWaitHandle object and the threads are created within the class. I'm not spawning new threads during runtime. i create a fixed number to threads in the constructor of my producerConsumserQueueClass according to my machine processor count...I can't debug because NT won't allow me to add the indicator to the chart. it immediately crashes as soon as i try to added to a chart...
          Last edited by d.allen101; 12-11-2011, 08:50 PM.

          Comment


            #6
            koganam, here's a code example from my original thread post:

            Example:

            MyCls myCls = new MyCls();

            void OnBarUpdate()
            {
            double high = High[0];
            double low = Low[0];
            double close = Close[0];

            string data = string.Format("{0},{1},{2}",high,low,close);
            myCls.GetData(data);
            }

            // my class
            class MyCls
            {
            EventWaitHandle ewh = new AutoResetEvent(false);
            object sync = new object();
            Queue<string> que = new Queue<string>();
            Thread t = new Thread(worker);

            public MyCls()
            {
            t.IsBackground = true;
            t.Start();
            }

            public void GetData(string data)
            {
            lock(sync)
            {
            que.Enqueue(data);
            }
            ewh.Set();
            }

            private void worker()
            {
            while(true)
            {
            lock(sync)
            {
            // get data from que.Dequeue();
            // blah, blah, blah...
            }

            // process data....blah, blah, blah...
            // after processing data block thread
            ewh.WaitOne();
            }
            }

            in my actual code I have the appropriate error handling in place (try/catch) this is just an example of what i'm doing...

            Comment


              #7
              Originally posted by d.allen101 View Post
              the threads are synchronized with the lock() and the thread signals are controlled with EventWaitHandle object and the threads are created within the class. I'm not spawning new threads during runtime. i create a fixed number to threads in the constructor of my producerConsumserQueueClass according to my machine processor count...I can't debug because NT won't allow me to add the indicator to the chart. it immediately crashes as soon as i try to added to a chart...
              Any messages in the trace or log files?

              Comment


                #8
                Is COBC true or false?

                Comment


                  #9
                  I tried both CalculateOnBarClose = true and false. setting crash but that shouldn't make a difference should it? i would run in both modes.

                  hey can you tell how to get to trace and log files please? i don't know how. thanks in advance!

                  Comment


                    #10
                    Trace files are Documents\NT7\trace folder...logs \log. or in the NT Control Center log tab.

                    Comment


                      #11
                      thanks VTtrader...I'm about to take a look right now and see what I can find. I really need to learn A LOT more about how to use NT. unfortunately I know VERY little.

                      Comment


                        #12
                        THANKS koganam and VTtrader! I FIXED it!!!! it was complaining about my shared database ADO.NET i.e. shared connection and command object across threads multiple threads!

                        thanks again for suggesting and telling me about access trace and log files!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by jclose, Today, 09:37 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post jclose
                        by jclose
                         
                        Started by WeyldFalcon, 08-07-2020, 06:13 AM
                        10 responses
                        1,413 views
                        0 likes
                        Last Post Traderontheroad  
                        Started by firefoxforum12, Today, 08:53 PM
                        0 responses
                        11 views
                        0 likes
                        Last Post firefoxforum12  
                        Started by stafe, Today, 08:34 PM
                        0 responses
                        11 views
                        0 likes
                        Last Post stafe
                        by stafe
                         
                        Started by sastrades, 01-31-2024, 10:19 PM
                        11 responses
                        169 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Working...
                        X