Create shortcuts for Symbols

There are a lot of features to create shortcuts or custom links from customize.

Can any shortcut be assigned a Symbol so that one-click can select symbol.

Ofcourse, we can config a Watchlist but in my case, if i need a quick symbol a few times an hour if i am trading, then it is still a couple of clicks or i have to type a few chars in symbol dropdown.

1 Like

In my opinion using watchlists for that is still the best and for sure the most straightforward option.

@nsm51 that is not exactly true, because in case of watchlists you only need one click to change a symbol :wink:

You can make your watchlist always visible using a pinup button (in the upper right corner of Symbols list) or by dragging it and docking as a separate window. See here:

But (if you really insist) because you can change the Symbol programatically (here is the simplest example changing currently selected chart to "CDR"):

if( ParamTrigger( "Change Symbol", "Press here" ) )

    AB = CreateObject( "Broker.Application" );
    doc = AB.ActiveDocument;
    doc.Name = "CDR";

...or change programatically chart interval:

... it can be done. You can create your own shortcuts either using Gui Buttons or custom toolbar shortcuts/buttons (a few other ways would be also possible)

Also remember that if you just switch between a few symbols back and forth, you can simply use Ctrl + Alt + Left Arrow and Ctrl + Alt + Right Arrow to change their charts:

Allows to move Back/Forward in 'browser-like' way.

  • Previous move to previous symbol (keyboard shortcut: Ctrl+Alt+LEFT)
  • Next move to next symbol (keyboard shortcut: Ctrl+Alt+RIGHT)

Lastly, remember about the Symbol finder window (F3 shortcut)



So you do not want to click on a Watchlist and select a symbol. :slight_smile:

Like @Milosz pointed out that would be ideal, however, I imagine you might want to hide the Watchlist section or might have long Watchlists. And during heat of intensive day trading simply toggle to some other Symbol instead of recalling the steps to reach that Symbol. Sometime back I had written a code but the subject is irrelevant to this topic. Anyways, here is a modified version of it tailored to your requirement. Hope it helps!

