SymbolSelect gives Specified symbol is not selected

 

Hi,

 

I want to add a symbol to MarketWatch to do some stuff later on. when I run my code, I get  "Specified symbol is not selected".

But when I first add a symbol in MarketWatch manually (any symbol) and then run the code, whatever symbol selected in the code will be added to the market watch.

string            empty_symbol="EMPTY";

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

//---

  

   AddSymbolToMarketWatch("MySymbolName");

   

  }

//+------------------------------------------------------------------+



//+------------------------------------------------------------------+

//| Adding the specified symbol to the Market Watch window           |

//+------------------------------------------------------------------+

string AddSymbolToMarketWatch(string symbol)

  {

   int      total=0; // Number of symbols

   string   name=""; // Symbol name

//--- If an empty string is passed, return the empty string

   if(symbol=="")

      return(empty_symbol);

//--- Total symbols on the server

   total=SymbolsTotal(false);

//--- Iterate over the entire list of symbols

   for(int i=0;i<total;i++)

     {

      //--- Symbol name on the server

      name=SymbolName(i,false);

      //--- If this symbol is available,

      if(name==symbol)

        {

         //--- add it to the Market Watch window and

         SymbolSelect(name,true);

         //--- return its name

         return(name);

        }

     }

//--- If this symbol is not available, return the string representing the lack of the symbol

   return(empty_symbol);

  } 

why do this happen?

 

Thanks 

 
reza_21:

Hi,

 

I want to add a symbol to MarketWatch to do some stuff later on. when I run my code, I get  "Specified symbol is not selected".

But when I first add a symbol in MarketWatch manually (any symbol) and then run the code, whatever symbol selected in the code will be added to the market watch.

here is the code: 

 

<REMOVED>

Please use the SRC button to post code . . .
 
RaptorUK:
Please use the SRC button to post code . . .
done
 
reza_21:
done
 
reza_21:

Hi,

 

I want to add a symbol to MarketWatch to do some stuff later on. when I run my code, I get  "Specified symbol is not selected".

But when I first add a symbol in MarketWatch manually (any symbol) and then run the code, whatever symbol selected in the code will be added to the market watch.

why do this happen?

 

Thanks 

Hi, your test procedures and explanations are not very clear to me, for instance:

1) Do you really change this line right before a test?

Change:
AddSymbolToMarketWatch("MySymbolName");

To (for example):
AddSymbolToMarketWatch("EURUSD");

 2) If you just want to activate a symbol and you can address it using SymbolSelec() as below, why you need a loop to check all the symbols?

if(SymbolSelect(name,true)) {
   ...
}

Note that it's important to check the SymbolSelect() return value (you don't do this in your code).

Anyway, if this is not enough to solve the problem, my suggestion is quite simple: put Print() after the main variables changes to check this code running step by step and please publish the report here.

 
good