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

[amibroker] Re: Single Value from Array



PureBytes Links

Trading Reference Links

Not sure if this is useful to you, but I had written these functions
awhile back which demonstrates an alternative non-looping way to look
back into the array based QP data fields that should only change by
quarter:

THOUSAND = 1000;
MILLION = THOUSAND * THOUSAND;

function getSalesMrq() {
    return GetExtraData("Sales") * MILLION;
}
function getEPSMrq() {
    return GetExtraData("EPS");
}
function getSalesTtm() {
    //Cycle through last 4 quarters and add up the getSalesMrq for TTM
    qtrDays = 260 / 4;
    salesMrq = getSalesMrq();
    return salesMrq + Ref(salesMrq, -1 * qtrDays) +
            Ref(salesMrq, -2 * qtrDays) + Ref(salesMrq, -3 * qtrDays);
}
function getEPSTtm() {
    //Cycle through last 4 quarters and add up the getSalesMrq for TTM
    qtrDays = 260 / 4;
    epsMrq = getEPSMrq();
    return epsMrq + Ref(epsMrq, -1 * qtrDays) +
            Ref(epsMrq, -2 * qtrDays) + Ref(epsMrq, -3 * qtrDays);
}

JD

--- In amibroker@xxxxxxxxxxxxxxx, "fatboycato" <fatboycato@xxx> wrote:
>
> Eureka! I think I figured it out. For those of you with QP3 data, 
> try this code to return the last 3 EPS reports:
> 
> EPS=GetExtraData("EPS");
> Filter=1;
> b=BarCount;
> i=1;
> EPS0=EPS[b-1];
> 
> do
> {
> 	EPS1=EPS[b-i];
> 	i++;
> }
> while (EPS1==EPS0 AND i<BarCount);
> 
> do
> {
> 	EPS2=EPS[b-i];
> 	i++;
> }
> while (((EPS2==EPS0) OR (EPS2==EPS1)) AND i<BarCount);
> 
> 
> //EPS1=Ref(EPS,-i);
> AddColumn(EPS0,"EPS0");
> AddColumn(EPS1,"EPS1");
> AddColumn(EPS2,"EPS2");
> 
> I really can't believe it was this simple, so something's probably 
> wrong. But it seems to work. It could probably be more elegant, but 
> I'm happy with what I've got. I imagine we could build in the Sales 
> array as well. Once we know the value of i, everything else should 
> fall out and a near-Canslim exploration could be done.
> 
> Any suggestions would be recommended.
> --- In amibroker@xxxxxxxxxxxxxxx, "fatboycato" <fatboycato@> 
> wrote:
> >
> > Well, I'm stumped. I've tried just about every way I could think 
> of 
> > to get this accomplished, but I'm simply not smart enough to do 
> it. 
> > Hopefully, someone here is.
> > 
> > I can't seem to iterate through an array to discover if a value is 
> > different from a base value. For example: suppose your array looks 
> > like this:
> > 0,0,0,0,0,0,0,0,1,1,1,1,1
> > 
> > I want to look through that array and return "1" the first time it 
> > changes from 0 to 1. The problem is that arrays can't show up in 
> any 
> > kind of loop. I don't know the 1 is there, so I can't just look 
> > for "1". I need to look through the array and return the different 
> > value, whatever it may be.
> > 
> > Here's an example of what the code would look like:
> > 
> > I have an array.
> > Look at the first number in the array and call it "x".
> > Look at the second number in the array. If it's the same as "x", 
> > then look at the third number. If it's still the same, look at the 
> > fourth number, etc...
> > Once you get to a number that is not "x", call that number "y".
> > Stop looking for something other than "x".
> > 
> > Any ideas? The Ref() function obviously won't work because it 
> > returns an array. Is there another function that works like Ref(), 
> > but returns a single value?
> >
>







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 other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/