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

[amibroker] Re: still struggling with Sum() and Cum()



PureBytes Links

Trading Reference Links

AmiBroker is working just fine.

We've just been answering the wrong question. All samples provided so 
far have been to tell you the number of times *for each stock* your 
criteria was met over the given period. None of the examples 
attempted to calculate the number of rows returned by the exploration 
or the number of stocks that met the crieria.

What exactly is your intention? If you just want to output the number 
of rows, use the AddSummaryRows function.

AddSummaryRows(16);

If you want to know how many stocks met your criteria, use the 
AddToComposite function. However, you cannot both calculate using 
AddToComposite and display using AddColumn in a single pass. So, you 
would have to run your Exploration twice to see the result of the 
first run.

You can also Plot the composite if you want to see how it changes 
over time. The complete guide to composites can be found here: 
http://www.amibroker.net/3rdparty/IntroToAtc.pdf

AddToComposite(m, "~Counter", "X", atcFlagDefaults | 
atcFlagEnableInExplore);

Plot(Foreign("~Counter", "Close"), "Counter", colorRed, styleLine);

AddColumn( Open, "Open" ); 
AddColumn( cumResult, "Cum" ); 
AddColumn( sumResult, "BarIndex" ); 
AddColumn( loopResult, "Looping" ); 
AddColumn( Foreign("~Counter", "Close"), "Count" );
AddSummaryRows(16);

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "bigitop" <doctormuniz@xxx> wrote:
>
> 
> I totally understand the logic of your example. it should work in 
theory
> however in reality it is not.  When i run this for a given date 
range,
> let's say 1/14/09 - 1/16/09, all three values (cumResult, sumResult 
and
> loopResult) are returning the number of days in the date range 
selected
> in AA window. So all three are returning 3.  However, the number 
stocks
> with the 40-60 price range in this 3-day period is 150.  I can't 
see why
> your example wouldn't work. I can't see why the other examples 
provided
> by other forum members wouldn't work. But they just are not working.
> 
> Im so frustrated. This is such a simple and basic calculation but 
AB is
> just not doing right. I'm so frustrated that i've been thinking 
about
> doing this in php!  if there was a php class for technical 
indicators i
> would've done just that!
> 
> I appreciate your help and patience as well as other forum members.
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> >
> >
> > Yes, Cum is only looking at the 1 values in the array. But, it is
> > counting from the start of all data (i.e. from barindex 0), 
whereas
> the
> > rows returned by your exploration will be limited to the selected 
date
> > range.
> >
> > As for LastValue, yes, it returns a single value. But, AddColumn 
is
> > expecting an array. So, the single value is effectively being 
treated
> as
> > an array for which all elements are set to that value.
> >
> > Following are 3 options to do what you are asking for; Note that 
the
> > output column for Sum is all zeros until the last date since 
there is
> > insufficient data to calculate the result until the last bar in 
the
> > range. The single value in the Cum and the manual looping cases 
are
> > simply being treated as arrays despite being scalers.
> >
> > In this case, the looping option is the best performing (run each
> option
> > through Check and Profile from Tools menu). But, generally that 
is not
> > the case and the built in AmiBroker functions are preferred over
> > looping.
> >
> > Finally, note that the operator is '&&' not '&'. You might find it
> > preferable to use the operator 'AND' for better clarity.
> >
> > Mike
> >
> > // Using Cum()
> > m = IIf( Open > 48 && Open < 52, 1, 0 );
> > inRange = Status( "barinrange" );
> > number = Cum( m && inRange );
> > cumResult = LastValue( number );
> >
> > // Using Sum()
> > bi = BarIndex();
> > startIndex = ValueWhen( Status( "firstbarinrange" ), bi );
> > endIndex = ValueWhen( Status( "lastbarinrange" ), bi );
> > range = ( endIndex - startIndex + 1 );
> > sumResult = Sum( m, range );
> >
> > // Using a manual loop over range
> > loopResult = 0;
> >
> > for ( i = 0; i < BarCount; i++ )
> > {
> >      if ( inRange[i] && Open[i] > 48 && Open[i] < 52 )
> >      {
> >          loopResult++;
> >      }
> > }
> >
> > // Output (select range of dates from AA window)
> > Filter = m == 1;
> >
> > AddColumn( Open, "Open" );
> > AddColumn( cumResult, "Cum" );
> > AddColumn( sumResult, "BarIndex" );
> > AddColumn( loopResult, "Looping" );
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "bigitop" doctormuniz@ wrote:
> > >
> > > you mean the price range? if so, yes, this is definitely less 
than
> all
> > > quotes. but i thought Cum(m) would look only at the 1 values in 
the
> > "m"
> > > array.
> > >
> > > so how can i make them equal?
> > >
> > > i just need to count the number of 1's and 0's in the array "m"
> which
> > is
> > > simply the stocks between 48 and 52 dollars for the time frame
> > specified
> > > in the Analysis window. how can i do this with AB?
> > >
> > > m = IIf(Open > 48 & Open < 52, 1, 0);
> > >
> > > number = Cum(m);
> > > result = LastValue(number);
> > >
> > > Filter = m == 1;
> > >
> > > AddColumn(Open, "Open");
> > > AddColumn(result,"result");
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "wavemechanic" timesarrow@ 
wrote:
> > > >
> > > > You probably have specified a range that is less than all 
quotes
> so
> > > cum() and open are looking at different amounts of data.
> > > >
> > > > Bill
> > > > ----- Original Message -----
> > > > From: bigitop
> > > > To: amibroker@xxxxxxxxxxxxxxx
> > > > Sent: February 25, 2009 2:15 PM
> > > > Subject: [amibroker] still struggling with Sum() and Cum()
> > > >
> > > >
> > > >
> > > > ok, here's my big problem. consider this example:
> > > >
> > > > m = IIf(Open > 48 & Open < 52, 1, 0);
> > > >
> > > > number = Cum(m);
> > > > result = LastValue(number);
> > > >
> > > > Filter = m == 1;
> > > >
> > > > AddColumn(Open, "Open");
> > > > AddColumn(result,"result");
> > > >
> > > > running this code in the Analysis window returns:
> > > >
> > > > total rows: 356 rows
> > > > highest number in "result": 450
> > > >
> > > > so, first of all, shouldn't they be the exact same number and
> > > > secondly, shouldn't "result" be filled with just one value as
> > > opposed to many values?
> > > >
> > > > neither of this is happening. what am i doing wrong?!
> > > >
> > >
> >
>




------------------------------------

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

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

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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

Yahoo! Groups Links

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

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/