procedure SymGfxTxtWdth( List ) {
	 if( !Nz( StaticVarGet( "InitGfxTxtSz" + GetChartID() ) ) ) {
		 StaticVarSet( "InitGfxTxtSz" + GetChartID(), 1, False );
		 GfxTxtSz = 0;		 
		 for( i = 0; ( sym = StrExtract( List, i, ',' ) ) != ""; i++ ) GfxTxtSz = IIf( GfxGetTextWidth( sym ) > GfxTxtSz, GfxGetTextWidth( sym ), GfxTxtSz );
		 StaticVarSet( "GfxTxtSz" + GetChartID(), GfxTxtSz, False );

function SymPicker( SymList ) {
	 IsErr = 0;
	 if( GetAsyncKeyState( 17 ) < 0 && GetAsyncKeyState( 116 ) < 0 ) { // 17 = Ctrl, 116 = F5
		 SymGfxTxtWdth( SymList );
		 SymCount = StrCount( SymList, "," ) + 1;
		 BtnWidth = StaticVarGet( "GfxTxtSz" + GetChartID() );	 BtnHight = 20; 	BtnOffsetXY = 3;
		 // Stipulated GUI Area
		 TopLeftPxX = 10;							TopLeftPxY = 20;
		 BotRghtPxX = 200;							BotRghtPxY = 200;
		 // GfxFillSolidRect( TopLeftPxX, TopLeftPxY, BotRghtPxX, BotRghtPxY, colorGrey40 );
		 if( SymCount > floor( BotRghtPxY / ( BtnHight + 2 * BtnOffsetXY ) * BotRghtPxX / ( BtnWidth + 2 * BtnOffsetXY ) ) ) IsErr = 1;
		 else {
			 id = GuiGetEvent( 0, 0 );					event = GuiGetEvent( 0, 1 );			 
			 GfxSelectPen( colorBlack, 1 );				GfxSelectSolidBrush( colorWhite );
			 GuiBtnPxX = TopLeftPxX + BtnOffsetXY;		GuiBtnPxY = TopLeftPxY + BtnOffsetXY;
			 for( i = 1; i <= SymCount; i++ ) {
				 // Drawing the GUI Buttons
				 GuiButton( StrExtract( SymList, i - 1, ',' ), i, GuiBtnPxX, GuiBtnPxY, BtnWidth, BtnHight, 1 );
				 if( GuiBtnPxY > BotRghtPxY - BtnHight - BtnOffsetXY ) {
					 GuiBtnPxX += BtnWidth + BtnOffsetXY;
					 GuiBtnPxY = TopLeftPxY + BtnOffsetXY;
				 else GuiBtnPxY += BtnHight + BtnOffsetXY;
				 // Event triggers upon GUI Button clicks
				 if( id == i && event ) {
					 Ticker = StrExtract( SymList, i - 1, ',' );
					 fC = Foreign( Ticker, "C" );
					 if( !IsNull( fC[ 0 ] ) ) {
						 App = CreateObject( "Broker.Application" );
						 AppActvDoc = App.ActiveDocument;
						 AppActvDoc.Name = Ticker;
						 IsErr = 0;
					 else IsErr = 2;
		 if( !IsNull( StaticVarGet( "InitGfxTxtSz" + GetChartID() ) ) ) StaticVarSet( "InitGfxTxtSz" + GetChartID(), Null, False );
	 return IsErr;

_SECTION_BEGIN( "Dynamic Symbol Picker" );
	 // Using ParamStr here but you could use any other list type
	 FreqSymList = ParamStr( "Freq. Symbol list (comma-separated)", "EURUSD,GBPUSD,JPYUSD,USDCAD" ); // "Freq" means Frequent, "Sym" means Symbol
	 err = SymPicker( FreqSymList );
	 switch( err ) {
		 case 1:
			 ErrTxt = "Too many GuiButtons to fit in the stipulated area.\nChoose Parameters from Right-click menu and remove some of the unwanted symbols.";
			 if( !Nz( StaticVarGet( "PopupErr" + GetChartID() ) ) ) {
				 StaticVarSet( "PopupErr" + GetChartID(), 1, False );
				 PopupWindow( ErrTxt, "Error 99", 10, -1, -1, -1, -1, 1 );
			 Error( ErrTxt );
		 case 2:
			 ErrTxt = "No such symbol exist.\nCheck and change the Parameter string list.";
			 if( !Nz( StaticVarGet( "PopupErr" + GetChartID() ) ) ) {
				 StaticVarSet( "PopupErr" + GetChartID(), 1, False );
				 PopupWindow( ErrTxt, "Error 99", 10, -1, -1, -1, -1, 1 );
			 Error( ErrTxt );
		 default: // No error
			 SetChartOptions( 1, chartShowDates );
			 Plot( C, "Price", colorDefault, styleCandle );
			 if( !IsNull( StaticVarGet( "PopupErr" + GetChartID() ) ) ) StaticVarSet( "PopupErr" + GetChartID(), Null, False );
			 /* Do something else */

// The timed refresh is just for testing purposes which might be unnecessary during live datafeed and/or as per other segment(s) of your code.
// Also read this KB - When and how often AFL code is executed? (
RequestTimedRefresh( 1 );
|This code is for AmiBroker Formula Language (AFL) learning (non-commercial) purposes only. Please do not copy this code|
|(or any other version of it) and paste it over on other forums or anywhere else on the Internet or in any other form	|
|without the AmiBroker Forum owner's consent (                                            |


Press and hold Ctrl & F5 together for the GUI Buttons to populate on chart. While Ctrl & F5 are held down, click on the GuiButton for desired symbol to show-up in the ActiveDocument. Release the keys once done. You may also change the hotkey combination(s) by changing the argument of GetAsyncKeyState() directly from the code.


Otherwise as shown in the examples sought by Milosz, you could also create a customized toolbar.


thanks guys for all your suggestions.
I will read and try them over the weekend.

One alternative that i'm using is to run my formula with Foreign ticker fixed in it on another sheet of my working chart sheet.
so in one click i can swap through some sheets each with fixed symbol.
only drawback is that if the main ticker has holes or some data inconsistency then the charting is a bit different.

@Tomasz I hope we can have some buttons from customize that can be set out-of-the-box in the future. Thanks


Not sure what you mean by "out-of-the-box", but you can create custom Button(s) and put that in any of the toolbar. Try the steps below if that solves.

Step 1:

Using any Text Editor (like Notepad.exe) write simple two-liner .js for each symbol separately for which you want a single-click symbol picker button. And Save those in the Drive where AmiBroker is installed, preferably in AmiBroker\Scripts folder, however not necessarily, you can save those anywhere but make sure to put the correct path of those .js file in the next step.


var App = new ActiveXObject( "Broker.Application" );
App.ActiveDocument.Name = "EURUSD";


var App = new ActiveXObject( "Broker.Application" );
App.ActiveDocument.Name = "GBPUSD";


Step 2:

Repeat this process for each one of .js from main AmiBroker application window.

Tools -> Customize -> Tools -> New -> Type [Symbol Name] -> Type "Command" as [Full File Path of .js that you just created] -> Close


Step 3:

Then follow the steps as discussed in this KB. The only difference in this case is that while the Customize dialog box is open, you would need to select the Tools menu (instead of View menu) from the Menu bar to drag and drop those User defined tools that you see there in any toolbar of your choice.



P.S. If you wish to further customize your buttons, you may also refer to the Advanced customizable toolbars, menus and keyboard shortcuts section from the User interface customization guide.


this should work for me, thanks
for those who have a lot of symbols/watchlist would understand how useful such a one-click go-to a symbol is :slight_smile:

Out-of-the-box would be relatively very simple to-do for the developer is what i meant.
for example, In above solution, we would have a multi-AB instance problem

Just don’t think theirs demand for it. Easy way Is have separate chart and just go through MDI tabs at top. Can symbol lock the chart and that’s it. Or most have another monitor that you could just symbol lock a chart on or a couple and that’s it. Or you press a hot key to search symbol and type a few letters and your on that symbol.

thanks for your suggestion but

this slower back-and-forth inconvenience stemmed the idea in the first place. i wrote in opening post

this is resource intensive and i can regard as just a suggestion from another user

not practical all the time IMHO

possible, hence the suggestion to Tomasz

1 Like

Very helpful, thank @Cougar

1 Like

Thank you @Cougar. This is very useful.
How can one go about making the following modifications?

  1. Dynamically Populate FreqSymList from the list of active windows

  2. Not Hold Ctrl + F5 , till the symbol is selected. User can initially press Ctrl + F5 and then leave it
    This will show up the drop down list, from which user can select the symbol.

    If No symbol is selected , say within 5 seconds, the drop down list is no longer shown

I am still learning AFL, so all of this is very advanced for me.

I don’t see the purpose of that. You can simply setup a watchlist and go up/down immediately using arrows and that without ANY coding at all.

Or you can use Favorities


Thanks for sharing the code. Which section of the code needs to be modified If I want to display the buttons always without using the Ctrl + 5 commands.

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