Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Remove data between the dates for Amibroker (AFL)

Rating:
5 / 5 (Votes 2)
Tags:
remove data, amibroker, jscript

Many times there is bad data uploaded into the database due to various reasons and then there is no other solution but to create a new database.
Understanding the common difficulty faced by amibroker users all across , this is a one stop solution wherein you can delete a particular date’s or range of date’s data from a particular amibroker database. All you have to do is supply name of database and range date and time (in case of intraday data) and run the jscript file from the “command prompt”. This script works for both EOD and intraday data. Its not my script and I am just the medium.

Similar Indicators / Formulas

Kavach Of Karna v2
Submitted by hbkwarez over 10 years ago
Advanced Elliott Waves
Submitted by MarcosEn about 13 years ago
3_6Day GuaiLiLv
Submitted by motorfly about 13 years ago
Williams Alligator System
Submitted by durgesh1712 about 13 years ago
Interactive Linear Regression Channel
Submitted by InternetWorm about 13 years ago
*Level Breakout system*
Submitted by Tinych about 13 years ago

Indicator / Formula

Copy & Paste Friendly
/* 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 = "c:\\Program Files\\AmiBroker\\Data"

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("august 1, 2009 00:00:00");
var DeleteTo = new Date("august 15, 2009 00:00: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 :-)" );

6 comments

1. shahin

this afl can not working, i am using amibroker5.5, showing error

2. sepemar

Thanks a lot, its working. Well done! :-)

3. halfman

Thank you so much! It works like a charm.

For you who dont know how to use this, it’s a javascript. Copy and paste the code to notepad. Notice DataDir = “c:\\Program Files\\AmiBroker\\Data”. Change it according to your own amibroker database folder.

var DeleteFrom = new Date(“august 1, 2009 00:00:00”);
var DeleteTo = new Date(“august 15, 2009 00:00:00”);

Change it according to which date you wanna delete. In my case, I only need to delete 1 date, so i fill both with same date. It will be deleted without deleting the symbol. Only particular data and date. Period.

Save the notepad with .js extension, such as Datedelete.js etc.

How to use it? Double click that file to run it, and wait. It will take some time depend on how many data in that range. If the process is finished, there will be a small window notification said “Cleanup ended :-)”. Enjoy.

4. djokoroe

It works and saves my time! Thank you.

5. Ratatutu

Hi,

Thanks for sharing the code. I want to delete all the 9:00AM quotes of 1 year. I am not a jscript coder not sure how do I edit above code. Could you help with that ?

6. tgbssk

Not working I want to shrink intraday databse which is almost 2.7Gb

It goes on infinite loop in background, just record log for 2 stocks
and then nothing happens. Apart from that no records are deleted for those 2 stocks

Leave Comment

Please login here to leave a comment.

Back