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 | ||
---|---|---|---|---|
Net Change
by Segwin
Started by Segwin, 05-07-2018, 02:15 PM
|
10 responses
1,769 views
0 likes
|
Last Post
by Leafcutter
Today, 03:01 AM
|
||
Change colour of Stop market and limit orders to red and green via indicator script
by Rapine Heihei
Started by Rapine Heihei, 04-23-2024, 07:51 PM
|
2 responses
30 views
0 likes
|
Last Post
by Max238
Today, 02:25 AM
|
||
Started by Shansen, 08-30-2019, 10:18 PM
|
24 responses
943 views
0 likes
|
Last Post
by spwizard
Today, 01:29 AM
|
||
Started by Max238, Today, 01:28 AM
|
0 responses
10 views
0 likes
|
Last Post
by Max238
Today, 01:28 AM
|
||
Started by rocketman7, Today, 01:00 AM
|
0 responses
7 views
0 likes
|
Last Post
by rocketman7
Today, 01:00 AM
|
Comment