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

[amibroker] Explore script for finding stocks potentially interesting for intraday trading



PureBytes Links

Trading Reference Links

Hello,

In the same line as the previous posts, here is a small script that
looks for stocks (within an EOD database) that are presumably
interesting to trade on an intraday basis. Criteria for selection are
explained below, I don't claim they are all necessary meaningful : )
but that's a starting point. Note, that when computing the average
intraday variation over the last X days, the highest variations are
discarded because occasionally the intraday variation is much too high
due to some abnormal trades. Comments if any are welcome of course,

Best regards,

Nicolas  

//-----------------------------------------------------------
// Scan database and find stocks that may be tradable
// on an intraday basis - criteria for the selection:
// highest intraday variation, price should not be
// too small, liquidity is a must and avoid stocks that 
// had a recent slump,  N.N. - 2006-12-09
//-----------------------------------------------------------

// sort function available in the AFL library
// customized so as to sort only the last X bars 
function sortLastXBars(inlist, X)
{
temp=0;
for(i = BarCount-1; i>BarCount-1-X; i--) {
	for (j = BarCount-X +1; j <= i; j++) {
		if (inlist[j-1] > inlist[j]) {
			temp = inlist[j-1];
			inlist[j-1] = inlist[j];
			inlist[j] = temp;
		}
	}
}
return inlist;
}

// how long ago should we look back? 
periods=Param("Periods",30,1,100,1);
SetBarsRequired(periods, 0); 

// do not consider the largest variation in the sample,
// they are sometimes "abnormal" High AND Low values
discardedPercent=Param("Discarded (%)",5,0,25,1);
nbDiscarded = ceil((DiscardedPercent*periods)/100.0);

// not interested in stocks that have lost a lot recently
MaxDrawdown = Param("MaxDrawdown (%)",0.2,0,0.5,0.01);

// not interested in penny stocks
MinPrice = Param("MinPrice",30,0,100,1);
// liquidity is needed
MinVolume = Param("MinVolume (10^5)",10,0,50,1);
 
// add to watchlist?
addToWatchList = ParamToggle("Add to watchlist","No|Yes");
watchListNumber= Param("Watchlist number",1,0,63,1);

// check that there are enough quotations otherwise 
// discard the stock.
if (BarCount-periods-1>=0) {
	Variation = (C[BarCount-1]-C[BarCount-periods-1])/C[BarCount-periods-1];
} 
else Variation = -10000;

// compute average price
PriceArray = MA(C,periods);
AddColumn(LastValue(PriceArray),"AvgPriceOverXDays");
// compute average volume 
VolArray = MA(V,periods);
AddColumn(LastValue(VolArray),"AvgVolumePerDays");

Filter = (Variation > -MaxDrawdown) AND
(LastValue(VolArray)>=MinVolume * 10^5) AND
(LastValue(PriceArray)>=MinPrice);

tmpSum = 0.;
if (Filter) {
	if (addToWatchList) CategoryAddSymbol("",categoryWatchlist,
watchListNumber);	
	VariationArray = sortLastXBars((H-L)/L,periods);
	for (i=BarCount-nbDiscarded-1;i>BarCount-1-periods;--i) {
		tmpSum = tmpSum + VariationArray[i];
	}
}
// strange, not taken into account if inside the if statement
AddColumn(tmpSum/(periods-nbDiscarded),"AvgVariationPerDay",1.4);
AddColumn(Variation,"VariationOverXDay",1.4);


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.15/581 - Release Date: 12/9/2006 3:41 PM