Delete Quotes that have time-seconds value of 00

radiosilk

Active Member
#1
Delete Quotes that have time-seconds value of 00
-------------------------------------------------------


Can anyone help in modifying below script (by Ami's TJ), to delete only those quotes that have time-seconds value = 00.

Example,
if time value = 12:31:59, correct value
if time value = 12:31:00, WRONG value --- Delete this quote but not the above one.

Some one who knows scripting could please help..

PHP:
// THIS IS NOT AFL
// This is Windows script to be run from the outside of AmiBroker
function 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" );
 

radiosilk

Active Member
#2
seems that "qt.Date" is the object that can be used to sort out this script here.

if anyone who knows js equivalent of below vba sample then pls share.

if Right(qt.Date, 2) = 00 then delete quote

(yet to understand the part after delete but anyways)

so pls, if anybody who knows coding help a bit..
 

radiosilk

Active Member
#3
@mastermind007 , @trash , @yusi

saw your comments on this thread

request you to pls help modify the code in the 1st post of this thread.

like for any open chart if there's data with 00 as seconds value then the script deletes that quote.
 

yusi

Well-Known Member
#4
Delete Quotes that have time-seconds value of 00
-------------------------------------------------------

PHP:
    ...
     for( i = iQty - 1; i >= 0; i-- )
     {
        qt = Quotes.Item( i );
        if( qt.Volume == 0 ) 
        { 
           cnt++;
           Quotes.Remove( i );
        }
     }
Suggest you try the following change. It would be best if you checked it on a database copy (with Quotes.Remove commented and debug statements added). Or better still, you could manually add a few quotes with seconds as 25, say, and check if they get deleted.

Code:
    ...
     for( i = iQty - 1; i >= 0; i-- )
     {
        qt = Quotes.Item( i );
        //dt may vary with locale but we are interested in the seconds
        dt = new Date( qt.Date );
        if( dt.getSeconds() == 0 ) 
        { 
           cnt++;
           Quotes.Remove( i );
        }
     }
 

radiosilk

Active Member
#5
Thanks a lot, Yusi Sir.

Can this Jscript take user input for "Ticker/Symbol"? I looked around and found that some wsf needs to be used and i tried hard to make it work but couldn't.

If that's too complicated then how can the script be modified to scan all symbols-quotes for a given period ? (tried using MasterMind's script, but haven't succeeded till now).

Anyways, just putting it together for ease of use for anyone who needs it.

PHP:
//****************************************************
/////////////////////// CAUTION/////////////////////////////////////////
// This script deletes quotes that end with "Seconds Value == 00"
// Make a backup of db before executing this script
// THIS IS NOT AFL 
// This is Windows script to be run from the outside of AmiBroker 
/////////////////////// CAUTION/////////////////////////////////////////
//****************************************************
// Enter Amibroker Symbol in the second-last line "n= ..."
// Copy-paste this code in notepad and save file with extension ".js"
// Double click the file to execute
// THANKS TO: Traderji's MasterMind, Yusi for this script



function RemoveQuotesWithZeroSeconds( 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 );
        //dt may vary with locale but we are interested in the seconds

        dt = new Date( qt.Date );
        if( dt.getSeconds() == 0 ) 
        { 
           cnt++;
           Quotes.Remove( i );
        }
     }
     
     AB.RefreshAll(); 

     return cnt; 
} 
n = RemoveQuotesWithZeroSeconds("Nifty"); 
WScript.Echo ( "Removed " + n + " quotes with -00- seconds" );
 
#6

Similar threads