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

[amibroker] Re: functions in AFL, a question



PureBytes Links

Trading Reference Links

thanks for your reply, hairy_mug

in your formula you put the variable yourLastDateNum. This I should 
get somewhere from the date-range I define in the Automatic Analysis 
window. I would not know how to get it.

regrads, Ed

--- In amibroker@xxxxxxxxxxxxxxx, "hairy_mug" <WSCHWARZ@xxxx> wrote:
> Ed,
> 
> I think instead of "barcount" you might try:
> 
> lastBar= lastvalue(valuewhen(datenum()==yourLastDateNum,barindex());
> 
> which will return the barnumber at the "yourLastDateNum" point.
> 
>                       Walt
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "ed2000nl" <empottasch@xxxx> 
wrote:
> > Using the new option of writing functions in AFL, I wrote a 
simple 
> > function ( see code (1) ) to track high volumes in the last ndays 
> of 
> > an array. This function I execute in inside the "automatic 
analysis 
> > window" using code (2). 
> > 
> > If I want to look for buy signals at some point in the past (e.g. 
> > 6/6/2002) I scan for buy signals for all stocks from 6/6/2002 to 
> > 6/6/2002. This does not work. It seems to only be able to scan 
for 
> > buy signals at the last point in the database.
> > 
> > This is due to "BarCount" in my opinion. How should I rewrite 
code 
> > (1) to be able to scan for signals at some date in the past?
> > 
> > thanks in advance, Ed
> >  
> > 
> > code (1)
> > ///////////////////////////////////////////////////////
> > // Edward Pottasch, July 2003
> > // high_volume.afl returns a 1 if an area if high volume is found
> > 
> > // volume: volume array
> > // tdays: number of days over which the average volume is 
calculated
> > // ndays: number of days at the end of the vol array over which 
the 
> > average high vol is calculated 
> > // factor: the factor the average high vol should exceed average 
vol
> > 
> > 
> > function high_volume(volume,tdays,ndays,factor) 
> > {
> > 
> > 	// initialize first element
> > 	outp = 0;
> > 	vtot = 0;
> > 	vtote = 0;
> > 
> > 	if (BarCount > tdays) {
> > 	
> > 		// calculate the average volume 
> > 		for( i = BarCount - tdays; i < BarCount - ndays; 
> > i++ ) {
> > 	
> > 			vtot = vtot + volume[ i ];
> > 		
> > 		}
> > 	
> > 		vtot = vtot / tdays;
> > 		
> > 		// 
> > 		for( i = BarCount - ndays; i < BarCount; i++ ) {
> > 		
> > 			vtote = vtote + volume[ i ];
> > 		
> > 		}
> > 	
> > 		vtote = vtote / ndays;		
> > 		
> > 		
> > 		if ((vtote / vtot) > factor) {
> > 		
> > 			outp[ BarCount - 1 ] = 1;
> > 
> > 
> > 		}
> > 		else {
> > 		
> > 			outp[ BarCount - 1 ] = 0;
> > 		
> > 		}
> > 		
> > 	}
> > 	
> > 	return outp;
> > 	
> > }
> 
> ///////////////////////////////////////////////////////////////////
> > 
> > 
> > code (2)
> 
> ///////////////////////////////////////////////////////////////////
> > #pragma nocache
> > #include <high_volume.afl>
> > 
> > Buy = high_volume(Volume,50,1,6);


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs Online - Over 14,500 titles.
No Late Fees & Free Shipping.
Try Netflix for FREE!
http://us.click.yahoo.com/YoVfrB/XP.FAA/ySSFAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

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