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

RE: [amibroker] Cleanup script help



PureBytes Links

Trading Reference Links

Just a suggestion...
You do not have to necessarily use this script to do that.
You could great a filter that for stocks with the condition you are looking
for, export to CSV file.

Then create a script, that reads that CSV file and loads the tickers in to
an array (i.e. like oStocksToDelete below ), and then just iterate thru that
and delete the stocks.  

-----Original Message-----
From: jism1992 [mailto:gdihia@xxxxxxxxxxx] 
Sent: Saturday, November 20, 2004 3:59 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Cleanup script help



How can I modify this script to delete all stocks with MA (VOLUME, 20)
< 100,000. I want to delete all stock with small volume. Thanks.

I am not even sure how to edit this file. Please help. Thanks a lot.

/*
** AmiBroker/Win32 scripting Example
**
** File:		Cleanup.js
** Created:		Tomasz Janeczko, December 2th, 2000
** Purpose:		Cleanup the database from not traded stocks
** Language: 	JScript (Windows Scripting Host)
*/

/* detection threshold (in days)  */
var Threshold = 5; // one month for example 
/* by default do not delete */
var DeleteByDefault = true;
/* ask the user for the decision */
var AskUser = false;
/* a timeout to wait until default route (no deletion) is taken */
var Timeout = 5;

var oAB = new ActiveXObject("Broker.Application");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var Shell = new ActiveXObject("WScript.Shell");


var oStocks = oAB.Stocks;

var MiliSecInDay = 24 * 60 * 60 * 1000;

var Continue = true;

var StockQty = oStocks.Count;

var oStocksToDelete = new Array;
var oStocksNotTraded = new Array;

if( ! AskUser ) WScript.Echo("Cleanup script started" );

for( i = 0; i < StockQty && Continue; i++ )
{
	oStock = oStocks( i );

	var Qty = oStock.Quotations.Count; 

	var response = 0;

	if( Qty > 0 )
	{
		oQuote = oStock.Quotations( Qty - 1 );

		var oDate = new Date( oQuote.Date );

		var Today = new Date();

		DaysNotTraded = Math.floor( ( Today - oDate )/MiliSecInDay
);

		if( DaysNotTraded > Threshold )
		{
			if( AskUser ) response = Shell.popup( oStock.Ticker
+ " is not
traded since " + oDate.toLocaleString() + " (" + DaysNotTraded + "
days).\nDo you wish to delete it?\n(Press Cancel to end the process)",
Timeout, "Confirm delete", 3 + 256 );
			else          response = -1; /* default */
		}
	}
	else
	{
		if( AskUser ) response = Shell.popup( oStock.Ticker + " has
no
quotes. Do you wish to delete it?",  Timeout, "Confirm delete", 3 + 256 );
		else          response = -1; /* default */
	}

	/* change default route if needed */
	if( response == -1 && DeleteByDefault ) response = 6;

	switch( response )
	{
		case -1:/* Timeout - fallback to no */
		case 7: /* No */
				oStocksNotTraded[ oStocksNotTraded.length ]
= oStock.Ticker;
				break;
		case 6: /* Yes */
				oStocksToDelete[ oStocksToDelete.length ] =
oStock.Ticker;
				break;
		case 2: /* Cancel */
				Continue = false;
				break;
		default: break;
	}
}

if( oStocksToDelete.length > 0 && Shell.popup( "You are now about to
delete " + oStocksToDelete.length + " stock(s).\nDo you wish to
proceed?" , 0, "Confirm delete", 4 + 256 ) == 6 )
{
	for( i = 0; i < oStocksToDelete.length; i++ )
	{
		oStocks.Remove( oStocksToDelete[ i ]  );
	}

	oAB.RefreshAll();
}

if( oStocksNotTraded.length > 0 && Shell.popup( "There are " +
oStocksNotTraded.length + " not traded stock(s) detected but not
deleted by your choice.\nDo you wish to save their tickers to
\"nottraded.txt\" file?" , 0, "Confirm save", 4 + 256 ) == 6 )
{
	f = fso.OpenTextFile( "nottraded.txt", 2, true );	

	for( i = 0; i < oStocksNotTraded.length; i++ )
	{
		f.WriteLine( oStocksNotTraded[ i ]  );
	}

	f.Close();
}

WScript.Echo("Cleanup script finished" );






Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links



 





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

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

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