Download MetaTrader 5

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

To add comments, please log in or register
The entire MQL5.community history on a single page!
tao zemin.
402
tao zemin. 2014.04.02 02:42 
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());
       }
    }
  }
}
Alain Verleyen
Moderator
30775
Alain Verleyen 2014.04.02 09:44  
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.

tao zemin.
402
tao zemin. 2014.04.02 12:48  
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!

To add comments, please log in or register