Batch > Watchlist > ShellExecute

Trying to create step 2 of a Batch file sequence, since I think that is the process of what needs to happen.

Step 1 > Run > Exploration to Add Symbols to Watchlist "List 10" // This part Works Great - Thanks to TJ documentation

Step 2 > Extract Symbols from Watchlist "List 10" and ShellExecute the ExportImage.js

I get confused on the proper object syntax between FSO, VBScript, OLE, and JScript.
This is what I have so far, but not sure if it should be FSO?

Do I need to use #include in this file as well so it can reference the file that placed the symbols in the watchlist?
How do I loop thru the symbols from watchlist "List 10" and trigger the shellexecute for each individual symbol, once each until done.?
Do I save as a separate file / project (if so, what file extension?) and then in the batch, add run step 1, wait, then add run step 2?

Amibroker is loaded and the desired Window sheet tab is the Active Window.
So, in Step 2 > Extract Symbols from Watchlist "List 10" and ShellExecute the ExportImage.js

Thanks in advance.

listnum = 10;
if (InWatchListName(" List 10"))
{	
	ShellExecute("wscript.exe", "ExportImage.js", "C:\\Program Files\\AmiBroker\\Scripts\\");
}

Hi. @MrV

A javascript form an old Yahoo mailing list.

I just test it and works perfect
If you like to try this, is a ready code to export from a WatchList all symbols images

// Here is one. Save a .js file not as .AFL
// If you wanna execute from AFL then use ShellExecute() AFL function
//  execute one by one ALL the tickers from WatchList and save in a *.png 
// ImageTest_02.js by Progster, fixed by Tomasz Janeczko


iWatchList = 0; // you can define watch list number here

AB = new ActiveXObject("Broker.Application");
Qty = AB.Stocks.Count;

for( i = 0; i < Qty; i++ )
{
    Stk = AB.Stocks( i );
	//exportfolder = "C:\\#ABexport\\" + Stk.Ticker + ".png";
    exportfolder = "R:\\" + Stk.Ticker + ".png";

    if( iWatchList < 32 )
    {
        if( Stk.WatchListBits & ( 1 << iWatchList ) )
        {
            AB.ActiveDocument.Name = Stk.Ticker;
            WScript.Sleep( 100 ); // 0.1 sec wait
            AB.ActiveWindow.ExportImage( exportfolder );
        }
    }
    else
    {
        if( Stk.WatchListBits2 & ( 1 << ( iWatchList - 32 ) ) )
        {
            AB.ActiveDocument.Name = Stk.Ticker;
            WScript.Sleep( 100 ); // 0.1 sec wait
            AB.ActiveWindow.ExportImage( exportfolder );
        }
    }
}

//notify the user when finished
Shell = new ActiveXObject("WScript.Shell");
Shell.Popup("Image(s) exported", 1.5);
1 Like

PanoS,
Thank you.
I edited it to change the export path and add the pixel width and height and saved as .js file.
I am using List 10, and I ran it from cmd line as wscript.exe
and it Only returned the first symbol in Watchlist 10 and none of the others.

Since there are a number of them in there, I would also like to add a date format to the file path as MM_DD_YYYY. So, Stk.Ticker + filenameDate + .png
I tried to add it and was unsuccessful. Below are the edited codes.

Edited .js Script file saved in the Scripts Folder:

// Here is one. Save a .js file not as .AFL
// If you wanna execute from AFL then use ShellExecute() AFL function
//  execute one by one ALL the tickers from WatchList and save in a *.png 
// ImageTest_02.js by Progster, fixed by Tomasz Janeczko


iWatchList = 10; // you can define watch list number here

AB = new ActiveXObject("Broker.Application");
Qty = AB.Stocks.Count;

for( i = 0; i < Qty; i++ )
{
    Stk = AB.Stocks( i );
    
    exportfolder = "C:\\DataExport\\" + Stk.Ticker + ".png";

    if( iWatchList < 32 )
    {
        if( Stk.WatchListBits & ( 1 << iWatchList ) )
        {
            AB.ActiveDocument.Name = Stk.Ticker;
            AB.ActiveWindow.ExportImage( exportfolder , 640, 480 ); 
        }
    }
    else
    {
        if( Stk.WatchListBits2 & ( 1 << ( iWatchList - 32 ) ) )
        {
            AB.ActiveDocument.Name = Stk.Ticker;
            AB.ActiveWindow.ExportImage( exportfolder , 640, 480 ); 
        }
    }
}

//notify the user when finished
Shell = new ActiveXObject("WScript.Shell");
Shell.Popup("Image(s) exported", 1.5);

Edited filenameDate format that works in AFL to insert into .js file:

dt = SelectedValue(DateTime());
str1 = DateTimeFormat( "%#x", dt );// long date
str2 = StrTrim(StrExtract(str1, 1)," ");// Remove weekday
str3 = DateTimeFormat( "%Y", dt );
longdate = str2 + ", " + str3;
str4 = DateTimeFormat( "%m", dt );
str5 = DateTimeFormat( "%d", dt );
//str6 = DateTimeToStr( 4, mode = 1 )
filenameDate = ("_" + str4 + "_" + str5 + "_" +  str3 + "_");  //

