AFL to delete quotes before a specific date in a database

Hi,

I would like to delete all quotes in a database, before a particular date, say (01/*01/2000) by usindg a AFL or a Script.
Any suggestions please.

This can be done from the user interface (no code) Edit->Delete range

Or using OLE automation. See Cleanup.js file inside Scripts subfolder to see how it is done. For more detail see: AmiBroker Object Model

1 Like

Here is one of my daily working script if I happen to download Yahoo Finance EOD which is a bank holiday. Copy and save it to a .js file. Change the select date and launch it from Window script host.

var Amibroker = new ActiveXObject( "Broker.Application" );
var obj_stocks = Amibroker.Stocks;
var total_stock = obj_stocks.Count;
var sym, selected_sym, quotes;
var select_date = "2000/1/1";
for (i = 0; i < total_stock; i++) {
	sym = obj_stocks( i ).ticker;
	selected_sym = obj_stocks(sym)
	if (selected_sym) {
		quotes = selected_sym.Quotations;
		quotes.Remove(select_date);
	}
}
WScript.echo("Remove " + select_date + " from database completed.");
Amibroker.RefreshAll();
1 Like

For what it is worth it does not require script at all.
The functionality to delete selected quote from all symbols at once is built in
Just use Edit -> Delete session

1 Like

@Tomasz, unfortunately Delete session deletes only a single session.

The original user wants to delete all sessions up to a specific date. Unless he has unlimited patience, the only practical solution is to use an OLE script (which is very slow on databases with many symbols).
It would be nice to have a new function in OLE (and/or in the GUI interface) that accepts a range of dates and performs deletion on the selected multiple sessions more efficiently.

2 Likes

Much respect to the creator of Amibroker for such a flexible and customizable software.
Indeed beppe, Just add multiple lines of quotes.Remove("yyyy/mm/dd") and it's done.

There is a Edit -> Delete Range that deletes multiple sessions at once. Why don’t you guys just read my previous replies in this very thread and / or open the Edit menu before commenting ?

@Tomasz, I think the OP wanted to purge ALL the price series of the whole database up to a certain date (i.e. purge ALL sessions in a selected range for ALL symbols in the database).

The GUI Delete Range deletes a range of quotes only for the selected symbol.

What I was hoping for was an additional method (OLE and/or GUI) to make the operation of deleting a range of sessions on all the database symbols as efficient as possible (without using loops in the OLE script).

plus one for me too. this was discussed sometime before. Some way to delete Range for multiple symbols in a quick way.
GUI Delete Range is very nice but it does only one symbol, then i have to change symbol and delete again. Here, at least the Range remains selected.

For that there is other feature.
Tools -> Preferences, Data tab, Limit number of saved quotations.

@Tomasz of course in my case there are short comings from data side where history/backfill is limited so as you suggest we could limit saved quotations, but it is still a challenge to delete certain quotations in the middle of the range in a "quick way".

Delete range for multiple symbols would be great.
For now either OLE works but takes a lot of time and using Mouse clicker with delete Range is quirky when some symbols dont have data. AB will prompt with pop-up, so couldn't full automate that either.

1 Like

No problem. Next version will support multiple selection from Symbol List, so you would be able to delete range from any number of symbols that you multi-select from symbol list.

As a reminder, many features in AmiBroker already support multiple symbol selections.

In Windows generally, you can perform multiple selections in a list view using various methods:

  1. Click and Shift+Click (Contiguous Selection):

    • Click on the first item you want to select.
    • Hold down the Shift key on your keyboard.
    • Click on the last item you want to select while still holding the Shift key.

      All items between the first and last clicked items will be selected.
  2. Click and Ctrl+Click (Non-Contiguous Selection):

    • Click on the first item you want to select.
    • Hold down the Ctrl key (also known as the Control key) on your keyboard.
    • Click on each additional item you want to select while still holding the Ctrl key.

      This method allows you to select multiple items that are not necessarily adjacent to each other.
  3. Select All:
    If you want to select all items in the list view, you can press Ctrl + A on your keyboard, which is a universal shortcut for selecting all items in many Windows applications.

3 Likes