Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy freezes after sitting long enough, how can I fix?

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

    Strategy freezes after sitting long enough, how can I fix?

    I'm sim testing a strategy and it'll work throughout the day just fine, but when I go to sleep and wake up I notice it's stuck on a very large trade which shouldn't be.

    To confirm I turn off the strategy and enable it back to submit and synchronize account, so if it was meant to be there it wouldn't change a thing.

    But the order disappears and immediately submits into the opposing direction.

    In this case it ended up in a multi hundred dollar loss (on a sim but if it was real would've been huge)

    Is there some way I can have an automatic "refresh" line of code to ensure this doesn't happen.

    DISCLAIMER: I have 'exit on session close" disabled if that makes a difference

    #2
    Hello unpronounceable1700,

    It may be the computer is sleeping or hibernating or may have lost connection and data wasn't being received for a bit.

    One test from the script would be to print the bar time, condition values with labels for each value and comparison operator in OnBarUpdate(), and the order.ToString() from OnOrderUpdate().
    This would show if the script has stopped updating, and where to check the log tab for errors related to sleep / hibernation / connection loss.

    Below is a link to a support article on adding debugging prints to understand behavior.


    If the OnBarUpdate() prints stop appearing, this would tell us the script is no longer processing data.
    If the prints continue appearing it will tell us why the order methods called were called and what happened with the orders.

    I would also recommend closing all open workspaces and opening a new blank workspace with a new blank chart with no template applied and no indicators added to ensure only this script is running and using resources.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello unpronounceable1700,

      It may be the computer is sleeping or hibernating or may have lost connection and data wasn't being received for a bit.

      One test from the script would be to print the bar time, condition values with labels for each value and comparison operator in OnBarUpdate(), and the order.ToString() from OnOrderUpdate().
      This would show if the script has stopped updating, and where to check the log tab for errors related to sleep / hibernation / connection loss.

      Below is a link to a support article on adding debugging prints to understand behavior.


      If the OnBarUpdate() prints stop appearing, this would tell us the script is no longer processing data.
      If the prints continue appearing it will tell us why the order methods called were called and what happened with the orders.

      I would also recommend closing all open workspaces and opening a new blank workspace with a new blank chart with no template applied and no indicators added to ensure only this script is running and using resources.
      Thank you.

      I did have a few indicators up, editor, and strategy analyzer. So I closed them all down and it was still running come morning which is good. So I'll have to see if it continues to work.

      But would you happen to know the basics of getting StreamWriter going. I've imported the indicator into Ninjatrader, but don't know how to actually import it into my script, and how to set the actual path the file will be created in.

      Comment


        #4
        Hello unpronounceable1700,

        The SampleStreamWriter example is meant for you to learn from so you can code your own scripts to use a C# StreamWriter.


        To import a NinjaScript into NinjaTrader 8 do the following:
        1. Download the script to your desktop, keep it in the compressed .zip file.
        2. From the Control Center window select Tools -> Import -> NinjaScript Addon...
        3. Click the Desktop icon on the left to navigate to the desktop
        4. Select the downloaded .zip file -> then click Open
        5. NinjaTrader will then confirm if the import has been successful.
        Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.

        Below is a link to the help guide on importing NinjaScripts.
        https://ninjatrader.com/support/help...-us/import.htm


        Once imported, you can view the code of the script by opening the NinjaScript Editor from the Control Center > New menu.

        On the Explorer pane on the right double click to open Indicators > double click to open SampleStreamWriter.
        This allows you to view the code and learn how to use a C# StreamWriter to write information to a file with a provided path.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello unpronounceable1700,

          The SampleStreamWriter example is meant for you to learn from so you can code your own scripts to use a C# StreamWriter.


          To import a NinjaScript into NinjaTrader 8 do the following:
          1. Download the script to your desktop, keep it in the compressed .zip file.
          2. From the Control Center window select Tools -> Import -> NinjaScript Addon...
          3. Click the Desktop icon on the left to navigate to the desktop
          4. Select the downloaded .zip file -> then click Open
          5. NinjaTrader will then confirm if the import has been successful.
          Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.

          Below is a link to the help guide on importing NinjaScripts.
          https://ninjatrader.com/support/help...-us/import.htm


          Once imported, you can view the code of the script by opening the NinjaScript Editor from the Control Center > New menu.

          On the Explorer pane on the right double click to open Indicators > double click to open SampleStreamWriter.
          This allows you to view the code and learn how to use a C# StreamWriter to write information to a file with a provided path.

          Oh yeah I imported it and checked the sample but when I try to copy paste the code into my strategy I get two errors:
          1 - The type or namespace name 'StreamWriter' could not be found (CS0246)
          2 - The name 'File' does not exist in the current context (CS0103)

          Do I need to reinstall Ninjatrader or is there just something I'm missing?

          SOLVED: Figured out I needed to add
          using System.IO
          Last edited by unpronounceable1700; 10-30-2024, 05:43 PM.

          Comment


            #6
            Hi ChelseaB,

            Regarding your comment below for Importing NinjaScript Add-on for Strategy:

            Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.

            I did import from my laptop to VPS and said "Yes" to these. How do I undo it?

            After I have imported my strategy and said "Yes", I tested the imported strategy to the strategy analyzer to compare the results from my laptop, however, there some difference in the results. Not sure if that's the effect of it.

            Can you please help me fix it. Thanks

            Comment


              #7
              Hello mrrdiamante,

              "I did import from my laptop to VPS and said "Yes" to these. How do I undo it?"

              Run the repair from the NinjaTrader installer to replace system NinjaScripts with the original versions.


              "After I have imported my strategy and said "Yes", I tested the imported strategy to the strategy analyzer to compare the results from my laptop, however, there some difference in the results. Not sure if that's the effect of it."

              Differences in the results when the code is exactly the same is typically due to differences in data.

              See the support article linked below.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              44 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              124 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              65 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