Thank you
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!
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
NinjaTrader
Median indicator ?
Collapse
X
-
Tags: None
-
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
-
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
-
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
-
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
-
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
-
Originally posted by DaveE View PostHello 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()
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
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
1 view
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
6 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
||
Started by timmbbo, Today, 08:59 AM
|
2 responses
10 views
0 likes
|
Last Post
by bltdavid
Today, 04:10 PM
|
||
Started by alifarahani, Today, 09:40 AM
|
6 responses
41 views
0 likes
|
Last Post
by alifarahani
Today, 03:18 PM
|
Comment