amibroker

HomeKnowledge Base

How to delete quotes without removing the symbol from a database

In order to delete quotations from a local database manually, we can use Quotations Editor (Symbol–>Quote Editor), then mark the required range of quotes and press Delete button. To mark a range – it is enough to click on the first line of the range, then scroll to the other line, hold SHIFT and click on the end-line of the range. To multi-select individual lines, hold down CTRL key while clicking on the lines.

Delete quotes

There is also a way to delete quotations programmatically with use of OLE automation interface explained here:

http://www.amibroker.com/guide/objects.html

The following code presents how to do it using automation scripts (the code deletes all quotations of MSFT ticker):

// THIS IS NOT AFL// This is Windows script to be run from the outside of AmiBrokerfunction RemoveAllQuotes( Name ){    AB = new ActiveXObject("Broker.Application");    Stk = AB.Stocks( Name );    Quotes = Stk.Quotations;    iQty = Quotes.Count;    for( i = iQty - 1; i >= 0; i-- )    {       Quotes.Remove( i );    }    AB.RefreshAll();}RemoveAllQuotes("MSFT");WScript.Echo ( "Completed" );

The code above is intended to be used from the outside of AmiBroker.

To use above code follow these steps:

  1. Open Notepad
  2. Copy-paste above the code
  3. Save the file with .JS extension (which means that system will treat this as JScript code)
  4. Make sure that AmiBroker is running with desired chart as active one
  5. Double click on .JS file to execute the JScript code

IMPORTANT: if you are running 64-bit Windows and have BOTH 32-bit and 64-bit versions of AmiBroker installed the OLE scripts by default would only talk to 64-bit instance. To use 32-bit version instead you would need to follow advice given in this article: “Running OLE automation scripts with 32- and 64-bit versions of AmiBroker”

Using the very same method you can delete quotes selectively, for example the script below deletes only quotes having zero volume:

// THIS IS NOT AFL// This is Windows script to be run from the outside of AmiBrokerfunction RemoveQuotesWithZeroVolume( Name ){     AB = new ActiveXObject("Broker.Application");     Stk = AB.Stocks( Name );     Quotes = Stk.Quotations;     iQty = Quotes.Count;     cnt = 0;     for( i = iQty - 1; i >= 0; i-- )     {        qt = Quotes.Item( i );        if( qt.Volume == 0 )         {            cnt++;           Quotes.Remove( i );        }     }         AB.RefreshAll();     return cnt;}n = RemoveQuotesWithZeroVolume("MSFT");WScript.Echo ( "Removed " + n + " quotes with zero volume" );

Comments are closed.