Thanks in Advance.

PanoS and TJ, Thank You! This Works.

I changed the watchlist number to watchlist 0 and it works, as you said.
It now erases and refreshes the watchlist with each Scan or Exploration

Exploration or Scan results to Watchlist 0

//Open Analysis Window and select formula Exploration to Watchlist 0.afl from folder
// Run Exploration code > that will save the resulting symbols to Watchlist 0
//Settings: Apply To: Filter Range: From-To-Dates  Today and Today

Buy = Close > 2800.00;  // Change to your buy parameters for Scan button
Filter = Close > 2800.00; // Change to your buy parameters for Exploration button
AddColumn( Close, "Close" ); // Results will display in the Exploration window as well


listnum = 0; // we use watchlist 0 for storing results > This will automatically refresh with a Exploration

// erase the watchlist when we process very first symbol
if ( Status( "stocknum" ) == 0 )
{
    // retrieve watchlist members
    oldlist = CategoryGetSymbols( categoryWatchlist, listnum );

    // iterate through the list and remove tickers
    for ( i = 0; ( sym = StrExtract( oldlist, i ) ) != ""; i++ )
    {
        CategoryRemoveSymbol( sym, categoryWatchlist, listnum );
    }
}

// check how many times Filter variable was true in the tested range
// if non-zero value detected, add current symbol to a watchlist
if ( LastValue( Cum( Filter AND Status( "barinrange" ) ) )  )
    CategoryAddSymbol( "", categoryWatchlist, listnum );

ExportImage from Watchlist 0 to disk folder - This works and iterates thru each symbol creating an image of the Active Window Sheet tab which must be displayed at the time you execute.

/// Open Notepad and Copy the code below, paste, and save as WL_Export.js
/// Be sure to change the destination exportpath to a directory on your system and use the double \ in the folder path on Windows machines
/// You can also adjust the pixel width and height to your needs before saving the file e.g. 640 by 480
/// Place this file in your AmiBroker/Scripts/ directory
/// Open AmiBroker and navigate to the Sheet tab you would like Watchlist images of
/// ShellExecute the WL_Export.js file and be patient as it will take time to cycle thru generating the image for each ticker in the watchlist
/// Finally, This code works!

// Here is one from PanoS and Tomasz Janeczko. Save a .js file not as .AFL
// If you wanna execute from AFL then use ShellExecute() AFL function
// execute one by one ALL the tickers from WatchList and save in a *.png
// ImageTest_02.js by Progster, fixed by Tomasz Janeczko

// Save code below as: WL_Export.js
/// Place this file in your AmiBroker/Scripts/ directory
// ShellExecute the file and wait, the images will appear in your destination directory
// paste in command prompt and wait:

C:\Program Files\AmiBroker\Scripts>wscript.exe WL_Export.js

// monitor your destination directory for image export

iWatchList = 0; // you can define watch list number here

AB = new ActiveXObject("Broker.Application");
Qty = AB.Stocks.Count;

for( i = 0; i < Qty; i++ )
{
    Stk = AB.Stocks( i );
	//exportfolder = "C:\\#ABexport\\" + Stk.Ticker + ".png";
    exportfolder = "C:\\DataExport\\" + Stk.Ticker + ".png";

    if( iWatchList < 32 )
    {
        if( Stk.WatchListBits & ( 1 << iWatchList ) )
        {
            AB.ActiveDocument.Name = Stk.Ticker;
            WScript.Sleep( 100 ); // 0.1 sec wait
            AB.ActiveWindow.ExportImage( exportfolder , 640, 480);
        }
    }
    else
    {
        if( Stk.WatchListBits2 & ( 1 << ( iWatchList - 32 ) ) )
        {
            AB.ActiveDocument.Name = Stk.Ticker;
            WScript.Sleep( 100 ); // 0.1 sec wait
            AB.ActiveWindow.ExportImage( exportfolder );
        }
    }
}

//notify the user when finished
Shell = new ActiveXObject("WScript.Shell");
Shell.Popup("Image(s) exported", 1.5);
1 Like

Hello @MrV
Well done, finally you found your mistakes.
Bravo :+1:

You can add few more lines in your last JS script to include date format on the file name.

iWatchList = 0; // you can define watch list number here

DateObj=new Date();
D=DateObj.getDate();
M=(DateObj.getMonth()+1);
Ye=DateObj.getYear();
H=DateObj.getHours();
mi=DateObj.getMinutes();

AB = new ActiveXObject("Broker.Application");
Qty = AB.Stocks.Count;

for( i = 0; i < Qty; i++ )
{
    Stk = AB.Stocks( i );

    // exportfolder = "C:\\DataExport\\" + Stk.Ticker + ".png";
	
	// export file name with date format = "Symbol_YYYYMMDD_HH-MM"
	exportfolder = "C:\\DataExport\\" + Stk.Ticker + "_"+Ye+M+D+"_"+H+"-"+mi+ ".png";  


    if( iWatchList < 32 )
    {
	
// ...............  rest of the JS code    

PanoS,

Thank you, much appreciated.

MrV

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.