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 indicator ?

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

    Median indicator ?

    Hello, is there a "median" indicator available around ?

    Thank you

    #2
    I'm not exactly sure what you mean by this, but the Median price can be directly accessed with the Median() method in your scripts -

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello,

      No that's not what I meant.

      Median is a very specific mean indicator.

      If the period is 5 then the median indicator should find the value the way that 2 values are below the median value, and 2 other values are above the median value.

      Example with a series of 7 values (=input = Close for what it's worth) :
      4 / 5 / 9 / 15 / 21 / 24 / 34

      while the SMA(7) would have been (4+5+9+15+21+24+34)=16
      ...the median price is 15 just because 3 numbers are below it and 3 other numbers are above it

      does the median price indicator exist on NT ?

      Comment


        #4
        SARdynamite, I see thanks for clarifying - unfortunately this does not exist per default in NinjaTrader. You would find perhaps various C# methods to calculate this via a Google search...
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hello, I am also looking into an indicator being able to calculate the median price over a certain period of time. The median () function in Ninja only finds the median price within the same bar. What I am looking for is the same as SARdynamite. Is it available within Ninja? Or do you know if there is a code somewhere?
          Thanks in advance.

          Comment


            #6
            Sorry Ninja Trader Bertrand, I just saw your reply.
            thanks.

            Comment


              #7
              Code for MedianIndicator

              Here's the code. Perhaps mnoel & SARdynamite could share their trading tips for its use?

              /*1) Use a default of 5 for Period parameter.
              Use a minimum of 3 for Period parameter (looks at current plus 2 previous). Since MedianIndicator(2) would give same result as SMA(2)
              */

              //2) Add this line to "Using declarations"
              using System.Collections.Generic;

              //3) In Initialize:
              Overlay = true;

              //4) use this in OnBarUpdate():
              if (CurrentBar<period) return;

              List<double> vals = new List<double>();
              for (int i = 0; i < period; i++)
              {
              vals.Add(Input[i]);
              }
              vals.Sort();
              decimal midindex=(period-1)/2m; //if period is even this will be ?.5 (eg period=2 gives 0.5, so need mean of values at 0 and 1)
              double val=0;

              if (Math.Floor(midindex)==midindex)
              {//odd period, just use middle value from sorted list
              val=vals[(int)midindex];
              }
              else
              {//even period, use mean of the two middle values
              val=(vals[(int)Math.Floor(midindex)] + vals[(int)Math.Ceiling(midindex)])/2;
              }

              Value.Set(val);

              Comment


                #8
                Great, thanks for sharing your code Dave!
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Thank you very much DaveE for your code. I am new to programming in C#. I just switch from Metastock. I need this code in order to calculate the median volume over a certain period of time. This information is used to calculate the effective volume of a security (see Pascal Willain's book, Value in time).

                  I will keep you posted when I succeed in programming the rest.

                  Comment


                    #10
                    Hello mnoel,

                    Thanks for the feedback.
                    I just noticed that NT has a built in function GetMedian(), that must have similar code to my sample below. For some reason GetMedian() was not wrapped into an indicator. The simplest way to make a MedianIndicator is to use this code in OnBarUpdate()
                    if (CurrentBar<period) return;
                    Value.Set(GetMedian(Input,period));

                    Comment


                      #11
                      Originally posted by DaveE View Post
                      Hello mnoel,

                      Thanks for the feedback.
                      I just noticed that NT has a built in function GetMedian(), that must have similar code to my sample below. For some reason GetMedian() was not wrapped into an indicator. The simplest way to make a MedianIndicator is to use this code in OnBarUpdate()
                      Thank you again DaveE. Much appreciated! I have not started yet. Probably an Holiday project.
                      Regards

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by DJ888, 04-16-2024, 06:09 PM
                      6 responses
                      18 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by Jon17, Today, 04:33 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post Jon17
                      by Jon17
                       
                      Started by Javierw.ok, Today, 04:12 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post Javierw.ok  
                      Started by timmbbo, Today, 08:59 AM
                      2 responses
                      10 views
                      0 likes
                      Last Post bltdavid  
                      Started by alifarahani, Today, 09:40 AM
                      6 responses
                      41 views
                      0 likes
                      Last Post alifarahani  
                      Working...
                      X