Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetMedian() Bug

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

    GetMedian() Bug

    The method GetMedian() returns false results.

    To show this I have built a small indicator, which displays the median of the last 3 closes on a chart. Indicator is attached. As you can see on the chart below, the value returned for the median is not the median of the closes, but something else (yellow line).

    I have also coded an indicator, which calculates the correct median by writing values to an array and sorting them. This indicator shows on the chart as a magenta line.

    Or is there anything that I did not understand?

    By the way there is an unfortunate terminology, calling (H+L)/2 of a bar the median. This is no median but the center of the bar. The median is a statistical measure, as correctly described in the NinjaTrader help file for the NinjaScript method GetMedian(). So you can calculate a (statistical) median of a (false) median, but the results are false, anyhow.
    Attached Files

    #2
    Hello,

    Thanks for posting,

    I will look into this with my product manager on Monday.

    Thanks for your patience.

    Comment


      #3
      Hi Brett,

      thanks for your answer: Let me make a further suggestion.

      The NinjaScript method GetMedian() has another shortcoming. Actually it should be implemented in a similar way as the method MAX, the syntax would then be

      GetMedian (IDataSeries input, int period) [int barsago]

      as there is absolutely no reason to limit the use to the CurrentBar.

      I am aware that this would be a small code breaking change, but the code breaking change might be useful, as it would eliminate the false results produced by the current GetMedian() method.

      Let me know what you think about it.

      Comment


        #4
        Harry,

        I can see why this legacy documentation article can be confusing. This will be clarified in the next version. GetMedian() is not about getting the median of (H+L)/2. It is about getting the "median" of the series you input into it.

        For example, if you punch in a series of Close, you would be using the close prices and getting a median off of those close prices. If you used a lookback period of 2 you would be getting the median from the current close price and the two prior close prices. If the values were 1, 7, and 100 for those three closing prices, the median would be 7.

        Another example, if you used a lookback period of 3 you would be getting the median off the current close + last 3 prior closes. If the data set was 1, 7, 15, and 100 then the median would be the mean between 7 and 15. (7+15)/2 = 11 = median.

        The reason there is no [] bar index for GetMedian() is that this method is not an indicator and is not tied to bars indexes the same way the MAX() indicator is. If you want to you could easily create yourself an indicator to achieve the desired [] indexing capabilities.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi Josh,

          no need to explain the details of a statistical median. I had two concerns:

          (1) GetMedian() produces falls values. As shown on the chart, it does not pick 7, if the three last closes are 1, 7 and 100. It simply produces a false result. You did not comment on this.

          (2) My second post was a suggestion for an improvement, which is not mandatory, as it is easy to code a working median.

          Comment


            #6
            Harry/Sharky,

            Complete misunderstanding. I have deleted some posts to remove further confusion. In short...

            - The documentation will be updated on next update to accurately reflect the GetMedian() method
            - The lookBackPeriod parameter is a bug and will be fixed on the next update

            Thanks for your patience and understanding.
            RayNinjaTrader Customer Service

            Comment


              #7
              Update:

              - We will change the documentation to reflect how its implemented
              - We will not change the actual implementation

              The reason is that changing the internal calculation method has unknown implications to all script developers including our large 3rd party base. Instead, the documentation will change to accurately reflect how the calculation is performed so there is no confusion and we will look to resolve this with the next major version of NinjaTrader.
              RayNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by RubenCazorla, Today, 09:07 AM
              2 responses
              11 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by i019945nj, 12-14-2023, 06:41 AM
              7 responses
              81 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by timmbbo, 07-05-2023, 10:21 PM
              4 responses
              158 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by tkaboris, Today, 08:01 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by Lumbeezl, 01-11-2022, 06:50 PM
              31 responses
              819 views
              1 like
              Last Post NinjaTrader_Adrian  
              Working...
              X