• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:
          https://ninjatrader.com/support/foru...y-catch-blocks

          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

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by rexmie888, Today, 09:37 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post rexmie888  
                  Started by jvanelli, Today, 09:23 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post jvanelli  
                  Started by lavalampmj, Today, 06:07 PM
                  1 response
                  7 views
                  0 likes
                  Last Post bltdavid  
                  Started by Sameer, Today, 04:40 PM
                  1 response
                  35 views
                  0 likes
                  Last Post NinjaTrader_EricB  
                  Started by Teebone21, Today, 04:34 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post Teebone21  
                  Working...
                  X