Deleting RT ticks

a1b1trader

Well-Known Member
#11
Hmmm .... my experience with Ami is that everytime you close it and if any data was changed, it will save any unsaved data without prompting you ... Maybe there will be a preference setting somewhere to auto-save that I am yet to uncover.
Yes you are right,
In Ami it is auto save option by default.
However if you do not want auto save then go as

Preferences -> Miscellaneous
and tick the option "ask to save changed data"

Then it will ask you to save data, every time you close ami.
I prefer to save database manually.

You can save data by yourself by pressing "save the database" button on the toolbar also.
 

mastermind007

Well-Known Member
#13
Here is the solution !!!
Code:
[FONT="Courier New"]
// //                                                                   //      
// // File:                DeleteDateRange.js                           //
// // Author:              mastermind007                                //
// // http://www.traderji.com/amibroker/88211-deleting-rt-ticks-2.html#post825413
// // Purpose:             Remove all quotations between                //
// //                      two given Date and Time Stamps               //
// // Language:            JScript (Windows Scripting Host)             //
// // ENJOY :-)                                                         //
// //                                                                   //
   // ////////////////////////////////////////////////////////////////////
   //A D J U S T   N E X T   3   L I N E S   B E F O R E   R U N N I N G
   // ////////////////////////////////////////////////////////////////////
    DataDir = "@@@@@YOURDATA@@@PATH"
    // CAUTION Jan is 00. Feb is 01. Dec is 11.
    var DayDeleteFrom = new Date(2013, 00, 07, 09, 00);
    var DayDeleteUpto = new Date(2013, 00, 07, 23, 30);
   // ///////////////////////////////////////////////////////////////////
   // ///////////////////////////////////////////////////////////////////
   // ///////////////////////////////////////////////////////////////////
    
    var oAB = new ActiveXObject("Broker.Application");
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var fileX = fso.OpenTextFile( "C:\\DeleteDateRange.Amibroker.log", 2, true );

    oAB.LoadDatabase( DataDir );

    var oStocks = oAB.Stocks;

    var Qty = oStocks.Count;

    var j = 0;
    var k = 0;

    fileX.WriteLine( "Will delete all quotations from all stocks between starting date:" + DayDeleteFrom);
    fileX.WriteLine( "and ending date:" + DayDeleteUpto);
    fileX.WriteLine( "" );
    WScript.Echo("Cleanup Will Start Now !!!. Abort Process if this is not what you want" );

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

        while (j < oStock.Quotations.Count)
        {
            tmpDateNum = oStock.Quotations( j ).Date ;
            //fileX.WriteLine( "Date returned by AB is " + tmpDateNum);
            if ((tmpDateNum >= DayDeleteFrom) && (tmpDateNum <= DayDeleteUpto))
            {
                k++;
                oStock.Quotations.Remove(j);
            } else if (tmpDateNum > DayDeleteUpto)
            {
                  break;
            }  else
                j++;
        }
        fileX.WriteLine( "Deleted " + k  + " quotes from " + oStock.Ticker);
    }
    oAB.SaveDatabase( );

    fileX.Close();
    WScript.Echo("Deletion completed :-)" );
[/FONT]
 

mastermind007

Well-Known Member
#15
Don't know exactly why, but would suggest a decrementing j approach.
That would have been a correct way to code if I had used conventional for loop where increment happens at the opening of for loop.
In this js file, I've used while loop and j increments only if deletion does not happen. Also, While loop will never run completely.
(i.e. as long as Sentinel dates are defined correctly!!)

This approach is better suited for most general purpose cleanup cases, because Ami Quotations are always sorted by date and deleting past data is more common requirement than deleting recent data.

Only scenario where decrementing j approach would be faster is if one needed to deleting more recent quotes.

There is a design pattern (a programming thing) available for this, if you are interested.
 

yusi

Well-Known Member
#16
That would have been a correct way to code if I had used conventional for loop where increment happens at the opening of for loop.
In this js file, I've used while loop and j increments only if deletion does not happen. Also, While loop will never run completely.
(i.e. as long as Sentinel dates are defined correctly!!)

