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

Break infinite loop

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

    Break infinite loop

    Hello,

    unfortunately, I have an infinite loop within a NinjaScript.

    How can I break-up the execution? I tried already Ctrl-C, Ctrl-Break and the ESC-Key.

    Is there any working hotkey and do I need to kill the process NinjaTrader.exew to stop the execution?

    Best regards
    Gerik

    #2
    Well, why do you have an infinite loop in the first place? :-) Maybe you/we can optimise that part.
    When debugging/developing, try to use counter in your loop, and exit after X iterations with an IF statement.
    Infinite loops are nasty, try to evade it.

    Comment


      #3
      Hello Gerik,

      Thank you for your reply.

      You would need to most likely kill the NinjaTrader process from the Windows Task Manager, yes. There would not be a working hot key that would be able to be recognized after NinjaTrader has become unresponsive.

      If you're unable to launch NinjaTrader without triggering the loop behavior, try starting it in Safe Mode. To do this, shut down NinjaTrader, then hold the Ctrl key on your keyboard while you click on the icon to launch it. Continue to hold the Ctrl key until the Control Center comes up. You should then be able to access the NinjaScript Editor to edit or remove your script.

      I would concur with Gorkhaan here, you'd want to ensure the loops you're writing have some means to end them. If you post your an example of your loop code, I would be happy to assist you in reworking your logic so it will appropriately exit.

      Please let us know if we may be of further assistance to you.
      Kate W.NinjaTrader Customer Service

      Comment


        #4
        Hello NinjaTrader_Kate, hello Gorkhaan,

        thank you for your answer. The infinite loop occured, because I made a mistake. As suggested, I have implemented a counter to avoid the infinite loop, but I need some additional help as throw new System.InvalidOperationException("Infinite loop detection") does not seem to be the right syntax.


        while (i >= 0 && k < 100)
        {
        k=k+1;
        if (k > 50) throw new System.InvalidOperationException("Infinite loop detection");
        i=i+1
        }

        Gerik

        Comment


          #5
          Hello Gerik,

          Thank you for your reply.

          Since I have no way of knowing what the initial value of i or k is from that code, I can't speak to that part of the loop, but I would use try catch blocks instead of what you've got there with System.InvalidOperationException.

          Here's a reference sample from the forums that goes into how to use try catch blocks to handle situations in which an error could occur:


          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Hello NinjaTrader_Kate,

            thank you for your reply.

            How can I stop NinjaTrader in case the Platform is freezed? Do you have a script that kills all the tasks, so that I can avoid to restart the computer?

            Best regards
            Gerik

            Attached Files
            Last edited by Gerik; 01-22-2020, 07:36 PM.

            Comment


              #7
              Hello Gerik,

              Thank you for your reply.

              There would not be a script that would kill all the tasks, however, you should be able to access the Windows Task Manager and kill the process from there if NinjaTrader becomes unresponsive.

              Please let us know if we may be of further assistance to you.

              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hello Kate,

                thank you for your reply.

                I assume that I need only to kill NinjaTrader.exe in case calculations do not stop after a while.

                There are no other processes that have to be stopped, right?

                Best regards
                Gerik

                Comment


                  #9
                  Hello Gerik,

                  Thank you for your reply.

                  That's correct, you can just kill the main NinjaTrader task to shut it down.

                  Please let us know if we may be of further assistance to you.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Kate,

                    I have again a bug in my code, so NinjaTrader is calculating since hours and it seems that there is an infinite loop.

                    Is there any way to stop and/or cancel the strategy without killing the task with the Chart? And by the way, does NinjaTrader run with run without issue with the other charts in case I only kill one chart?

                    Kind regards
                    Gerik

                    Comment


                      #11
                      Hello Gerik,

                      Thank you for your reply.

                      No, there would not be a way to kill just the strategy or just a single chart, if it is frozen you would need to kill the entire process in the Windows Task Manager.

                      Please let us know if we may be of further assistance to you.
                      Kate W.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by gravdigaz6, Today, 11:40 PM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by MarianApalaghiei, Today, 10:49 PM
                      3 responses
                      10 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by XXtrader, Today, 11:30 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post XXtrader  
                      Started by love2code2trade, Yesterday, 01:45 PM
                      4 responses
                      28 views
                      0 likes
                      Last Post love2code2trade  
                      Started by funk10101, Today, 09:43 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post funk10101  
                      Working...
                      X