Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Old code runs on new orders.

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

    Old code runs on new orders.

    Hi NinjaTrader Forums,
    I have an issue where I have recompiled some code for a strategy I'm working on, but I can see Print messages from the old code still executing.

    For example, I have a printout of information for OnOrderUpdate, which shows the order name and details. That has since been removed, and no longer found anywhere in my codebase, but it still displays for newly created orders. I've tried clearing all the data in each account that has orders in it by going to the Accounts tab, right-clicking on the account, selecting Edit Account, then resetting the data. I can print out all my account orders and see no orders appear. However, when I create new orders with the new strategy code I'm testing, the old messages still show up. I've tried restarting NinjaScript and restarting my computer.

    Any advice on totally clearing what seems like cached code would be greatly appreciated.

    Thank you!

    #2
    Hello Jimmathy,

    Thank you for your post.

    After recompiling, remove the old instance of the strategy from the chart or Strategies tab and add a new instance.

    Are you still seeing this behavior occur?

    Comment


      #3
      Hi Gaby,
      Yes, I have removed the strategy, reset the account data, compiled twice, and re-added the strategy back and I still see the same output from an old version of the strategy.

      I suspect it has something to do with a method that was not removed from the account on OrderUpdate. Here is something similar to what I had before:

      Method added during class construction.
      HTML Code:
      public OrderTestStrategy()
      {
      AccountName = (string.IsNullOrWhiteSpace(AccountName)) ? "Playback101" : AccountName;
      
      lock (Account.All)
      account = Account.All.FirstOrDefault(a => a.Name == AccountName);
      
      // Subscribe to order updates
      if (account != null)
      account.OrderUpdate += AccountOrderUpdate;
      }


      This is what I suspect was missing from the old code I used before.
      HTML Code:
      protected override void OnStateChange()
      {
      switch (base.State)
      {
      ...
      case State.Terminated:
      if (account != null)
      account.OrderUpdate -= AccountOrderUpdate;
      break;
      }
      }
      ​Here is the method I suspect the orders are still calling.
      private void AccountOrderUpdate(object sender, OrderEventArgs e)
      HTML Code:
      {
      Print("AccountOrderUpdate Short");​
      Print("-Order Name: " + e.Order.Name.);​
      Print("-Order: " + e.Order.ToString());​
      Print("-Sender: " + sender.ToString());​​​​
      }
      Here is an example of the print that comes out in the output 1 tab and what I cannot find in my project. I tried to use Visual Studio's search through the entire project and it can't find this Print text anywhere.
      HTML Code:
      AccountOrderUpdate Short
      -Order Name: Entry-7208e1a8-f03a-4172-9560-ba438566f335
      -Order: orderId='7b480df4de0342778b15df32de563d79' account='Playback101' name='Entry-7208e1a8-f03a-4172-9560-ba438566f335' orderState=Initialized instrument='MNQ 12-24' orderAction=Buy orderType='Stop Limit' limitPrice=20679 stopPrice=20677.75 quantity=1 tif=Gtc oco='7208e1a8-f03a-4172-9560-ba438566f335' filled=0 averageFillPrice=0 onBehalfOf='' id=39 time='2024-11-18 10:32:47' gtd='2099-12-01' statementDate='2024-11-18'
      -Sender: Playback101
      Is there something else I need to clear from the account to drop this lingering method that was added and never removed? Strange that it remains even after restarting my computer multiple times.

      Thanks again for the help!​

      Comment


        #4
        One more oddity,
        This will print out 58 times in my output, then when the order moves from Initialized to Submitted, another 58 outputs, and again on each stage of the order process.

        When I remove the strategy, reset my account, recompile, re-add the strategy, and attempt the playback again, I got more outputs per order submitted. So the next time I did this, I had 62 outputs of that "AccountOrderUpdate Short" output. Another round of the entire clearing process, and now there's 68.

        Attached is the most recent output.

        Thanks again!
        Attached Files

        Comment


          #5
          If this is a strategy, why is there code to subscribe to Account OrderUpdate events? The output indicators you are submitting orders via the managed approach.

          It is difficult to say what could be going on without actually seeing the strategy code.

          Comment


            #6
            Here is the strategy in its current form.
            Attached Files

            Comment


              #7
              Hello,

              Are you testing this from the platform? When I paste this exact code into the Editor, it doesn't compile.

              ​Please provide an export of a working version of the code.

              To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
              1. Click Tools -> Export -> NinjaScript Add-on...
              2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
              3. Click the 'Export' button
              4. Enter a unique name for the file in the value for 'File name:'
              5. Choose a save location -> click Save
              6. Click OK to clear the export location message
              By default your exported file will be in the following location:
              • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
              Below is a link to the help guide on Exporting NinjaScripts.


              Once exported, please attach the file as an attachment to your reply.

              I look forward to receiving the export.​​

              Comment


                #8
                Sorry about that Gaby, I removed some comments and it looks like I removed too much from the code I sent you. Here is the export.
                Attached Files

                Comment


                  #9
                  Hello Jimmathy,

                  I'm not seeing that output when I run your script (OrderName, Order, and Sender).

                  Do you have any other scripts running at the same time?

                  Do you perhaps have an AddOn script that has this code within it?
                  Attached Files

                  Comment


                    #10
                    Hi Gaby,
                    That's the point, that code is nowhere to be found in my code. I don't know where that is coming from. I had the code in there a few versions ago, but it has since been removed.

                    Comment


                      #11
                      Hello,

                      I understand that's the point - which is why I'm asking if (1) there are other scripts running at same time or (2) you have any AddOn script that have this code?

                      If not, I would recommend testing on a clean version of the platform.

                      You may follow the steps listed below to completely uninstall and reinstall NinjaTrader.
                      • Close all running applications.
                      • Navigate to your Documents folder > Right-click on the 'NinjaTrader 8' folder > Rename > rename the folder to 'NinjaTrader 8 OLD'. DO NOT delete this folder.
                      • Uninstall NinjaTrader within Windows Control Panel.
                      • Navigate to C:\ > Program File > Delete the 'NinjaTrader 8' folder if it exists
                      • Reboot your PC.
                      • Once these steps are completed, download and install NT8 from the link below:
                      • After you have reinstalled NinjaTrader, recreate your Live Connection.
                      ​Import and test your script on this clean installation.

                      Comment


                        #12
                        I think I was able to fix my problem. It looks like Visual Studio is not able to properly search through the entire solution and didn't find the Print I was seeing over and over again. I opened up Visual Studio Code and it was able to find it in another strategy that wasn't used.

                        However, even after I commented out the lines, recompiled, and reset the account data, I still had many instances of new orders showing the Print lines that I commented out. I also tried restarting NinjaTrader and it still persisted. It wasn't until I restarted my computer that the Prints finally stopped appearing in the output.

                        If anyone else sees NinjaScript running into what seems like a caching problem, hopefully this will help.

                        I'm curious Gaby, when you run mine and other people's strategies in your instance of NinjaTrader to test them out, do you ever have overlapping outputs that you see? Has this been an issue for other users?

                        Thanks for your help!

                        Comment


                          #13
                          Let me ask that differently.

                          How do you ensure no other strategy, add-on, indicator, etc., interferes with the strategy you want to run?

                          Comment


                            #14
                            Hello Jimmathy,

                            I have not seen this behavior reported before myself. It is expected that prints will only appear for indicator or strategy scripts that are already running, or AddOn scripts (prints from AddOn scripts will appear when you first enable a strategy or indicator).

                            Comment


                              #15
                              Understood,
                              Thanks for your help Gaby! You're using this software more than I am, so perhaps something is not working properly with my installation of NinjaTrader. I can see this same error is happening with another strategy I have not added to the chart, so I am definitely seeing this happen. Ninjascript is running the constructor of my other strategy and the printouts display when other strategy are added to the chart. I'll make sure to remove code I'm not using to avoid this issue.​

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              50 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              126 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              69 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              42 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              46 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X