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

using 'while'

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

    using 'while'

    It seems that if I use a 'while' loop in the OnBarUpdate(), I get a crash....

    Any comments?

    #2
    Hi Rigsby, there could be many, many reasons for a while loop to crash. Can you please post the code that is causing it?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by Rigsby66 View Post
      It seems that if I use a 'while' loop in the OnBarUpdate(), I get a crash....

      Any comments?
      Could it be that your while loop never exits and causes an infinite loop?

      For example:

      int myInt = 5;
      while (myInt == 5)
      // Do something
      RayNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Ray View Post
        Could it be that your while loop never exits and causes an infinite loop?

        For example:

        int myInt = 5;
        while (myInt == 5)
        // Do something
        Well, if for example I use:

        while (Stochastics(7, 14, 3).D[0] < 50)
        {
        Print(Stochastics(
        7, 14, 3).D[0]);
        }

        Comment


          #5
          Rigsby, the code you posted would definitely cause an infinite loop and crash NinjaTrader because the loop doesn't have an exit.
          AustinNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Austin View Post
            Rigsby, the code you posted would definitely cause an infinite loop and crash NinjaTrader because the loop doesn't have an exit.
            Well, I know that because as I already said Ninja crashes when I do it.

            The point is that there is an exit. The exit should be when the stochastics go >=50. This is the point of a while statement. It checks for a condition until it is met.... So I guess I need to do a while but grab the stochastics myself in each loop as this is obviously not happening otherwise..

            Maybe I need to add that I am not a trader and am not a C# programmer... I am a C programmer who has lost his way... LOL

            Comment


              #7
              Originally posted by Rigsby66 View Post
              Well, I know that because as I already said Ninja crashes when I do it.

              The point is that there is an exit. The exit should be when the stochastics go >=50. This is the point of a while statement. It checks for a condition until it is met.... So I guess I need to do a while but grab the stochastics myself in each loop as this is obviously not happening otherwise..

              Maybe I need to add that I am not a trader and am not a C# programmer... I am a C programmer who has lost his way... LOL
              The stochastics in each loop will always be the same value since it does not change between the time OnBarUdpate() is called and exited thus you will still have the problem.
              RayNinjaTrader Customer Service

              Comment


                #8
                Rigsby, why won't an if statment work?
                Code:
                [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Stochastics([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]7[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]).D[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]50[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]// Stochastics are less than 50. do something.[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2]
                [SIZE=2][FONT=Courier New]}
                [/FONT][/SIZE][/SIZE][/FONT]

                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Austin View Post
                  Rigsby, why won't an if statment work?
                  Code:
                  [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Stochastics([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]7[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]).D[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]50[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                  [SIZE=2][FONT=Courier New]// Stochastics are less than 50. do something.[/FONT][/SIZE][/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                  [/FONT][/SIZE]
                  I was only poking for reactions.... As I said in my firs post, "any comments"....

                  I guess I am just trying to find a more reliable cycle than OnBarUdpate()

                  Comment


                    #10
                    Originally posted by Rigsby66 View Post
                    I guess I am just trying to find a more reliable cycle than OnBarUdpate()
                    OnBarUpdate() gets called for each and every tick (if CalculateOnBarClose = false). When OnBarUpdate gets called all indicators and values and such are updated and correct.

                    Lets take a step back, what do you mean by you want to find a more reliable cycle than OnBarUpdate?
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Sorry

                      Originally posted by NinjaTrader_Austin View Post
                      Lets take a step back, what do you mean by you want to find a more reliable cycle than OnBarUpdate?
                      Sorry, reliable is not what I meant... I meant more "kind of everything and not just a bar update" and have now found OnMarketData - so problem solved on that one.

                      Thanx

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by stafe, Yesterday, 08:34 PM
                      1 response
                      15 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by jclose, Yesterday, 09:37 PM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by firefoxforum12, Yesterday, 08:53 PM
                      1 response
                      15 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by kmunroe478, Yesterday, 05:39 PM
                      2 responses
                      15 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by kevinenergy, 02-17-2023, 12:42 PM
                      115 responses
                      2,700 views
                      1 like
                      Last Post kevinenergy  
                      Working...
                      X