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

median

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

    median

    hy folks,

    is it possible in nt7 to calculate median from a set of numbers?
    i mean:
    ... the numerical value separating the higher half of a data sample, a population, or a probability distribution, from the lower half...

    #2
    Hello Andre,

    Thank you for your note.

    Yes, this is possible with C# in NinjaScript but note that this type of programming is unsupported with NinjaTrader.

    You would need to create a List that you can then load numbers into and the sort numerically so that you can then find the median.

    http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      You can calculate a median from the last N closes, from the TPOs or VWTPOs by using the last N bars. I have coded the TPO and VWTPO variations for the mean, the median and the mode, and also developed a median of the current session with percentile bands. Below is a description of the indicator package (which is free and comes open source)

      This package includes a TPO mean, a TPO median, a TPO mode (calculated from high and low points of price) and a VWTPO mean, a VWTPO median and a VWTPO mode (calculated from both price and volume data). TPO and VWTPO indicators do not use the open value and the close value, but both assume that the volume is evenly distributed over the range of a price bar. Although this information is mostly incorrect, it is still a better approach when compared to the traditional solution of calculating indicators exclusively from the close values.

      Here is a description of the six indicators:

      Moving Mean (TPO):

      This indicator can be considered as a range weighted moving average that uses the bar center (high + low)/2 as input series. Usually wide range bars have a higher volume than narrow range bars. This makes sense giving them a higher weight. When a breakout occurs, the MovingMean (TPO) will adapt faster than a traditional SMA. Compared to a SMA the lag is reduced when volatility increases, but it is lagging more when volatility decreases.

      Moving Mean (VWTPO):

      This indicator is identical to the VWMA, when the bar center (high + low)/2 is used as input series. It is pretty similar to the TPO mean, but uses real volume instead of approximating it via the range. The properties of this indicator are similar to the TPO mean, but it should be slightly more accurate.

      Moving Median (TPO):

      A statistical median calculated from all data points of all bars contained within the lookback period. Compared to a standard median calculated from the closes, it should give a better approximation of the statistical median of the entire price volume distribution. The median is the most stable of the three statistical measures and probably the most representative as well.

      Moving Median (VWTPO):

      This indicator is similar to the TPO median, but should give an even better approximation of the the statistical median of the price volume distribution.

      Moving Mode (TPO):

      The indicator shows the price with the highest occurence over the lookback period of the indicator. As the price volume distribution of the single price bars over the lookback period is unknown, there can be a significant error in any estimation. Unlike the median, the mode is not self-correcting in a way that errors cancel out. It should therefore be used with prudence. However, this indicator will still yield far better results than the Pearson formula, which should only be applied to unimodal distributions.

      Moving Mode (VWTPO):

      The indicator shows a better accuracy than the TPO mode, but still suffers from its inherent instability.

      The indicators can be downloaded here:

      The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies


      The link to a standard median calculated just from the closes is here:

      The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies


      I have used the standard median as input series for a number of indicators such as the SuperTrend, MACD, Stochastics.

      If you are not an elite member of Big Mike's, but want to use the indicators, just send me a private message.

      Comment


        #4
        Here is a developing median with 68% and 95% percentile bands for yesterday's regular session for ES 06-14. The median is calculated from 3 min VWTPOs (same time frame as the chart). I have another version in preparation that will let you select the underlying timeframe of the TPOs or VWTPOs independently from the chart period.
        Attached Files

        Comment


          #5
          For those interested, I have just uploaded a Percentile indicator to the NT7 file sharing area.

          You can plot any percentile. To plot a median, just specify 50 as the percentile.

          It uses an efficient algorithm with no sorting per bar, and calculates exact values.

          Update: It's intended for EOD bars. I have another version that should work in real time as ticks come in, updating only when a bar is complete, but since I no longer have a live feed, I can't test it so I'm hesitant to upload it.
          Last edited by anachronist; 12-18-2014, 02:32 PM.

          Comment


            #6
            Hi Harry,

            I could not download the Moving Median (TPO) at BigMike, I am not a elite member.
            Could you please, post in this forum ?

            thanks

            Comment


              #7
              Originally posted by cbahia View Post
              Hi Harry,

              I could not download the Moving Median (TPO) at BigMike, I am not a elite member.
              Could you please, post in this forum ?

              thanks
              Not double-posting, but if you send me a private message with your e-mail, I will send it.

              Comment


                #8
                Originally posted by andre.adamov View Post
                hy folks,

                is it possible in nt7 to calculate median from a set of numbers?
                i mean:
                ... the numerical value separating the higher half of a data sample, a population, or a probability distribution, from the lower half...
                If you want a Moving Median indicator, I have one for you: http://ninza.co/product/moving-median
                ninZa
                NinjaTrader Ecosystem Vendor - ninZa.co

                Comment


                  #9
                  The median is a statistical measure of all trades over a given period. If you use price bars - other than 1 tick bars - you do not know the exact price volume distribution inside each of the price bars. Therefore any median indicator produces an estimate. The simplest way of making an estimate is just to use the closing price of the bar. Of course this approach will not produce any accurate results as much of the data that is available is not used. A better approach would also use the open, high and low prices as well as the volume.

                  Let us look at an example:

                  simple median (N) - median price calculated from N closes
                  TPO median (N) - median price calculated from all time price opportunities over the last N bars
                  VWTPO median (N) - median price calculated from volume-weighted time price opportunities over the last N bars

                  Both TPO and VWTPO approach still assume a linear distribution of the trades within the price bars. This is a pretty simplistic assumption, as it only relies on the high and the low of the bar, but does not take into account open and close price. The weight attributed to the TPOs covered by the body of a candlestick is identical to the weight attributed to the upper and lower shadows. A further improvement can be obtained when replacing the linear distribution with a non-linear one that uses the open and the close price of the candle.

                  Sample chart: shows a simple, a TPO and a VWTPO approximation of a 34-bar median.
                  Attached Files
                  Last edited by Harry; 12-20-2014, 09:01 AM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by inanazsocial, Today, 01:15 AM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Jason  
                  Started by rocketman7, Today, 02:12 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post rocketman7  
                  Started by dustydbayer, Today, 01:59 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post dustydbayer  
                  Started by trilliantrader, 04-18-2024, 08:16 AM
                  5 responses
                  23 views
                  0 likes
                  Last Post trilliantrader  
                  Started by Davidtowleii, Today, 12:15 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Davidtowleii  
                  Working...
                  X