NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-05-2010, 05:29 AM   #1
SARdynamite
Member
 
Join Date: Dec 2009
Posts: 96
Thanks: 2
Thanked 4 times in 4 posts
Default Median indicator ?

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

Thank you
SARdynamite is offline  
Reply With Quote
Old 07-05-2010, 05:37 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,548
Thanks: 261
Thanked 1,012 times in 993 posts
Default

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 -

http://www.ninjatrader-support.com/H...V6/Median.html
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 07-05-2010, 06:20 AM   #3
SARdynamite
Member
 
Join Date: Dec 2009
Posts: 96
Thanks: 2
Thanked 4 times in 4 posts
Default

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 ?
SARdynamite is offline  
Reply With Quote
Old 07-05-2010, 06:45 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,548
Thanks: 261
Thanked 1,012 times in 993 posts
Default

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...
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 10-18-2010, 07:44 PM   #5
mnoel
Junior Member
 
Join Date: Jan 2010
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
mnoel is offline  
Reply With Quote
Old 10-18-2010, 07:45 PM   #6
mnoel
Junior Member
 
Join Date: Jan 2010
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

Sorry Ninja Trader Bertrand, I just saw your reply.
thanks.
mnoel is offline  
Reply With Quote
Old 10-19-2010, 09:48 AM   #7
DaveE
Senior Member
 
Join Date: Mar 2010
Posts: 106
Thanks: 6
Thanked 1 time in 1 post
Default 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);
DaveE is offline  
Reply With Quote
Old 10-19-2010, 09:56 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,548
Thanks: 261
Thanked 1,012 times in 993 posts
Default

Great, thanks for sharing your code Dave!
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 10-19-2010, 10:01 AM   #9
mnoel
Junior Member
 
Join Date: Jan 2010
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
mnoel is offline  
Reply With Quote
Old 11-05-2010, 08:51 AM   #10
DaveE
Senior Member
 
Join Date: Mar 2010
Posts: 106
Thanks: 6
Thanked 1 time in 1 post
Default

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()
Quote:
if (CurrentBar<period) return;
Value.Set(GetMedian(Input,period));
DaveE is offline  
Reply With Quote
Old 11-05-2010, 09:06 AM   #11
mnoel
Junior Member
 
Join Date: Jan 2010
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
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
mnoel is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Median Lines Dissapearing tommyjames Version 7 Beta General Questions & Bug Reports 9 11-30-2009 08:29 AM
Calculating the median of 4 values poseidon_sthlm General Programming 3 11-12-2009 06:50 AM
Changing historical bar values, Median? heech General Programming 3 12-08-2008 01:43 PM
Median calculation in NT stefy Indicator Development 1 05-29-2008 09:25 AM
PriceType - Median same as HLAvg? Jibu V Miscellaneous Support 10 08-03-2007 01:24 PM


All times are GMT -6. The time now is 02:01 AM.