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

Leftover orders from optimization iterations

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

    #16
    Originally posted by NinjaTrader_PatrickH View Post
    Setting the IOrder objects to private resolved the lock up on my end. Can you provide the script that is still locking up after you have set the IOrder objects to private?
    Sure thing. It's attached.

    I am gratified to know that it doesn't lock up for you. Still does for me. The attached strategy is the same as I sent before except for declaring the IOrders private, checking for a null order in OnExecution, and adding a test for CurrentBar==0 in the trend calculation in OnBarUpdate.

    Question: Why would it matter if the word 'private' is missing? According to Microsoft's C# programming guide, "the access level for class members and struct members, including nested classes and structs, is private by default."

    If the attached script works for you, but not me, perhaps I need to re-install or reset NT7? I'm using the 64-bit version, if it matters.

    -Alex
    Attached Files
    Last edited by anachronist; 11-18-2014, 12:54 PM. Reason: Added MS note about C# defaults

    Comment


      #17
      Hello anachronist,

      Thank you for your response.

      Seems it was a fluke as both versions are repeating the same issue. I am looking into it further by going line by line through your code to find the root cause.

      Comment


        #18
        My hopes are dashed! I was hoping it was working on your end. It's hard to find anything else to comment out.

        I thought maybe that submitting and cancelling orders might cause a problem, so I put a test in to prevent any orders prior to 6/12/2009, so that only one limit order is submitted and then filled. But it still crashes.

        It's looking to me like the NinjaTrader proprietary code has an un-caught exception somewhere, or a caught exception that isn't being displayed. And the exception is occurring somewhere outside of this script.

        -Alex
        Last edited by anachronist; 11-18-2014, 03:49 PM.

        Comment


          #19
          Hello anachronist,

          The code works perfectly on smaller time frames, but for some reason a Weekly chart is causing this anomaly. I am trying to isolate on my end and I will follow up when I have more information.

          Comment


            #20
            Originally posted by NinjaTrader_PatrickH View Post
            The code works perfectly on smaller time frames, but for some reason a Weekly chart is causing this anomaly. I am trying to isolate on my end and I will follow up when I have more information.
            Weird.

            I'll point out that the strategy has an additional time frame Add()ed in Initialize(). So, for example, reducing the overall chart time frame to daily bars would also require series 1 time frame be reduced to hourly bars in the strategy source code.

            I no longer have an intraday feed, so I can't test it on smaller time frames. I can try on larger ones though.

            -Alex

            Comment


              #21
              Aha! I believe I found the problem.

              Man, that was subtle. I'm so accustomed to passing a null object for a not-needed string parameter. Old programmer's habit. I was passing null instead of an empty string as the OCO parameter in SubmitOrder().

              Maybe the SubmitOrder() method could check for oco==null for safety. Or at least catch an exception in there to display in the output window. Right now it just crashes silently if you pass null for OCO.

              Okay, now I can get on with trying to demonstrate the bug that started this thread. Apologies for this diversion.

              Comment


                #22
                Hello anachronist,

                Thank you for your patience.
                Originally posted by anachronist View Post
                But then my order management framework generates internal error messages to the Output window with strings like "125" and "124.5" appended to the order name, saying it does not recognize these orders that just got filled. And it shouldn't. These fill events shouldn't even be happening because those orders were never placed in that iteration.
                I am glad you were able to figure out the null reference in the ocoid. So with this fix and running the strategy on BA Weekly, I see the execution reported as you detailed as "12/3.5/3". Is this correct? How do I get your internal order management framework?

                Comment


                  #23
                  Originally posted by NinjaTrader_PatrickH View Post
                  Thank you for your patience.

                  I am glad you were able to figure out the null reference in the ocoid. So with this fix and running the strategy on BA Weekly, I see the execution reported as you detailed as "12/3.5/3". Is this correct? How do I get your internal order management framework?
                  Thank you for your patience. We ran around in circles due to a null parameter that should have been an empty string, and neither of us saw it. I hope NinjaTrader will introduce a fix that will catch things like that. It should be permissible to pass null for any unused parameter.

                  I'm happy to share my order management framework. Its purpose is to simulate ATM orders in backtest, switching over to real ATM orders on live trades. I've been using it for years to backtest intraday strategies, but I'm running into problems during optimizations on weekly data. Now, I know I don't need ATM orders on weekly or EOD bars. But my framework has so many other useful trade management features beyond just duplicating ATM strategies in backtest, that I'd like to make it work.

                  Rather than have you guys look at a thousand or so lines of code, I wrote a simple strategy that doesn't use my framework, to demonstrate the problem I saw: executions of orders submitted in previous optimization iterations. That simple strategy is posted in this thread. Now that we fixed the crashing issue, however, I am not seeing the optimization bug. So now I am trying to figure out what may be wrong in my framework.

                  A couple answers would help. I'm refactoring the code now to have a new way to associate exit orders with an entry order, like the ATM strategies do it.
                  1. The entry orders have the Signal name of the ATM strategy, and those names are unique (tagged with the bar number). But the Name field in my ATM exit orders must have values like "stop1" or "target2" instead of unique IDs, to retain compatibility with NinjaTrader's ATM strategies. I need a unique ID for these exit orders. I've been using the Token attribute, but that can change, according to the documentation. I need something unique and unchanging.
                  2. I'd love to set order.FromEntrySignal for tracking purposes, to associate exits with an entry signal, but it's read-only. Is there a public method for setting this? There's no Set() method. Or does this get set only when the exit order is executed?

                  Using order.Token in a dictionary is an elegant way to associate orders with ATM strategies, but can mess up if Token changes without me knowing about it. So now, refactoring to avoid using Token, I've run into the questions above. I can solve these issues with ugly string manipulations in the order.Name attribute (basically using that string as an encoded array of values), but if there's a more elegant way, I'd like to know.

                  -Alex
                  Last edited by anachronist; 11-25-2014, 12:37 PM.

                  Comment


                    #24
                    Hello Alex,

                    Thank you for your response.
                    1. The entry orders have the Signal name of the ATM strategy, and those names are unique (tagged with the bar number). But the Name field in my ATM exit orders must have values like "stop1" or "target2" instead of unique IDs, to retain compatibility with NinjaTrader's ATM strategies. I need a unique ID for these exit orders. I've been using the Token attribute, but that can change, according to the documentation. I need something unique and unchanging.
                    2. I'd love to set order.FromEntrySignal for tracking purposes, to associate exits with an entry signal, but it's read-only. Is there a public method for setting this? There's no Set() method. Or does this get set only when the exit order is executed?
                    1. You can implement a unique value for each instance via a user defined variable that could just be an int added to the id in the orders. For example, the first instance runs with the int set to 1 and the second to 2.

                    2. order.FromEntrySignal would only exist when the order is submitted. You could use an IOrder object and not set it to null when the order fills, but then you would need several IOrder objects for your orders and it could get messy.

                    Please let me know if I may be of further assistance.

                    Comment


                      #25
                      Hello Alex,

                      Thank you for your response.
                      1. The entry orders have the Signal name of the ATM strategy, and those names are unique (tagged with the bar number). But the Name field in my ATM exit orders must have values like "stop1" or "target2" instead of unique IDs, to retain compatibility with NinjaTrader's ATM strategies. I need a unique ID for these exit orders. I've been using the Token attribute, but that can change, according to the documentation. I need something unique and unchanging.
                      2. I'd love to set order.FromEntrySignal for tracking purposes, to associate exits with an entry signal, but it's read-only. Is there a public method for setting this? There's no Set() method. Or does this get set only when the exit order is executed?
                      1. You can implement a unique value for each instance via a user defined variable that could just be an int added to the id in the orders. For example, the first instance runs with the int set to 1 and the second to 2.

                      2. order.FromEntrySignal would only exist when the order is submitted. You could use an IOrder object and not set it to null when the order fills, but then you would need several IOrder objects for your orders and it could get messy.

                      Please let me know if I may be of further assistance.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by judysamnt7, 03-13-2023, 09:11 AM
                      4 responses
                      59 views
                      0 likes
                      Last Post DynamicTest  
                      Started by ScottWalsh, Today, 06:52 PM
                      4 responses
                      36 views
                      0 likes
                      Last Post ScottWalsh  
                      Started by olisav57, Today, 07:39 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post olisav57  
                      Started by trilliantrader, Today, 03:01 PM
                      2 responses
                      21 views
                      0 likes
                      Last Post helpwanted  
                      Started by cre8able, Today, 07:24 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post cre8able  
                      Working...
                      X