![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Dec 2009
Posts: 96
Thanks: 2
Thanked 4 times in 4 posts
|
Hello, is there a "median" indicator available around ?
Thank you |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,548
Thanks: 261
Thanked 1,012 times in 993 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Dec 2009
Posts: 96
Thanks: 2
Thanked 4 times in 4 posts
|
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 ? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,548
Thanks: 261
Thanked 1,012 times in 993 posts
|
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...
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jan 2010
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Jan 2010
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
|
Sorry Ninja Trader Bertrand, I just saw your reply.
thanks. |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Mar 2010
Posts: 106
Thanks: 6
Thanked 1 time in 1 post
|
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); |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,548
Thanks: 261
Thanked 1,012 times in 993 posts
|
Great, thanks for sharing your code Dave!
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Jan 2010
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#10 | |
|
Senior Member
Join Date: Mar 2010
Posts: 106
Thanks: 6
Thanked 1 time in 1 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() Quote:
|
|
|
|
|
|
|
#11 | |
|
Junior Member
Join Date: Jan 2010
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
Regards |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |