Median

Modified on 2008/04/18 09:11 by Administrator — Categorized as: Standard Indicators

Syntax

public Median(DataSeries source, int period, string description) public static Median Series(WealthLab.DataSeries source, int period) public static double Value(int bar, DataSeries source, int period)

Parameter Description

source The source DataSeries
period Indicator calculation period

Description

Median returns the Median value of the source DataSeries based on the specified period. Median sorts the values and returns the value occupying the "middle" slot of the group. When there is an odd number of values, the median is simply the middle value. For example, the median of 2, 4, and 7 is 4. When there is an even number of values, the median is the average of the two middle numbers. Thus, the median of the numbers 2, 4, 7, 12 is (4+7)/2 = 5.5.

Example

using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { DataSeries hMedFast = Median.Series( Close, 13 ); DataSeries hMedSlow = Median.Series( Close, 25 ); PlotSeries( PricePane, hMedFast, Color.Brown, WealthLab.LineStyle.Solid, 2 ); PlotSeries( PricePane, hMedSlow, Color.Black, WealthLab.LineStyle.Solid, 2 );

for(int bar = 25; bar < Bars.Count; bar++) { if( CrossOver( bar, hMedFast, hMedSlow ) ) BuyAtMarket( bar+1 ); else if( CrossUnder( bar, hMedFast, hMedSlow ) ) SellAtMarket( bar+1, Position.AllPositions ); } } } }