Deleting data for specific dates from native DB

How can I delete data for all “tickers and its corresponding synthetic tickers” for few explicitly defined dates from native DB?

Yes you can but only using OLE interface
http://www.amibroker.com/guide/objects.html

AB = CreateObject("Broker.Application");

Sym = AB.Stocks("MSFT");

if( Sym )
{
   Quotes = Sym.Quotations;
   
   Quotes.Remove("2017-11-17");
} 
   
AB.RefreshAll();
2 Likes

I tried the following code

 _SECTION_BEGIN("The Deletion");
	AB = CreateObject("Broker.Application");


	Wlist = CategoryFind("ABC",categoryWatchlist);
		symlist = CategoryGetSymbols( categoryWatchlist, Wlist );
		for ( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ ) 
		{
			
			Sym = AB.Stocks(sym);



			if(Sym )
			{
   			  Quotes = Sym.Quotations;
   
                          Quotes.Remove("2020-10-23");
                         } 
   
                         AB.RefreshAll();
                  }
                  
  _SECTION_END();

However it's not working through. There is no error either

See the KB article:

It clearly says

// THIS IS NOT AFL
// This is Windows script to be run from the outside of AmiBroker

Read it in detail including bitness if you have both.
https://www.amibroker.com/kb/2015/01/13/how-to-delete-quotes/

You don't need ANY code at all.
Use mark desired date on chart (click) and use Edit->Delete Session.

@Tomasz, probably my post was in wrong thread. This is an intraday database. So I wish to delete all quotes for the specified date.

1 Like

Downloaded & modified from http://otithilozz.blogspot.com/2018/09/remove-data-between-dates-for-amibroker.html

This is for IEOD data

// Downloaded From website
/* Its a jscript and hence should be run from the command prompt. Change parameters  ** before executing the script. Also take backup of your data for safety reasons.
** AmiBroker/Win32 scripting Example
**
** File:                Remove all quotations between dates .js
** Version:             0.1 beta
** Purpose:             Remove all quotations between dates for all symbols !
** Language:            JScript (Windows Scripting Host)
**
**
** CHANGE variable DataDir
** CHANGE variable DeleteFrom and DeleteTo 
**
** ENJOY :-)
*/

// where database is stored
fs = new ActiveXObject("Scripting.FileSystemObject");

DataDir = "E:\\Amibroker-EOD Data\\NSE-IEOD"

var oAB = new ActiveXObject("Broker.Application");
var fso = new ActiveXObject("Scripting.FileSystemObject");
file    = fso.OpenTextFile( "_remowe_xdays.log", 2, true );

oAB.LoadDatabase( DataDir );

var oStocks = oAB.Stocks;
var Qty = oStocks.Count;
var MiliSecInDay = 24 * 60 * 60 *1000;

var DeleteFrom = new Date("october 23, 2020 09:15:00");
var DeleteTo = new Date("october 23, 2020 15:30:00");

//add a day to the date
DeleteTo.setDate(DeleteTo.getDate() + 1);

// make date with time 00:00:00        
var DayDeleteFrom = new Date((Math.floor(DeleteFrom / MiliSecInDay)) * MiliSecInDay);
var DayDeleteFromNum = (Math.floor(DeleteFrom / MiliSecInDay)) * MiliSecInDay;

var DayDeleteTo = new Date((Math.floor(DeleteTo / MiliSecInDay)) * MiliSecInDay);
var DayDeleteToNum = (Math.floor(DeleteTo / MiliSecInDay)) * MiliSecInDay;

file.WriteLine( "Starting delete quotes from date:" + DeleteFrom);
file.WriteLine( "" );

for( i = 0; i < Qty; i++ )
{
        oStock = oStocks( i );
        file.Write( i + ". " + oStock.Ticker + "=" );

        for (j=oStock.Quotations.Count-1;j>=0;j--)
        {
                //file.Write( "j=" + j + "," );
                //tmpDate = new Date( oStock.Quotations( j ).Date );
                tmpDateNum = oStock.Quotations( j ).Date ;
                if (tmpDateNum >= DayDeleteFromNum) 
                {
   if (tmpDateNum <= DayDeleteToNum) 
   {
                        //file.WriteLine( "Delete data=" + tmpDateNum);
                        oStock.Quotations.Remove(j);
   }
                }
                else 
                {
                        //file.WriteLine( "Last data no to delete=" +tmpDateNum);
                        break;
                } 
        }
        file.WriteLine( "OK" );
}
oAB.SaveDatabase( );

file.Close();
WScript.Echo("Cleanup ended :-)" );

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.