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

[amibroker] Re: Help with arrays



PureBytes Links

Trading Reference Links

j12012_30,

Although your code may seem to work correctly, you are setting 
a 'future' bar (i+1) at the 'i.th' 'present' bar in computational 
time sequence as follows:

> for (i=0; i< BarCount; ++i)
> {
> 	if (Buy [i] AND i+1<BarCount)
> 		Sell [i+1] = 1;
> }

Normally, this shouldn't matter, but because of the manner in which 
AFL processes arrays, it may matter.  This MAY be one factor creating 
your unexpected problem.  A preferable way (in my opinion), is to 
adjust the looping code as follows:

for (i=1; i< BarCount; ++i) {
   If ( Buy[i-1] )  Sell[i]=1 ;   } 

Here, you are setting a 'present' value ('Sell') based upon 
a 'previous' bar's ('Buy') value in the loop.  Note that loop-
variable initialization and subscripts are changed slightly.

Note also, that by coding as I suggest, you can get rid of the 'AND 
i+1<BarCount' superfluous in-loop time-wasting calc!!  (;->)

If you're still having problems with Sell values and/or timing, 
perhaps they are being replaced by an array computation that occurs 
after the loop computation above, OR as other posters have stated, 
perhaps your 'trade delay' settings are in conflict with what you 
expect.  If you, say, Buy on NEXT bar's 'open' (delay=1), but Sell on 
THIS bar's close (delay=0), then you'd probably see the results 
you're getting.

Another thing to be aware of is that on ANY bar the Close exceeds 
200, a Buy=1 will be generated.  Once an 'uptrend' occurs where Close 
continually exceeds 200, Buy=1 will be generated for EACH one of a 
continuing sequence of adjacent bars!!  Is this what you really want? 
You need to be very clear on how you want your 'Buy' signals to be 
generated, and the CROSS function mentioned in a previous post may be 
more appropriate.

As to other AFL references, I've found an EXCELLENT one to be Howard 
Bandy's book: 'Qunatitative Trading Systems' (available at 
www.quantitativetradingsystems.com). There are MANY useful AND 
PRACTICAL AFL examples given throughout the book, from very simple to 
very complex.  This is also a SUPERB (in my opinion) reference for 
development of trading systems in general.  I HIGHLY recommend it!!  
(;->)

Hope all this helps a bit....

Buzz






--- In amibroker@xxxxxxxxxxxxxxx, "jl2012_30" <jl2012_30@xxx> wrote:
>
> I'm totally new to Amibroker and am trying to figure out how its 
> array works. I have quite extensive experience with C programming 
and 
> understand that AFL works pretty much like C. However, when I try 
> programming with arrays, I get very unpredictable results...
> 
> For instance, with the code below, I would expect the system to buy 
> when the close is greater than 200 (it does this as expected). I 
> thought it should sell the next day, since I wrote Sell [i+1] = 1. 
> However, the system sells on the same day instead.
> 
> I know I'm missing something here. Any help will be very much 
> appreciated.
> 
> Btw, just wondering if there's any other books/reference guides out 
> there on AFL, besides the user guide. Thanks.
> 
> --------------------------------
> Buy = C > 200;
> Sell = 0;
> 
> for (i=0; i< BarCount; ++i)
> {
> 	if (Buy [i] AND i+1<BarCount)
> 		Sell [i+1] = 1;
> }
>




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/