Deleting RT ticks

Steve

Active Member
#21
HI Seniors,
I'd appreciate your help in "RTD auto saving" in Ami during market hours, At times
during power outages, or other such incidences, entire data of previous hours
is lost if it was not saved manually
Is there a way to auto save data every 5 minutes or so.

I'm off topic here since you're discussing deleting data, all the same
since seniors are here I'd appreciate your help if possible

Thanks.

Steve
 
Last edited:

a1b1trader

Well-Known Member
#22
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 Mastermind

Can you please let me know how to use this code, I mean how to execute this Jscript.
Further what changes I have to made, if I want to delete data, say, from 1.4.13 to 28.6.13

Thanks
 

mastermind007

Well-Known Member
#23
Hi Mastermind

Can you please let me know how to use this code, I mean how to execute this Jscript.
Further what changes I have to made, if I want to delete data, say, from 1.4.13 to 28.6.13

Thanks
a1b1 and all others


It is a JS file, so you need to double click on it from explorer and usually OS will know how to run it. On my machine, I have a 3rd party JS compiler that runs this but it will not be there on your machien by default. Script will still run without it but I don't remember the name of executable.

I've placed comments in the code for you ppl to read and act accordingly. Highlighting what is already in the code. You have to enter the dates desired in two variables. You have to place path (in double quotes pair ) of your database in the correct field. Hint: I was deleting data on 7th January 2013 from 9AM to 11:30 PM

// ////////////////////////////////////////////////////////////////////
//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);
 

josh1

Well-Known Member
#24
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 Mastermind,

I tried it. It is working. However, it is very....... slow. Is there a faster solution?
 

mastermind007

Well-Known Member
#25
Hi Mastermind,

I tried it. It is working. However, it is very....... slow. Is there a faster solution?
Yes, it is very slow. Faster approach is as follows

a) Export all ticks into a CSV file (compress it as necessary).
b) Edit the resulting CSV file manually and remove unwanted ticks
c) Empty the symbol in AmiBroker or simply Delete it
d) Re import edited CSV file
 

Similar threads