Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

statistics of values

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

    statistics of values

    hi,

    if i have an indicator. and the current value is 10.

    then if i look back a 100 values; out of the 100 values the current value '10' showed up 50 times. therefore, 50/100 = 50% of the data = 10.

    how can i do this in NT?

    essentially what i want to do is

    lookup the # of times the current value comes up in the past 10000 bars

    thanks


    i havnt tested this since i'm at work

    but would this work?

    Code:
    if (CountIf(delegate {return IndicatorValue[0];}, 10000) ;
    // create a count for the current value in the last 10000 values?
    Last edited by staycool3_a; 11-18-2014, 09:25 AM.

    #2
    Hello calhawk01,

    Thank you for your post.

    The code would be the following:
    Code:
    int count = CountIf(delegate {return IndicatorValue[0] == 10;}, 10000);
    double percent = count/10000;

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello calhawk01,

      Thank you for your post.

      The code would be the following:
      Code:
      int count = CountIf(delegate {return IndicatorValue[0] == 10;}, 10000);
      double percent = count/10000;


      Pat, thanks

      That code works. Only issue is that the "10" value had to be static. Meaning 10 is supposed to be the current value of the indicator. The goal is to find out statistics if your indicators current value

      I tried indicatorvalue[0] == indicatorvalue[0] for past 1000 bars. But that returns a 1... Which is correct since this compares the value to itself.

      Any idea how I can compare the current value and see how many times it occurred in 1000 bars?

      Also the code you posted doesn't compile. Error said that you cannot use a [] for double value during indexing

      Int count ......indicatorvalue[0]

      Indicatorvalue is a double

      Here is the code I got

      Double a,b,c,e;

      A= bollinger band upper
      B= bollinger band lower
      C= a/b-1
      int count = CountIf(delegate {return C[0] == c;}, 10000);
      double percent = count/10000;
      Last edited by staycool3_a; 11-18-2014, 12:26 PM.

      Comment


        #4
        Hello calhawk01,

        I do apologize, but I do not understand what you are going for here. Perhaps you can provide the full code used or the .cs file?

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          Hello calhawk01,

          I do apologize, but I do not understand what you are going for here. Perhaps you can provide the full code used or the .cs file?
          you were spot on with the initial suggestion but it doesnt work properly.

          what i'm trying to do is to calculate the statistics of my indicators current value. in other words, if i an RSI indicator ranges from 0 to 100. and current value is 90. i want to know how many times 90 was the value for this indicator in the past 1000 bars. so we have to count the # of times 90 showed up in the past 1000 bars.



          Code:
          Double a;
          a= rsi(14) 
          int count = CountIf(delegate {return a[0] == a;}, 10000);
          double percent = count/10000;
          ///the above doesn't compile "cannot apply indexing with [] to an expression of type 'double'
          if i try


          Code:
          Double a;
          a= rsi(14) 
          int count = CountIf(delegate {return [B]a[/B] == a;}, 10000);
          double percent = count/10000;
          the above compiles. but the output is 1. since a is always going to = a.
          Last edited by staycool3_a; 11-18-2014, 01:29 PM.

          Comment


            #6
            Hello calhawk01,

            Thank you for your response.

            The code should be the following:
            Code:
            double a = 10; // enter you desired value to check against
            int count = CountIf(delegate {return RSI(14) == a;}, 10000);
            double percent = count/10000;
            If you want the double 'a' to be a user defined parameter please take a look at the information in the following link: http://www.ninjatrader.com/support/f...ead.php?t=5782

            Comment


              #7
              Originally posted by NinjaTrader_PatrickH View Post
              Hello calhawk01,

              Thank you for your response.

              The code should be the following:
              Code:
              double a = 10; // enter you desired value to check against
              int count = CountIf(delegate {return RSI(14) == a;}, 10000);
              double percent = count/10000;
              If you want the double 'a' to be a user defined parameter please take a look at the information in the following link: http://www.ninjatrader.com/support/f...ead.php?t=5782
              are we looking at this the wrong way? i'm not sure if i'm explaining this correctly. I'm not trying to make double a to be a user defined parameter.

              all i'm trying to do is get the count of the CURRENT value of RSI(14)[0] and see how many times this value was posted in the last 1000 bars.

              for example; if current value of RSI(14)[0] is 90

              last 10 bars of RSI(14)=

              90 90 90 90 90 90 100 100 100 100; then the count should be 6 bars in the last 10 bars == rsi(14)[0]

              the current can change all the time. i dont want it to remain the same value..... current value changes with time

              Code:
              double a = 10; // enter you desired value to check against
              int count = CountIf(delegate {return RSI(14) == a;}, 10000);
              double percent = count/10000;

              Comment


                #8
                Originally posted by calhawk01 View Post
                you were spot on with the initial suggestion but it doesnt work properly.

                what i'm trying to do is to calculate the statistics of my indicators current value. in other words, if i an RSI indicator ranges from 0 to 100. and current value is 90. i want to know how many times 90 was the value for this indicator in the past 1000 bars. so we have to count the # of times 90 showed up in the past 1000 bars.



                Code:
                Double a;
                a= rsi(14) 
                int count = CountIf(delegate {return a[0] == a;}, 10000);
                double percent = count/10000;
                ///the above doesn't compile "cannot apply indexing with [] to an expression of type 'double'
                if i try


                Code:
                Double a;
                a= rsi(14) 
                int count = CountIf(delegate {return [B]a[/B] == a;}, 10000);
                double percent = count/10000;
                the above compiles. but the output is 1. since a is always going to = a.
                Code:
                double a = 0.0;
                a = RSI(14)[0];
                int count = CountIf(delegate {return RSI(14)[0] == a;}, 10000);
                double percent = count/10000;

                Comment


                  #9
                  The code below will check how many times in the last 10,000 bars the RSI equaled 10.
                  Originally posted by NinjaTrader_PatrickH View Post
                  Code:
                  double a = 10; // enter you desired value to check against
                  int count = CountIf(delegate {return RSI(14) == a;}, 10000);
                  double percent = count/10000;
                  Please test this code and set the value of a to the value you are looking for, whether 10 or 90.

                  Comment


                    #10
                    Originally posted by NinjaTrader_PatrickH View Post
                    The code below will check how many times in the last 10,000 bars the RSI equaled 10.

                    Please test this code and set the value of a to the value you are looking for, whether 10 or 90.
                    Pat the above works.

                    but the issue is i do not want to define the ''10''. The 10 should be whatever the rsi[0] value is. i'm trying to look back a 1000 bars to see how many times the current rsi[0] value occurred. the current changes every single second...

                    Comment


                      #11
                      Then koganam's code would be correct.
                      Originally posted by koganam View Post
                      Code:
                      double a = 0.0;
                      a = RSI(14)[0];
                      int count = CountIf(delegate {return RSI(14)[0] == a;}, 10000);
                      double percent = count/10000;

                      Comment


                        #12
                        Originally posted by NinjaTrader_PatrickH View Post
                        Then koganam's code would be correct.
                        that doesnt even compile.

                        could it be because the custom indicator that I have is using multi instruments?

                        here is the complete code that I am trying to compile

                        Code:
                                    
                                    double a,b,c;
                                    a = Bollinger(PairsRatio("ES 12-14", "NQ 12-14").Ratio, 4, 720).Upper[0];
                                    b = Bollinger(PairsRatio("ES 12-14", "NQ 12-14").Ratio, 4, 720).Lower[0];
                                    c = a/b-1;           
                                    double d = 0.0;
                                    d = c[0];
                                    int count = CountIf(delegate {return c[0] == d;}, 10000);
                                    double percent = count/10000;        
                                    
                                    {
                                        Values[0].Set(percent);
                                        Values[1].Reset();
                                    }
                        error = Indicator\Bandstats.cs Cannot apply indexing with [] to an expression of type 'double' CS0021 - click for info 51 8

                        Comment


                          #13
                          Originally posted by calhawk01 View Post
                          that doesnt even compile.

                          could it be because the custom indicator that I have is using multi instruments?

                          here is the complete code that I am trying to compile

                          Code:
                                      
                                      double a,b,c;
                                      a = Bollinger(PairsRatio("ES 12-14", "NQ 12-14").Ratio, 4, 720).Upper[0];
                                      b = Bollinger(PairsRatio("ES 12-14", "NQ 12-14").Ratio, 4, 720).Lower[0];
                                      c = a/b-1;           
                                      double d = 0.0;
                                      d = c[0];
                                      int count = CountIf(delegate {return c[0] == d;}, 10000);
                                      double percent = count/10000;        
                                      
                                      {
                                          Values[0].Set(percent);
                                          Values[1].Reset();
                                      }
                          error = Indicator\Bandstats.cs Cannot apply indexing with [] to an expression of type 'double' CS0021 - click for info 51 8
                          Your error code rather clearly tells us what is not kosher. You have "c" declared as a double, then you try to refer to it with an index. A double is not a collection of any kind, so a double cannot be referenced as an indexed structure.

                          If you want to do it the way that you have written, then make "c" a DataSeries, and set it up properly. Then you can refer to its values using an index.

                          Without being snarky, if I might add, when you pose a more or less hypothetical scenario with specific data, and are given code to handle that scenario, you might want to test that code for validity in the scenario that you posed, instead of changing the code first to do something else. That way you can really isolate the issue to the changes that you may have made post-acquisition of the code.
                          Last edited by koganam; 11-19-2014, 07:45 AM.

                          Comment


                            #14
                            Originally posted by koganam View Post
                            Your error code rather clearly tells us what is not kosher. You have "c" declared as a double, then you try to refer to it with an index. A double is not a collection of any kind, so a double cannot be referenced as an indexed structure.

                            If you want to do it the way that you have written, then make "c" a DataSeries, and set it up properly. Then you can refer to its values using an index.

                            Without being snarky, if I might add, when you pose a more or less hypothetical scenario with specific data, and are given code to handle that scenario, you might want to test that code for validity in the scenario that you posed, instead of changing the code first to do something else. That way you can really isolate the issue to the changes that you may have made post-acquisition of the code.
                            OMG STOP BEING SNARKY!!!!!

                            LOL just kidding!

                            man i always appreciate your help. And NT help. You guys are awsome.

                            Thanks for always being there!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Aviram Y, Today, 05:29 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post Aviram Y  
                            Started by quantismo, 04-17-2024, 05:13 PM
                            3 responses
                            25 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by ScottWalsh, 04-16-2024, 04:29 PM
                            7 responses
                            34 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by cls71, Today, 04:45 AM
                            0 responses
                            6 views
                            0 likes
                            Last Post cls71
                            by cls71
                             
                            Started by mjairg, 07-20-2023, 11:57 PM
                            3 responses
                            217 views
                            1 like
                            Last Post PaulMohn  
                            Working...
                            X