Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator to count bars?

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

    Indicator to count bars?

    I'm looking for an indicator that keeps a running total of bullish and bearish bars for x period. On a given chart there were 15 bullish candles and 12 bearish candles if that makes sense. Has anyone ever seen an indicator like this before? I looked everywhere but couldn't find anything. Thanks!

    #2
    Hello Hando311,

    Welcome to our forums.

    I'm not familiar with this by name or concept but it should be pretty easy to implement with custom programming.

    Here are some questions to consider if you plan to program it:
    How are bullish and bearish candles defined?
    Are there two lines? (one for counting bullish, the other bearish)
    Is this a running total of all bars on the chart or does it reset every session?
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hello, im trying to count the last 50 bullish candles and this is what i got so far, but i think there is is something wrong, a little help please?

      {
      if (Close[0] < Close[50] )
      {
      if ( Close[0] > Open[0] )


      UpCandles = UpCandles +1;


      else

      UpCandles = UpCandles;

      }
      else
      UpCandles = 0;

      }

      Comment


        #4
        Hi kabott,

        What is wrong exactly -- are the any error messages in log tab of control center when you run this?

        Can you please clarify what is your goal with this code snippet? Are you trying to count the number of bullish bars over a 50-period lookback?
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Yes Ryan, im trying to count the number of bullish bars then bearish bars , subtract them to the the "wining " rate of bulls vs bears, the problem i have is i dont know how to tell it to start calculating from the last "xx" bars

          Comment


            #6
            I want to know how many bars did the bears Vs the bulls won over the past "X" periods

            Comment


              #7
              You could custom code a counter, but using built-in method CountIf() should work well for this:
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Ryan; i dont think this is the key (maybe i don't understand it well) but what i need is to know what code should i use to "look-back 50 bars " and start counting from there .

                if the bar is bullish then : 1,2,3,4, etc , if its bearish (inside the 50 period bar) then = keep the last count

                and start adding again if the next bar is also bullish


                Bull - Bull - Bull - Bull - Bull - Bear - Bear - Bear - Bull - Bull
                1 2 3 4 5 5 5 5 6 7


                etc,

                i got the rest done ( i think , he) but how do i tell the script to start the count from the last 50 periods back?


                thank you

                Comment


                  #9
                  Countif() has a lookback component and it returns the number of occurrences that the test condition you specify is true within this lookback. The example in the help guide uses a very similar condition to what you're looking for:

                  if (CountIf(delegate {return Close[0] > Open[0];}, 10) > 8)
                  EnterLong();
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    i must be very sleepy, sorry , i cant seem to make it work

                    i only need this part : if (CountIf(delegate {return Close[0] > Open[0];}, 10)

                    but doesn't work, cause ninja doesn't recognize it .

                    what do i do with the >8) i dont need that :P
                    Attached Files
                    Last edited by kabott; 03-07-2012, 02:13 PM.

                    Comment


                      #11
                      Just work with the value returned by the method. Try printing this and checking outputwindow:

                      if (CurrentBar > 50)
                      Print(CountIf(delegate {return Close[0] > Open[0];}, 50));

                      It returns the number of times over the last 50 bars that the close is greater than open.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        and how do i use the value?

                        this wont compile

                        if(CountIf(delegate {return Close[0] > Open[0];}, 50));

                        UpCandles =UpCandles +1;

                        else

                        UpCandles = 0;


                        Click image for larger version

Name:	i-dont-get.jpg
Views:	2
Size:	181.8 KB
ID:	864906
                        Last edited by kabott; 03-07-2012, 02:20 PM.

                        Comment


                          #13
                          Countif already does the counting for you. How you use the value returned by it is up to you.

                          If you have limited time or programming experience but have some ideas for an indicator you would like to see developed, please consider working with one of our 3rd party NinjaScript consultants:
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks for your time and advice Ryan, but i want to learn , what ever it takes, so ill keep reading from other posts, see if i figure it out

                            Comment


                              #15
                              That's a great attitude, and we're happy to see it and help you along. Try with simple approaches, printing values like shown in the post earlier. See here for additional help using Print() to debug your script:


                              CountIf is a long expression, so assigning its value to a double variable could make working with it easier.

                              These introductory tutorials are good for the structure and basics of developing indicators:
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,228 views
                              0 likes
                              Last Post xiinteractive  
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              440 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post FAQtrader  
                              Working...
                              X