How to Check If A Symbol Exists in Amibroker DB

Hi,

I am working on an AFL where I determine the name of a Ticker based on some dynamic parameters.

Say Sym_Z = X + Y ; where both X and Y are some dynamic strings. While care is taken that both X and Y are valid values, sometimes I am encountering issue where the ticker formed combining X and Y is not a ticker present in Amibroker DB and thereby in downstrem foreign calls its causing issues. So I need to ensure that Sym_Z is a valid ticker before initiating computation on that ticker.

I tried using Foreign call and validating the outcome. But no luck yet. Can someone please guide me on how can I come to a binary conclusion that Sym_Z exists in Amibroker DB ? I am not sure to what should I compare the outcome {EMPTY} to determine its an invalid symbol. If any other cleaner method is available, please suggest.

My trace attempt on below code chuck and its outcome is as below.

_TRACE("!CLEAR!");
Sym_Z_Exists = Foreign(Sym_Z,"C");
_TRACE("Sym_Z_Exists =>" + Sym_Z_Exists);


image

Thanks,
Nandy

{EMPTY} is just other name for Null value and that is precisely how you would check for existence:

fc = Foreign("NONEXISTING","C");

if( typeof( fc ) == "number" AND IsNull( fc ) )
{
  printf("Symbol does NOT exist\n");
}

Or alternative code:

fc = Foreign("NONEXISTING","C");

if( IsNull( fc[BarCount-1] ) )
{
  printf("Symbol does NOT exist\n");
}
1 Like

Dear Tomasz,

Thank you for your quick help. Really appreciate it.

Thanks,
Nandy

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