• 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

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by sidlercom80, Today, 12:29 PM
          1 response
          18 views
          0 likes
          Last Post NinjaTrader_Jim  
          Started by itrader46, Today, 02:49 PM
          2 responses
          7 views
          0 likes
          Last Post itrader46  
          Started by m94306, Today, 03:01 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Heath  
          Started by fx.practic, Today, 02:54 PM
          3 responses
          8 views
          0 likes
          Last Post fx.practic  
          Started by MarianApalaghiei, 07-14-2019, 04:00 AM
          5 responses
          62 views
          0 likes
          Last Post koganam
          by koganam
           
          Working...
          X