Date.prototype.yyyymmddhhmmss = function()
{
//Modified the code from https://www.yijunma.com/tool/code-snippet/format-date-yyyymmdd-hhmmss/
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();
var hh = this.getHours();
var mi = this.getMinutes();
var ss = this.getSeconds();
var yyyymmdd = [ this.getFullYear(), ( mm > 9 ? '' : '0' ) + mm, (dd > 9 ? '' : '0') + dd ].join('');
var hhmmss = [ ( hh > 9 ? '' : '0' ) + hh, ( mi > 9 ? '' : '0' ) + mi, ( ss > 9 ? '' : '0' ) + ss, ].join('');
return yyyymmdd + '' + hhmmss;
};
filespec = "C:/TradingApps/Amibroker/DB/WatchLists/List 0.tls";
DataDir = "C:\\TradingApps\\Amibroker\\DB";
var fso, watchlist, s, ForReading;
ForReading = 1, ForWriting = 2, s = "";
fso = new ActiveXObject( "Scripting.FileSystemObject" );
watchlist = fso.OpenTextFile( filespec, ForReading, false );
var oAB = new ActiveXObject( "Broker.Application" );
oAB.LoadDatabase( DataDir );
var oStocks = oAB.Stocks;
var Qty = oStocks.Count;
var DeleteFrom = new Date( "December 13, 2018 00:00:00" ).yyyymmddhhmmss();
var DeleteTo = new Date( "December 14, 2018 23:59:59" ).yyyymmddhhmmss();
file = fso.OpenTextFile( "_remowe_xdays.log", ForWriting, true );
file.WriteLine( "Starting delete quotes from date:" + DeleteFrom );
file.WriteLine( "" );
while( !watchlist.AtEndOfStream )
{
s = watchlist.ReadLine();
for( i = 0; i < Qty; i++ )
{
oStock = oStocks( i );
if( s == oStock.Ticker )
{
file.Write( i + ". " + oStock.Ticker + "=" );
for ( j = oStock.Quotations.Count - 1; j >= 0; j-- )
{
var tmpDateNum = new Date( oStock.Quotations( j ).Date ).yyyymmddhhmmss();
if( ( tmpDateNum % 1000000 != 0 ) && ( tmpDateNum >= DeleteFrom ) && ( tmpDateNum <= DeleteTo ) )
{
oStock.Quotations.Remove( j );
}
}
file.WriteLine( "OK" );
}
}
}
watchlist.Close();
oAB.RefreshAll();
oAB.SaveDatabase();
WScript.Echo( "Done!" );