SymbolsTotal() returns more symbols than those selected in the MarketWatch

 

I have a Trading Panel that, besides other stuff, has two buttons; the first sets the current chart to the next symbol in the MarketWatch, whilst the other sets the current chart to the previous symbol.

The code of both functions starts like this:


void OnClickNextBtn()
{
    int total=SymbolsTotal(true);
    Print("Total symbols = ", total);

//... function goes on
}


As you can see here, there's no USDJPY in the MarketWatch. However, when I click any of the buttons, it'll at some point select and set the chart to symbols that are not in the MarketWatch list.



Also, note that I have 7 symbols, but the print statement reveals that SymbolsTotal() function returns more than 7:

I tried deleting the symbols/ticks/history folders inside /bases/broker_server_folder/, but it didn't work.

What am I missing here?

 
Emanuel Cavalcante Amorim Filho:

I have a Trading Panel that, besides other stuff, has two buttons; the first sets the current chart to the next symbol in the MarketWatch, whilst the other sets the current chart to the previous symbol.

The code of both functions starts like this:



As you can see here, there's no USDJPY in the MarketWatch. However, when I click any of the buttons, it'll at some point select and set the chart to symbols that are not in the MarketWatch list.



Also, note that I have 7 symbols, but the print statement reveals that SymbolsTotal() function returns more than 7:

I tried deleting the symbols/ticks/history folders inside /bases/broker_server_folder/, but it didn't work.

What am I missing here?

Are you removing symbols from the MarketWatch programmatically, maybe?

It should not be possible, but maybe you remove a symbol to a position that's open.

This would explain the return value of SymbolsTotal. Else I would say, that could be a bug.
 
Dominik Egert #:
Are you removing symbols from the MarketWatch programmatically, maybe?

It should not be possible, but maybe you remove a symbol to a position that's open.

This would explain the return value of SymbolsTotal. Else I would say, that could be a bug.

No. As far as I know, the only way to remove a symbol programatically is calling SymbolSelect, right? My EA never calls that anywhere. That function only calls SymbolsTotal, SymbolName and ChartSetSymbolPeriod.

Just to make it a little bit more clear on the function code:


void OnClickPrevBtn()
{
    int total=SymbolsTotal(true);
    string symbols[];

    ArrayResize(symbols, total);

    for(int i = 0; i < total; ++i)
    {
        string name=SymbolName(i, true);

        for(int n = 0; n < total; ++n)
        {
            /*inserts symbols in alphabetical order*/
            if(StringLen(symbols[n])==0)
            {
                symbols[n]=name;
                break;
            }

            if(name < symbols[n])
            {
                for(int j = total-1; j > n; j--)
                {
                    symbols[j]=symbols[j-1];
                }

                symbols[n]=name;
                break;
            }
        }
    }

    for(int i = total-1; i > 0; --i)
    {
        if(_Symbol==symbols[i])
        {
            ChartSetSymbolPeriod(0, symbols[i-1], PERIOD_CURRENT);
            return;
        }
    }

    ChartSetSymbolPeriod(0, symbols[total-1], PERIOD_CURRENT);
}
 
Emanuel Cavalcante Amorim Filho:

I have a Trading Panel that, besides other stuff, has two buttons; the first sets the current chart to the next symbol in the MarketWatch, whilst the other sets the current chart to the previous symbol.

The code of both functions starts like this:



As you can see here, there's no USDJPY in the MarketWatch. However, when I click any of the buttons, it'll at some point select and set the chart to symbols that are not in the MarketWatch list.



Also, note that I have 7 symbols, but the print statement reveals that SymbolsTotal() function returns more than 7:

I tried deleting the symbols/ticks/history folders inside /bases/broker_server_folder/, but it didn't work.

What am I missing here?

There can be hidden symbols in the Market, they are automatically selected by the platform mainly for the calculation of positions margin and profit.

You can filter them :

  for(int i = 0; i < total; ++i)
   {
    string name=SymbolName(i, true);

    if(!SymbolInfoInteger(name,SYMBOL_VISIBLE))
     {
      printf("%s selected in Market Watch but not visible.",name);
      continue;
     }
    ...
   }
 
Thank you, Alain! It works just fine, now. Didn't know of that market watch behavior. Thanks a lot!
 
Alain Verleyen #:

There can be hidden symbols in the Market, they are automatically selected by the platform mainly for the calculation of positions margin and profit.

You can filter them :

I forgot about that as well.... Thank you.
 
Emanuel Cavalcante Amorim Filho #:
Thank you, Alain! It works just fine, now. Didn't know of that market watch behavior. Thanks a lot!
Dominik Egert #:
I forgot about that as well.... Thank you.
I deserve a "Like"...lool
 
You definitely do! Take it ;) 
 
Alain Verleyen #:
I deserve a "Like"...lool
Oh, that's a new feature, it's actually possible to vote answers/replies now. I thought that were only a link to take you to the top of the page....

What's happening here, totally new MQ attitude. I am baffled.