Button to Remove Symbol from Watchlist

Hello! I have the following code that produces a button to remove the current symbol from watchlist "test". For some reason, nothing happens when I click on it. Is there something wrong with this code?

GuiButton( "RS", 6, 10, 225, 50, 30, 7 );
id = GuiGetEvent( 0, 0 );
event = GuiGetEvent( 0, 1 );

if( id == 6 && event == 1 )
{
	ListNum = CategoryFind("test", categoryWatchlist);
	CategoryRemoveSymbol("", categoryWatchlist, ListNum);
}

@trongart, I tried your code.

It works but the Amibroker UI (if you have the "test" watchlist displayed) is not automatically updated.
If you select another watchlist and then reselect the one where you deleted the symbol, you'll see that it is no longer there.

1 Like

I wonder if there is a way to update/refresh Amibroker UI.

Save below two lines as jscript to Scripts folder i.e. RefreshAll.js

var AB = new ActiveXObject("Broker.Application");
AB.RefreshAll();

Then in AB call ShellExecute()

if( your_trigger )
    ShellExecute("Scripts\\RefreshAll.js", "", "" );

On the other hand in analysis you can use

SetOption( "RefreshWhenCompleted ", True );

at the top of AFL.

•RefreshWhenCompleted - when set to TRUE, it will perform View->Refresh All after Automatic-Analysis operation (scan/exploration/backtest/optimize) is completed.

1 Like

Tried it as you suggested, but nothing happens still. Added the file RefreshAll.js in C:\Program Files\AmiBroker\Scripts

GuiButton( "RS", 6, 10, 225, 50, 30, 7 );
id = GuiGetEvent( 0, 0 );
event = GuiGetEvent( 0, 1 );

if( id == 6 && event == 1 )
{
	ListNum = CategoryFind("test", categoryWatchlist);
	CategoryRemoveSymbol("", categoryWatchlist, ListNum);
	ShellExecute("Scripts\\RefreshAll.js", "", "" );
}

@trongart Why don't you try the simplest solution instead of using Gui Buttons code? You can easily assign custom keyboard shortcuts for such tasks. For example Ctrl+Shift+W to add selected symbol(s) to a watchlist and Ctrl+Alt+W to remove selected symbol(s) from a watchlist (or any other shortcuts that you like).

Shortcut

https://www.amibroker.com/guide/w_customize.html

You wlll be able to add or remove symbols to/from watchlists not only from the chart, but also directly from the exploration output or from the Symbols list. As you can see, there's no lag and all watchlists are automatically updated:

Watchlist3

Regards.

2 Likes

Hi Milosz, thank you for the suggestion. I used this before, but it requires to do the keyboard shortcut and then also to click ok with the mouse in the watchlist pop up window. With a GUI button it’s really only one mouse click and thus faster especially when you have to sort through hundreds of symbols :slight_smile:

But don't forget, that with ctrl key pressed you can select/deselect multiple symbols. During this procedure you can even switch to other windows, do some other things and later come back to the list to continue this procedure (the symbols stay selected untill you select one of them without ctrl key pressed) and remove all choosen symbols at once. Pressing the keyboard shortcut only once, clicking OK button only once and confirming performing operation on multiple symbols only once, will allow you to remove unlimited number of symbols at once. Besides you can add/remove symbols to/from different watchlists - not only one watchlist defined in the code. So as usual, there are different ways to achieve the same result :slight_smile:

Watchlist4

3 Likes

Just call RefreshAll directly without ShellExecute and without JScript. It does not hurt if you just to this once on button click

pxheight = Status("pxheight");
resetButtonID = 6;
GuiButton( "RS", resetButtonID , 10, pxheight - 35, 50, 30, notifyClicked );
id = GuiGetEvent( 0, 0 );
notify = GuiGetEvent( 0, 1 );

if( id == resetButtonID AND notify == notifyClicked )
{
    ListNum = CategoryFind("test", categoryWatchlist);
    CategoryRemoveSymbol("", categoryWatchlist, ListNum);
    AB = CreateObject("Broker.Application");
    AB.RefreshAll();
}

But really... @Milosz solution is so much better.

2 Likes

@Tomasz if you use the external Jscript file or calling the "RefreshAll" directly from AFL code as in your sample code, does not address the "UI" glitch the @trongart was seeing (at least in my configuration using the 6.28 beta - 64 bit).

As I wrote above, the function works as documented, but the AmiBroker UI, if you have the "test" watchlist displayed, is not automatically updated.

(If you select another watchlist and then reselect the one where you deleted the symbol, you can verify that the chosen symbol is no longer there).

So this may be something to consider for future versions of AmiBroker.

1 Like