How to find out the ordinal number or name of the watchlist in which symbol is being dispalyed

Hi AB experts,

I have same tickers in more than one watchlists. I am writing indicators that depends which watchlist the symbol is located. i need to find the ordinal number or name of the watchlist in which symbol is being dispalyed.
I have look through the category function list and cannot figure out a way to do so.
It would be much appreciated if someone with better brain to teach me how to do it.

Thank you,
jimmy

Hi Jimmy,

Something like this might help. It will display in a chart pane by clicking apply.

_SECTION_BEGIN("WL");
Title = "\nWatch List:  ";

for( i = 0; CategoryGetName( categoryWatchlist, i )!= ""; i++ ) 
{ 
	if( InWatchList( i ) ) 
			Title = Title+ "\n   " + CategoryGetName( categoryWatchlist, i ); 
}

_SECTION_END();

Anthony

2 Likes

@etcjkam

/// @link http://forum.amibroker.com/t/how-to-find-out-the-ordinal-number-or-name-of-the-watchlist-in-which-symbol-is-being-dispalyed/1590/3
wlstr = "";
category = categoryWatchlist;
for( i = 0; CategoryGetName( category, i ) != ""; i++ ) {
   if( InWatchList( i ) ) {
       catname = CategoryGetName( category, i ); 
       wlstr += "\n<i>#WL:</i> <b>" + CategoryFind( catname, category ) + "</b>, <i>WL Name:</i> <b>" + catname + "</b>";      
   }
}
printf( EncodeColor(colorGreen) + "<b>Watchlist Membership(s):</b>" + EncodeColor(-1) + wlstr );

4 Likes

Hi Anthony and fxshrat,
Really Appreciate the prompt and concise help you have provided. Heart felt thanks to you both.

My real difficulty is to know the unique ordinal number(watchlist) which is being addressed (charted) currently , so that I could differentiate the logic in my indicators.

Thank you,
jimmy

Hi Jimmy,

I am trying to understand your logic above , I think you could create a check in your indicator as to what watchlist is currently being addressed, something like: iif(inwatchlist(0), this indicator, iif(inwatchlist(1), this indicator etc,etc.

if (InWatchList(0)) 
{             /* With braces */
    Plot(Close,"",colorBlack,stylecandle);
}
else
    if(InWatchList(1))
    {
    Plot(MA(C,20),"",colorBlue,styleLine);
    }
    else
    Plot(MACD(),"MACD",colorRed,styleHistogram);//default if not in a watchlist

 _SECTION_BEGIN("WL");
Title = "\nWatch List:  ";

for( i = 0; CategoryGetName( categoryWatchlist, i )!= ""; i++ ) 
{ 
	if( InWatchList( i ) ) 
			Title = Title+ "\n   " + CategoryGetName( categoryWatchlist, i ); 
}

_SECTION_END();





I have tested this concept and if the symbol is in multiple watchlist then the above flow defaults to the watchlist prior for that symbol.

example:
if symbol is in watchlist 0 and watchlist 1 then the indicator defaults to indicator referenced for watchlist 0, at least that is what I am seeing right now.

Anthony

Dear Anthony,

I really appreciate your effort to understand my problem. As the symbol is in both watchlist0 and watchlist1, inwatchlist(0) and inwatchlist(1) will evaluate to be true. In this case we still do not know which watchlist is currently being referenced to.

My fear is that the algo i intended may not be possible without new functions - activewatchlist() returning ordinal number from Amibroker devlopers.

Lets try to think a bit more to see if we can crack this.

Many Thanks
jimmy