Announcement

Collapse
No announcement yet.

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:
                if (Stochastics(7, 14, 3).D[0] < 50)
                {
                // Stochastics are less than 50. do something.
                }
                

                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Austin View Post
                  Rigsby, why won't an if statment work?
                  Code:
                  if (Stochastics(7, 14, 3).D[0] < 50)
                  {
                  // Stochastics are less than 50. do something.
                  }
                  
                  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 toughiee, Today, 12:04 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post toughiee  
                      Started by vdoan20, Yesterday, 08:30 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post vdoan20
                      by vdoan20
                       
                      Started by gupagoer, Yesterday, 07:42 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post gupagoer  
                      Started by Holligoly, Yesterday, 05:13 PM
                      2 responses
                      11 views
                      0 likes
                      Last Post Holligoly  
                      Started by Raginpower, Yesterday, 01:53 PM
                      0 responses
                      14 views
                      0 likes
                      Last Post Raginpower  
                      Working...
                      X