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

[amibroker] Re: What is wrong with this simple code



PureBytes Links

Trading Reference Links

Thanks Keith and Ed. I understand now. I guess I will have to think
more in terms of arrays than array elements. This is a bit like
functional programming; will need to dust off some of the old school
books.

Regards,

Drew





--- In amibroker@xxxxxxxxxxxxxxx, Keith McCombs <kmccombs@xxx> wrote:
>
> Drew --
> Notice that the IIF() operator took only one line of code, while the 
> for() and if() operators took eight lines. 
> 
> Array operations are much more efficient and much less error prone.
 Use 
> them when ever possible!!
> Use for() *ONLY* when you have to.
> -- Keith
> 
> Edward Pottasch wrote:
> >
> > IIF operates on an array en returns an array. So if you want to
simple 
> > fill the array "position" with 1 if Buy is 1 you can simple do:
> >  
> > position = Buy;
> >  
> > if you like to use the IIF operater the equivalent is:
> >  
> > position = IIF(Buy,1,0);
> >  
> >  
> > if you like to use a loop the equivalent is:
> >  
> > position = 0;
> > for ( i = 0; i < BarCount; i++) {
> >  
> >     if (Buy[ i ] == 1) {
> >        
> >         position[ i ] = 1;
> >    
> >     } else
> >  
> >         position[ i ] = 0;
> >  
> >     }
> >  
> > }
> >  
> >  
> > rgds, Ed
> >  
> >  
> >
> >     ----- Original Message -----
> >     *From:* thomasdrewyallop <mailto:drewyallop@...>
> >     *To:* amibroker@xxxxxxxxxxxxxxx <mailto:amibroker@xxxxxxxxxxxxxxx>
> >     *Sent:* Sunday, March 11, 2007 11:57 AM
> >     *Subject:* [amibroker] What is wrong with this simple code
> >
> >     Buy = cross ( Close, MADaily );
> >     for ( i = 1; i < BarCount; i++)
> >     {
> >     IIf (Buy[i], position[i] = 1, 0);
> >     }
> >
> >     I run an explore and get position[1] == 0 and the remainder of the
> >     array == 1 ( there are only two buy signals triggered). Is there
> >     something about the Buy array I am missing?
> >
> >     Best regards,
> >
> >     Drew Yallop
> >
> >
>




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Transfer from your equities account.  
Receive up to $1,000 from GFT. Click here to learn more.
http://us.click.yahoo.com/aZttyC/X_xQAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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

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