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

MaxProcessedEvents

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

    MaxProcessedEvents

    Hi,

    Is there the equivalent of MaxProcessedEvents for indicators? I have a dll that can raise events in the NinjaTrader code and I need it to work with Historical data as well as real time.

    It appears that during the initial startup, tick processing (BIP 1) in the dll is causing so many callbacks into NinjaTrader that I am running into some sort of limitation. I know that MaxProcessedEvents is an issue when doing this with a strategy but can't find any equivalent for an indicator.

    I know my actual implemention is well beyond the scope of support (that part works well in standalone unit testing) but hopefully you can point me in the right direction relative to the issue.

    Thanks,
    Scott

    #2
    Hello Scott,

    Thank you for your post.

    The MaxProcessedEvents is only within the Strategy Base.

    Are you using the SampleCustomEvents.cs logic in your code?

    Do you have a snippet of code that we can look at for further information?

    And what are the exact errors you are receiving? Please detail these in your response.

    I look forward to assisting you further.

    Comment


      #3
      Patrick,

      Thanks for getting back to me so quickly. I haven't seen the code in SampleCustomEvents. It is pretty straightforward to pass "this" in from an indicator or strategy to a dll as an interface and then implement callbacks just as you would with any .NET program.

      I do this all the time and it works fine. I am not getting an error message, the processing simply gets so far behind that the queues in the dll backup and I get errors on that side. I was looking for a way to make the "buffer" larger but will find another way around it.

      In the meantime, I cut down on the initial message traffic between the dll and NT and that took care of the issue. I was doing a Print in the callback and that seemed to be the issue; I know that is inherently a very slow process.

      Best Regards,
      Scott

      Comment


        #4
        Hello Scott,

        Thank you for that information.

        I am glad you were able to resolve this matter.

        The SampleCustomEvents.cs file can be found at the following link: http://www.ninjatrader.com/support/f...ead.php?t=5965

        Comment


          #5
          Patrick,

          Do you happen to know if historical data is processed in order of BIP? I have messages that can only come from a bar being processed (BIP 0) and another one that can only come from a tick being processed (BIP 1).

          All historical messages come in order by timestamp by BIP. I get all the historical bar messages then all the historical tick messages. Any thoughts on this?

          Best Regards,
          Scott

          Comment


            #6
            Hello Scott,

            Thank you for your response.

            Going forward after the historical data loads do you see the messages at appropriate times for each BIP?

            I do not see the same behavior on my end, I see the Primary and Secondary Data Series print to the output window when they have closed historically.

            I recommend debugging your NinjaScript code with Print statements to check these values. For information on debugging your NinjaScript code please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3418

            Comment


              #7
              Patrick,

              After historical data loads, all is as it should be; it is during the load that the issue occurs. I expected to receive BIP 0 and BIP 1 in a historical context as it would occur in real time. Bars (BIP 0) and ticks (BIP 1) in timestamp order. What appears to be the case is all of BIP 0 loaded and then all of BIP 1. Can you confirm how the data is loaded?

              I am going to run this via the debugger in Visual Studio (I have done this on many occasions) and see if I can see what is going on with the threading.

              Best Regards,
              Scott

              Comment


                #8
                Patrick,

                I have found the issue and it is what certainly appears to be an error within NinjaTrader. It didn't have anything to do with a maximum number of events as I originally thought. It was only correlated with a high number of events as that increased the probability of seeing the error.

                As I mentioned above, I have two bars objects BIP 0 is a 1 minute bar and BIP 1 is a 1 tick bar. The alerts I raised used Times[1][0] to get the time resolution from the tick bar and normally this worked. However I finally tracked the issue down to a Bar Index Must be greater/equal 0 error when trying to use the time from BIP 1.

                When I put a try/catch around a set of a string variable to that and in the catch set the string to "Unavailable" the vast majority of the time I would not hit the catch get a valid time but every so often I would hit the catch and get "Unavailable". Coupled with the messages generated by bars (BIP 0) finishing completely before getting any messages coming from ticks (BIP 1) I would say that you have an internal threading issue or something very similar.

                I found another thread with the Bar Index Must be... in the title that perfectly describes what I experienced but it doesn't appear that issue was ever resolved. Additionally when I replaced the Times[1][0] with Times[0][0] the issue went away completely and the catch was never triggered.

                I hope this helps you track down the issue.

                Best Regards,
                Scott

                Comment


                  #9
                  Hello Scott,

                  Can you send a toy* NinjaScript code and a reproducible scenario so that we may replicating the behavior to look into this. You can Export it as a Source File using the step from our Help Guide at the link below.



                  You may send the file to Support [at] NinjaTrader [dot] com with reference to this thread in the body of the email.



                  Happy to be of further assistance.

                  *Toy - basically a stripped down version of code that isn't necessarily the whole logic; making it easier to identify lines of code.
                  JCNinjaTrader Customer Service

                  Comment


                    #10
                    JC,

                    As is often the case, the effort to disentangle the proprietary parts of the code such that I could send you anything that would help, is beyond what I have time for right now.

                    To replicate this issue, add a second bar series of a 1 tick bar to an indicator run on a 1 minute chart, raise a custom event in a tight loop that references the second bar series' time as in Times[1][0] in the event and you should get the error. As I mentioned, there is also another thread that discusses virtually this exact same issue.

                    The main difference between what I suggested above and my exact situation is that I have a dll making a callback into the indicator code via an Interface vs. raising a custom event. This is one of the primary reasons I can't easily provide you with an example.

                    Best Regards,
                    Scott
                    Last edited by ScottB; 02-12-2013, 10:11 AM.

                    Comment


                      #11
                      Hello Scott,

                      I am not able to reproduce this and I do not believe I have found the thread that you are looking at. Can you post a link to the thread that you were viewing?
                      JCNinjaTrader Customer Service

                      Comment


                        #12
                        JC, I don't have a link but originally found it by doing a Google search on NinjaTrader Support Index must be greater than/equal 0. I am sure somewhere in your internal documentation you can get the exact message to search for.

                        This is something I get reliably but most often on loading a chart but before I am connected. Let me clarify this; I can get it easily if I reload the NinjaScript (F5) on a chart prior to connecting but I do still get it just after connecting. Presumeably this is when data is loaded that was not cached earlier.

                        Best Regards,
                        Scott
                        Last edited by ScottB; 02-13-2013, 12:07 PM.

                        Comment


                          #13
                          Hello Scott,

                          I see many different threads, but I do not know the specific one that you are referring to. At your convenience can you see if you can find the thread and send us the link?

                          If you give me a specific reproducible scenario I would be happy to look into this further for you so that I can either clarify something or have our Development team check into. This would be in an environment like, downloading Market Replay data for the ES 03-13 for 02-08-13 at 10:15AM, using the following indicator, I get result "x", but I expect to get "y".

                          Happy to be of further assistance.
                          JCNinjaTrader Customer Service

                          Comment


                            #14
                            JC,

                            The post is on 06-11-2012 at 03:12 pm, is by arnonmoscona and is titled Bar index needs to be greater/equal 0.

                            I will past the code that fixes the issue below. The code is in a callback from a dll that is referenced via an interface. I have two bars series, a 1 minute BIP 0 and a 1 tick BIP 1. As you can see from the code, if it is Historical, I use the BIP 0 time otherwise use the BIP 1 time. The Print statement will show "Time Unavailable" interspersed throughout but I don't think I have seen it unless processing historical data.

                            I hope this helps.

                            try
                            {
                            string time = string.Empty;
                            try
                            {
                            if (Historical)
                            time = Times[0][0].ToString();
                            else
                            time = Times[1][0].ToString();
                            }
                            catch(System.Exception se1)
                            {
                            time = "Time Unavailable";
                            }

                            Print("Alert " + Instrument.FullName + " " + time + " " + alert.AlertType + " " + alert.AlertMessage + " " + Convert.ToDouble(alert.MarketState.CurrentPrice) / mPriceConversion + " " + alert.MarketState.CurrentDirection);
                            }

                            Comment


                              #15
                              Hello Scott,

                              Thank you for the information.

                              Let me do some testing on my end and I will get back with you.
                              JCNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Philippe56140, 04-27-2024, 02:35 PM
                              3 responses
                              27 views
                              0 likes
                              Last Post Philippe56140  
                              Started by port119, 04-27-2024, 02:43 PM
                              2 responses
                              22 views
                              0 likes
                              Last Post port119
                              by port119
                               
                              Started by AaronKTradingForum, Yesterday, 02:37 PM
                              4 responses
                              41 views
                              0 likes
                              Last Post AaronKTradingForum  
                              Started by iceman2018, 04-27-2024, 05:07 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by adaisguy, Yesterday, 10:27 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post adaisguy  
                              Working...
                              X