<snip>Median() wants a number as its second argument. (The manual is clear!)<snip>
To help me understand next time ... how did you decide that Median)array,period) wants a number from what is written in the manual? MA(array,periods); accepts an array and the only differential in the manual is plurality of the periods (do you think Tomasz intended the plurality to be significant?) MA(C,Cum(1));//this is OK? <snip> When are the "for" loops executed in the block of code? Knowing some more about the AFL execution order might be helpful.<snip> Sorry, don't know anything about execution. Recently Siddhartha said that learning the AFL execution was the best thing we can ever do ... I don't know where to find it though. You are not keen on my suggestion that calcs for the moments are arithmetic and so should fly in AFL without looping? I am a lay programmer but my instinct is to start there - looping will slow you down in RT indicators??? Plan C - use the RMath Plugin ... advanced stats available there. --- In [email protected], i cs <ics4...@...> wrote: > > Hi Brian, > > Thanks for getting back to me. > > Unfortunately, Cum() returns array, Median() wants a number as its > second argument. (The manual is clear!) > > I used median as an example because it's relatively easy to understand, > and I will be using it, but I will also be plotting the growth factor in the > same > way - as well as the other moments of distribution - just one step at a time. > > Its possible to derive a lot of the moments of distribution from other the > parts, but it comes back to the same problem - I'd have to write functions > to derive kurtosis, mode etc. > > Some of the historic emails in the group included the following solutions: > - code the functions myself - which I'm trying to avoid. > - create a dynamic set of variables using VarSet - this seems a bit brutish > especially if you are playing with a number of "profile attributes". > > When are the "for" loops executed in the block of code? Knowing some more > about the AFL execution order might be helpful. Might go down that track for > a while....and check out the other 1500 references to "loop" in the email > group. > > Thanks again... > Robert Z > > > > > > ________________________________ > From: brian_z111 <brian_z...@...> > To: [email protected] > Sent: Friday, 5 June, 2009 2:57:43 PM > Subject: [amibroker] Re: Newbie Array / Looping Question > > > > > > I am not sure about this one now ... I think we need some help from the > code/maths experts. > > Median() doesn't appear to accept an array as input (the manual doesn't say > one way or another?) ... it might be demanding a constant (that wouldn't > surprize me since mean/mode/median are moments of a distribution so massive > calcs might be required to find them for skewed dists without having the > distriution at hand) ... AB doesn't do that distributions off the shelf ... > not AFAIK. > > I think you can calc Skewness from N, StDev, arithmetic mean etc ... once you > have S you can back calc the Median or the Mode from the Mean and the StDev. > > Another brute method might be an algorithmic trial and error test for the > Mode (loops required)... I forget what it is called in programming but if the > value to the right of the mean has a higher frequency than the mean value the > mode is somewhere to the right .. by halving the range between the freq test > you will zero in on the mode and then you can calc the median by using the > mean and mode values..... AFAIK array processing will always be more timely > than looping though. > > --- In amibro...@yahoogrou ps.com, "brian_z111" <brian_z111@ ...> wrote: > > > > Median(array, periods) > > > > I assume you are measuring, say ROC(C,1) or similar for % price change. > > I guess you just need to get a progressive count, of the number of ROC > > datapoints, to make the function work. > > > > Things to look out for (if the AB function is going to work for you): > > > > - every element in the array you are measuring needs a value (nulls or > > zeros might trip up the math e.g. STDev, mean) ... I guess if you are > > interested in daily bars you will first create a daily ROC(C,1) or ROC of > > some other point of interest from within the bar HL range > > - the number of periods, in your array count, is range dependent i.e. in AB > > it can vary with mode ... QuickAFL can be used to change the range (in AA) > > and QickAFL will autoset the range in charts (or might ... I am not the > > full bottle on QuickAFL but there is an article by Tomasz in the AB > > KnowledgeBase) > > - BarsSince type functions might count one less period than you expect ... > > depending if the function is a zerobased count and how you want to use the > > count.... sometimes I have to add 1 to make the adjustment manually > > - BarIndex() is the bar by bar count since the start of the range, where > > range == the range of the database ... AB gets a bit tricky with when and > > where it uses the complete database range as the default .... probably to > > do with fast array processing etc ...sometimes I prefer to use Cum(1) as my > > count ... I seem to get more visually stable indicators in the charts > > because it doesn't reference the chart range it references from the start > > of the database. > > > > - so, making a few assumptions, and if Median works for you as required, > > Median(ROC(C, 1),Cum(1) ); // because Cum(1) is progressive and counts bars > > from the beginning > > > > - mathematically I find ROC is not as stable as GrowthFactor where ROC == > > 3% is expressed as 1.03 > > > > Haven't done it though. > > > > If that doesn't work maybe someone else in the forum knows more. > > > > In case of emergency RVince book two has the maths for median, mode, mean > > interelationships (possibly for advanced, or custom use, you could > > calculate the median from other values).... mean == median == mode for > > normal distributions (you should be so lucky!) > > > > > > > > > > --- In amibro...@yahoogrou ps.com, "ics4mer" <ics4mer@> wrote: > > > > > > Hi all, > > > > > > I'm after a general form for doing a particular type of algorithm > > > in AFL - and I'm happy to admit that I might be going about it > > > the totally wrong way... > > > > > > I am attempting to extract an evolving "profile" of a stock over > > > time. > > > > > > Using "median" as an example, lets say I want calculate the median > > > percentage price change for the life of the stock. To give an > > > example: > > > > > > The 1st trading day - do nothing. > > > The 2nd trading day - calc median for 2 days > > > The 3rd trading day - calc median for 3 days > > > Last traded day - calc median for n days. > > > > > > For simple functions, I have used a construct similar to; > > > for ( i=0; i < BarCount; i++ ){ > > > myArray[ i ] = simpleFunc( i ); > > > ..... > > > } > > > > > > However, in this case, I would have to write a new median function, > > > and this is irritating, since there is a perfectly good one > > > taunting me from the users manual! That's why I suspect that I > > > might be doing something in the wrong way. > > > > > > Any help or pointers would be much appreciated. A pointer to > > > a message in the user group would be fine too! ( Yes I am still > > > trawling through the email group as I write this....) > > > > > > TIA > > > > > > Robert Z > > > > > > > > > > > Need a Holiday? Win a $10,000 Holiday of your choice. Enter > now.http://us.lrd.yahoo.com/_ylc=X3oDMTJxN2x2ZmNpBF9zAzIwMjM2MTY2MTMEdG1fZG1lY2gDVGV4dCBMaW5rBHRtX2xuawNVMTEwMzk3NwR0bV9uZXQDWWFob28hBHRtX3BvcwN0YWdsaW5lBHRtX3BwdHkDYXVueg--/SIG=14600t3ni/**http%3A//au.rd.yahoo.com/mail/tagline/creativeholidays/*http%3A//au.docs.yahoo.com/homepageset/%3Fp1=other%26p2=au%26p3=mailtagline >
