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

Counting problem

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

    Counting problem

    Hi,

    I'm trying to count the number of consecutive bars where close[0] < close[4]. I can get it to count but when it encounters close[0] > close [4] and then a new close [0] < close [4]. it continues from the last number counted. how do i get it to reset itself?
    So for example, there are 4 bars where each consecutive close is less than their respective close 4 bars ago. The counter would've counted to 4. then it encounters a bar where its close is greater than the close 4 bars ago. it correctly doesn't count it. subsequently it comes across a bar where the close is again lower the the close 4 bars ago. it counts that bar as a '5'. How do i get it to count '1' again?

    this is what i have so far:-

    if (Close[0]<Close[4])
    {
    BuySetupCount++;
    DrawText((CurrentBar.ToString() +
    "BS"), BuySetupCount.ToString(), 0, (Low[0]-TickSize), Color.Green);
    if (BuySetupCount == 9)
    {
    BuySetupCount =
    0;
    }
    }







    #2
    if (Close[0]<Close[4])
    {
    BuySetupCount++;
    DrawText((CurrentBar.ToString() +
    "BS"), BuySetupCount.ToString(), 0, (Low[0]-TickSize), Color.Green);

    }
    else BuySetupCount = 0;

    Comment


      #3
      kaywai, Baruch's code should do the trick. Let us know if you have any other questions.
      AustinNinjaTrader Customer Service

      Comment


        #4
        good stuff! thx baruch!

        now, if i wanted to remove the tags for those counts that didn't make 9 consecutive bars lower than their respective bars 4 bars ago (in other words, they counted to 4 or 7 for example), how would i do that?

        Comment


          #5
          You need another counter.
          if (Close[0]<Close[4])
          {
          BuySetupCount++;
          DrawText((Buys * 10 + BuySetupCount +
          "BS"), BuySetupCount.ToString(), 0, (Low[0]-TickSize), Color.Green);

          }
          else BuySetupCount = 0;
          if (BuySetupCount == 9)
          {
          BuySetupCount =
          0;

          Buys++;
          }

          Comment


            #6
            Wow! Thanks Baruch!

            If you don't mind and it's not too much trouble, could you please explain the logic behind

            1) the need for 2 counters
            2) why "Buys * 10" and what it means?
            3) why "Buys++" comes later?
            4) how your code actually removed counts without using "RemoveDrawObject(Tags)"?

            BTW, the more current bars for some reason seem to be buggy...not sure why. but the others work perfectly. Chart is attached.
            Attached Files
            Last edited by kaywai; 02-22-2010, 07:13 AM.

            Comment


              #7
              Hi Kaywai,
              Buys is just for the drawing tag name. Each time you have BuySetupCount == 9 you increase it so your tag name will be:
              11, 12,13,14...19,21,22,23..29.
              You can't have more than one draw object with the same name so if you start BuySetupCount from the begining you don't increment the Buys. So NT draws new text with the same Tag name so it removes the old text and adds new. Thats why you still have some unwanted text.

              Baruch

              Comment


                #8
                Baruch, i think i get what you are saying.

                i just have to work out how to remove the unwanted text now just so i get a neat chart.

                Thanks!

                Comment


                  #9
                  kaywai,

                  You can remove old draw objects with the RemoveDrawObject() code you already outlined.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    That's right Josh.

                    Just need to think how to write the code to do that as some counts go up to 8 and stop and others count to 1 and stop.

                    Any help or pointers in that direction is deeply appreciated!

                    Comment


                      #11
                      Best bet would be to work on paper and try to walk through each step by hand on a simple case. Then you can work and try to duplicate that logic.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Josh, Great Advice! I've got it to where I want it to be now! Thanks!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ninza33, Today, 12:31 PM
                        2 responses
                        9 views
                        0 likes
                        Last Post ninza33
                        by ninza33
                         
                        Started by Bobin, 03-12-2024, 08:51 AM
                        15 responses
                        480 views
                        0 likes
                        Last Post fiddich
                        by fiddich
                         
                        Started by Skifree, Today, 11:21 AM
                        4 responses
                        13 views
                        0 likes
                        Last Post Skifree
                        by Skifree
                         
                        Started by Bogdan097, Today, 03:25 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post Bogdan097  
                        Started by cmtjoancolmenero, 04-25-2024, 03:58 PM
                        25 responses
                        127 views
                        0 likes
                        Last Post cmtjoancolmenero  
                        Working...
                        X