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

Ranking Indicator Values

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

    Ranking Indicator Values

    Hi,
    is there a way in ninjatrader to compare and rank the current indicator value to, lets say, its last 100 values ?
    thanks in advance for your help

    #2
    Hello,

    Thanks for the note.

    You can use Min or Max for example to to return the max or min value from a sample period. However if you want a more percentile rank let me know and I can send you more information on how to do this.



    I look forward to assisting you further.

    Comment


      #3
      Brett, thanks for your reply. yes, percentile rank is exactly what i'm looking for. could you please help me with this. thanks much

      Comment


        #4
        Hello,

        There is currently no built in method for this inside of NinjaTrader. Therefor you will need to simply loop through the previous values and create a for loop to do this.

        for(i = 0; i > 100; i++)
        {

        Close[i];

        }

        This is how you would loop though and is an example. When your looping you will want to do some calculation to get your positioning in the queue. How many values are greater then and how many values are less then the value you are comparing.

        Let me know if I can be of further assistance.

        Comment


          #5
          thanks Brett, will try along those lines....

          Comment


            #6
            If you still need this, I have just uploaded a Percentile indicator to the NT7 file sharing area. You can use it to plot median values of the last N bars, or any percentile of the last N bars. It's an efficient, fast algorithm, too.

            Comment


              #7
              Hi anachronist,

              I'm looking for a ranking algorithm - something that works like the PERCENTRANK function in Excel. I tried doing a quick search for your percentile indicator but couldn't find it. Could you provide me with a title/name to search for or maybe a link?

              Comment


                #8
                Hi PhillyD. You have to go to the forum home page, scroll down to the the file sharing area, select NinjaTrader 7 indicators, then browse the alphabetical list until you find it.

                Note that this indicator won't work with real-time data. It works only on static or end-of-day data.
                -Alex

                Comment


                  #9
                  OK, thanks. Is there any particular reason why it doesn't work on real-time data? I was hoping to use it in both backtesting and live trading on intraday price data.

                  Comment


                    #10
                    Originally posted by PhillyD View Post
                    OK, thanks. Is there any particular reason why it doesn't work on real-time data?
                    Many indicators don't work on real time data if they just use the last N closes without accounting for FirstTickOfBar. In this case, if you try using the Percentile indicator on real time data, you'll get a percentile value of the last N ticks rather than the last N bars, which is probably not what you want. Of course, if you're already using tick bars, then no problem as long as you don't exceed 255 in your lookback window.

                    I have a revised version that should work on real time data, but because I no longer have a real time feed, I'm reluctant to release it until I can test it.

                    I could probably test it with my Interactive Brokers data but (and NT Support can correct me if I'm wrong) I believe my lifetime NT license prohibits connecting NT to Interactive Brokers. Or maybe it's just placing orders through IB? I'm not sure.

                    Comment


                      #11
                      Ok, that makes sense. I'm using bar data, not tick data.

                      If you want, I can test the revised version using NT/IB. I have no issue connecting to my IB account.

                      Comment


                        #12
                        Here is an example how to determine the percentage rank of the CurrentBar based on the rate of change (ROC). rankPeriod is an integer that holds the number of bars that are used for the comparison. The code can be used in OnBarUpdate().

                        Code:
                        if (CurrentBar < 1)
                            return;
                        int barsAgo = Math.Min(rankPeriod, CurrentBar);
                        double rank = 0.0;
                        for (int i = 1; i <= barsAgo; i++)
                            if(rateOfChange[0] > rateOfChange[i])
                                rank = rank + 1.0;
                        double percentRank = 100 * rank/barsAgo;

                        The algorithm also works with setting CalculateOnBarClose = false, but will then create a moderate CPU load during high volume events such as news releases.
                        Last edited by Harry; 03-04-2015, 05:03 AM.

                        Comment


                          #13
                          Harry,

                          I walked through that code step by step and it looks simple and elegant. Thank you.

                          I'll be using end of bar data only, so I won't have a CPU load problem.

                          Comment


                            #14
                            I have a follow up question...

                            How exactly should I handle the coding if I wanted to do a percentile ranking on the results of a percentile ranking?

                            For example, let's say I use this code to get a percentile ranking value for the current bar, using 50 bars as the lookback period.

                            Then, I want to take the percent rank values for the past 20 bars and rank the current bar's percent rank value against those percent rank values.

                            Could I just have the code calculate the percent rank value for the ith previous bar on-the-fly, or do I need to have this code pass the previous 20 percent rank values into an array?

                            Edit - to clarify: can I use the above code to write a new indicator, let's say I call it PercentRank, that's called as follows: PercentRank(rankPeriod2,RateOfChange indicator)[0]

                            and then apply a PercentRank to this in a nested fashion, as in:

                            PercentRank(rankPeriod1,(PercentRank(rankPeriod2,R ateOfChange indicator)[0])[0]

                            or do I have to create a DataSeries array that stores rankPeriod2 number of historical PercentRank points to accomplish the same goal?
                            Last edited by PhillyD; 03-04-2015, 12:28 PM.

                            Comment


                              #15
                              What should the percentile ranking of a percentile ranking be good for? It would be mostly identical with the original percentile ranking but cause a high CPU load.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RookieTrader, Today, 09:37 AM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by kulwinder73, Today, 10:31 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post kulwinder73  
                              Started by terofs, Yesterday, 04:18 PM
                              1 response
                              23 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by CommonWhale, Today, 09:55 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Gerik, Today, 09:40 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post Gerik
                              by Gerik
                               
                              Working...
                              X