Thanks Paul, this worked very well for me (and was
similar to what Ed Hoopes suggested an hour later), though using this method
requires that I do my own calculation of things like standard deviation and
anything else that is more complex than summing up things that occur
occassionally. Ara and Ed, thank you!
Here is what i did (probably the long way, but I
don't care about speed):
cond6={my condition}
NumBars=12;
hV = IIf(BarsSince(Cond6) ==
NumBars,HHV(H,BarsSince(Cond6))-ValueWhen(Cond6,C),Null);
Sumhv = Cum(IIf(BarsSince(Cond6) ==
NumBars,hV,0));
Counthv = Cum(IIf(BarsSince(Cond6) ==
NumBars,1,0));
Avghv = Sumhv/Counthv;
AddColumn (Avghv,"avghv",1.3);
//AddColumn(Sumhv,"sumhv",1.3);
//AddColumn(counthv,"counthv",1.3);
Sumsquareshv= Cum(IIf(BarsSince(Cond6) == NumBars,(hV -
Avghv) ^ 2, 0));
Avgsumsquareshv = Sumsquareshv / Counthv;
stddeviationhv = sqrt(Avgsumsquareshv);
AddColumn (stddeviationhv,"stddev hv",1.3);
----- Original Message -----
Sent: Monday, April 28, 2008 5:17
PM
Subject: RE: [amibroker] Re: calculating
the mean of only some of the observations in an array ?
You can try the Cum function together with teh IIF
function to sum the array that meet the conditions
mysum = cum(iif(signal > whatever, signal,
0))
mycount = cum(iif(signal > whatever, 1,
0))
myavg =
lastvalue(mysum/mycount)
Ara, thanks for responding. Actually what I'm trying to do is a
little different. Here is what the array might look like
signal
hhv@xxxxxx avgofmyobsv 0 -- 1 -- 0 -- 0 -- 0 -- 0 -- 0
-- 0 -- 0 -- 0 -- 0 -- 0 -- 0 -- 0 .05 ..050 0
-- 0 -- 1 -- 0 -- 0 -- 0 -- 0 -- 0 -- 0 -- 0
-- 0 -- 0 -- 0 -- 0 -- 0 .06 .055 0 -- 0 -- 1
-- 0 -- 0 -- 0 -- 0 -- 0 -- 0 -- 0 -- 0 -- 0
-- 0 -- 0 -- 0 .07 .060
--- In amibroker@xxxxxxxxxps.com,
"Ara Kaloustian" <ara1@xxx> wrote: > > if you are using
loops and you know when your signal was generated, use that > bar
number as the starting poing point for your loop. Pick an end point as
> you edesire. > > a = SignalBarNumber; > b = Bars
required in your calculation; > > for (i=a; i< a+b;
i++) > ... > > ----- Original Message ----- >
From: "cdepuy" <cdepuy@xxx> > To: <amibroker@xxxxxxxxxps.com> >
Sent: Monday, April 28, 2008 2:40 PM > Subject: [amibroker]
calculating the mean of only some of the observations > in an
array ? > > > > Without requiring loops that work
through the whole barcount, can > > someone point out to me how to
exclude certain values in an array > > when calculating a statistic
across an array? > > > > I must be missing something. I am
trying to calculate the mean of > > some values that occur only
occassionally (after my signal) using > > Amibroker. But,what
happens is all the values between my signals get > > included
in the calculation. I know the solution is easy, but I > > cannot
figure it out. > > > > //figure highest value that occurs
between my signals and the > > next "x" following the
signal > > Cond6 = {some condition that i am investigating, like v
> 5*ma (v,50) > > NumBars = 12; > > hV =
IIf(BarsSince(Cond6) ==
NumBars,HHV(H,BarsSince(Cond6))- ValueWhen > >
(Cond6,C),Null); > > > > //now calculate the mean of
all the hv 's that occur > > mean = ma(hv,NumBars*50); //this
line I am having trouble with > > filter=1; > >
addcolumn(mean,"mean",1.2); > > //then perform more
statistics...(etc). > > > > > > > >
------------------------------------ > > >
> Please note that this group is for discussion between users
only. > > > > To get 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 >
> Yahoo! Groups Links > > > > >
> >
__._,_.___
Please note that this group is for discussion between users only.
To get 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
__,_._,___
|