[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Running Median Calculation Starting at Bar 0



PureBytes Links

Trading Reference Links

Title: AFL Function Reference - MEDIAN
Hi Searnp --

The User's Guide states:

MEDIAN
- calculate median (middle element)

Statistical functions
(AFL 2.5)


SYNTAX Median( array, period )
RETURNS ARRAY
FUNCTION The Median function - finds median (middle element) value of the array over period elements.
EXAMPLE // list only symbols which volume is greater than
// median Volume from past 50 days
Filter = Volume > Median( Volume, 50 );
AddColumn( V, "Volume" );

Period must be a scalar -- a constant.  When you run this code: 

RM = Median(Close, BarIndex() + 1);

The entire Close array is passed to the Median function at one time.  The value of BarIndex changes with each element of the Close array.  Looked at simplistically, the afl processor does not know which value of BarIndex to use, so it coughs.

You will have to write your own function using looping code.

Before you start, are you certain that you want the median value of an expanding list of data values?  Today's value will depend on how much data was loaded, which is generally not a good programming or systems idea.  Will Median(C,50), or some variation, give you what you need?

Thanks,
Howard



On Mon, Nov 3, 2008 at 11:26 AM, searnp <searnp@xxxxxxxxx> wrote:

I am trying to calculate a running median that starts at bar 0.

Code:

RM = Median(Close, BarIndex() + 1);

Then I get the following error message:
Error 5. Argument #2 has incorrect type (the function expects different argument type here)

I am using "Barindex() + 1" to get a running count at each bar to be used in the median's lookback period. Is there a way to implement this?

Thanks.

__._,_.___

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___