This approach is better suited for most general purpose cleanup cases, because Ami Quotations are always sorted by date and deleting past data is more common requirement than deleting recent data.

Only scenario where decrementing j approach would be faster is if one needed to deleting more recent quotes.

There is a design pattern (a programming thing) available for this, if you are interested.
Okay; just a suggestion; your call eventually.

Binary find instead of second-guessing recent or earlier, since guaranteed sorted.
 

mastermind007

Well-Known Member
#17
Okay; just a suggestion; your call eventually.

Binary find instead of second-guessing recent or earlier, since guaranteed sorted.
Yup, Binary find would work.
 
#18
Here is the solution !!!
Code:
[FONT="Courier New"]
// //                                                                   //      
// // File:                DeleteDateRange.js                           //
// // Author:              mastermind007                                //
// // http://www.traderji.com/amibroker/88211-deleting-rt-ticks-2.html#post825413
// // Purpose:             Remove all quotations between                //
// //                      two given Date and Time Stamps               //
// // Language:            JScript (Windows Scripting Host)             //
// // ENJOY :-)                                                         //
// //                                                                   //
   // ////////////////////////////////////////////////////////////////////
   //A D J U S T   N E X T   3   L I N E S   B E F O R E   R U N N I N G
   // ////////////////////////////////////////////////////////////////////
    DataDir = "@@@@@YOURDATA@@@PATH"
    // CAUTION Jan is 00. Feb is 01. Dec is 11.
    var DayDeleteFrom = new Date(2013, 00, 07, 09, 00);
    var DayDeleteUpto = new Date(2013, 00, 07, 23, 30);
   // ///////////////////////////////////////////////////////////////////
   // ///////////////////////////////////////////////////////////////////
   // ///////////////////////////////////////////////////////////////////
    
    var oAB = new ActiveXObject("Broker.Application");
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var fileX = fso.OpenTextFile( "C:\\DeleteDateRange.Amibroker.log", 2, true );

    oAB.LoadDatabase( DataDir );

    var oStocks = oAB.Stocks;

    var Qty = oStocks.Count;

    var j = 0;
    var k = 0;

    fileX.WriteLine( "Will delete all quotations from all stocks between starting date:" + DayDeleteFrom);
    fileX.WriteLine( "and ending date:" + DayDeleteUpto);
    fileX.WriteLine( "" );
    WScript.Echo("Cleanup Will Start Now !!!. Abort Process if this is not what you want" );

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

        while (j < oStock.Quotations.Count)
        {
            tmpDateNum = oStock.Quotations( j ).Date ;
            //fileX.WriteLine( "Date returned by AB is " + tmpDateNum);
            if ((tmpDateNum >= DayDeleteFrom) && (tmpDateNum <= DayDeleteUpto))
            {
                k++;
                oStock.Quotations.Remove(j);
            } else if (tmpDateNum > DayDeleteUpto)
            {
                  break;
            }  else
                j++;
        }
        fileX.WriteLine( "Deleted " + k  + " quotes from " + oStock.Ticker);
    }
    oAB.SaveDatabase( );

    fileX.Close();
    WScript.Echo("Deletion completed :-)" );
[/FONT]
Hi

I have entered the Dir path, But the afl is coming up with errors

"Sytax error, Unexpected identifier ,Isthere a semicolon missing at the previous line ?

Could u please help


I have entered the path as
DataDir = D:\\Mydata ;

Tried with D:\Mydata ; also ..but still the error,
Please guide about the usuage
 

KelvinHand

Well-Known Member
#20
Hi

I have entered the Dir path, But the afl is coming up with errors

"Sytax error, Unexpected identifier ,Isthere a semicolon missing at the previous line ?

Could u please help


I have entered the path as
DataDir = D:\\Mydata ;

Tried with D:\Mydata ; also ..but still the error,
Please guide about the usuage
Hello,


This is jscript standalone. you cannot put into AFL directly.
1. you can execute the jscript from window with amibroker is running.
2. usually we put in the Amibroker\scripts\ folder, so that we can setup and call from Tools Menu easily.

3. You can call from AFL if and only if you know how to use
ShellExecute("wscript.exe", "DeleteDateRange.js", ".\\Scripts");
 
Last edited:

Similar threads