SymbolSelect(symName,false)always failed with error 4305,what is wrong?

 
Dear all,
  I use the following simple script to remove the currency pair with bid price<1.0 from the market watch.I notieced that during debug, Each time SymbolSelect(SymbolName, false) is called, it fails with error #4305. What's wrong with my code? Many thanks for your help.
void OnStart(){
  int SymCntinMarketWatch=0, AllSymCnt=0;
  double bid=0.0;

  AllSymCnt=SymbolsTotal(true);
  for(int i=AllSymCnt-1;i>=0;i--){
    string sym=SymbolName(i,true);
    //Alert("Sym=",sym," Bid=",SymbolInfoDouble(sym,SYMBOL_BID));
    
    CSymbolInfo SYM;
    SYM.Name(sym);
    SYM.RefreshRates();
    bid=NormalizeDouble(SYM.Bid(),SYM.Digits());
    if(bid<1.0){
       if(!SymbolSelect(sym,false))
       {
         Alert("SymbolSelect",sym," failed() #",GetLastError());
       }
    }
  }
}
 
taozemin:
Dear all,
  I use the following simple script to remove the currency pair with bid price<1.0 from the market watch.I notieced that during debug, Each time SymbolSelect(SymbolName, false) is called, it fails with error #4305. What's wrong with my code? Many thanks for your help.

Your code is working well. But did you read the documentation of SymbolSelect() ?

A symbol can't be removed if the symbol chart is open, or there are open positions for this symbol.

 
angevoyageur:

Your code is working well. But did you read the documentation of SymbolSelect() ?

Dear angevoyageur,

  thank you for your concern this problem has been successfully solved after I closed all the open positions. I did read the related document before, but i havenot paid attention to the last sentence at that time.

Thank you for your kind help again!

Reason: