SymbolSelect(SYM,false) - isn't it working - or do I do something wrong?

 

I have written a loop within a script to get some symbol spec.s:

void OnStart()  {
   int nSym = SymbolsTotal(false);
   while(--nSym>=0 && !IsStopped() ) {
      ResetLastError(); 
      SYM = SymbolName(nSym,false);
      sel = SymbolSelect(SYM,true);
      Prc = iClose(SYM,PERIOD_MN1,0);
      while ( _LastError == 4066 && !IsStopped() ) { 
         Sleep(1000); 
         ResetLastError();
         Prc = iClose(SYM,PERIOD_MN1,0);
      }
      //  ....
      sel = SymbolSelect(SYM,false); // <= Always: Error 4220 ERR_SYMBOL_SELECT  Symbol select error
   }
}

Firstly I bring the symbol in the MarketWatch (SymbolSelect(SYM,true)).

And as I start from the end of the list of symbols it ( ZURN.Z ) is NOT opened in any chart of the terminal.

Anyway now it is in the MarketWatch and with the last line I want to get rid of it again - but I continuously fail with Error 4220 and the symbol remains in the MarketWatch

The doc tells me:

If the value is false, a symbol should be removed from MarketWatch,
otherwise a symbol should be selected in this window. A symbol can't be 
removed if the symbol chart is open, or there are open orders for this symbol.

Despite no chart, no open order?

Anybody with an idea how this might work except manually (for what do I have a computer, if I have to do manually anyway?)

 
gooly: Despite no chart, no open order?
Last line of SymbolSelect - Market Info - MQL4 Reference
The symbol can be hidden from MarketWatch after 10 minutes since the last access to the symbol history, i.e. since the call of functions like iOpen(), iHigh(), CopyTime() etc. This is due to the fact that the terminal stores symbol data for 10 minutes since the last access to them; after that unused data are automatically deleted from the terminal memory.
 
WHRoeder:
gooly: Despite no chart, no open order?
Last line of SymbolSelect - Market Info - MQL4 Reference
The symbol can be hidden from MarketWatch after 10 minutes since the last access to the symbol history, i.e.since the call of functions like iOpen(), iHigh(), CopyTime()etc. This is due to the fact that the terminal stores symbol data for10 minutes since the last access to them; after that unused data areautomatically deleted from the terminal memory.

Ah!! ok - thank you very much - now I have found it the editor's reference, I didn't read that far..
 

In a recent thread about Multi-Currency Indicators, I did a test with "ArrayCopyRates()", in which there was a delay (with corresponding error 4073) before data becomes available. Error 4066 is only presented when there is already data, but just slightly out of sync.

In your code, you are not testing for this, and so I deduce, that maybe you CANNOT remove the symbol, because MetaTrader is still downloading the data when you try to remove it. In other words, the "iClose()" initiates the process, but since you don't check for error 4073 (and thus do not wait for it to complete the download), you immediately request the removal but the operation is still underway and thus blocks its removal with error 4220.

Test this theory out in your code just to make sure this is not the case! Have your "while" loop test for both errors 4066 and 4073.

 

I have just done some testing and discovered that the Problem is neither the error 4073 nor the 10min rule!

What is blocking the operation is the Script Stack or Environment itself. In other words, while running the script, it is the script itself that is "holding" the symbol and will not let it go.

Upon completion, I then run a script that does nothing more than just "deselecting" the symbols (namely "sel = SymbolSelect(SYM,false);") and it then works with no errors and the symbols are indeed removed from the MarketWatch.

What is need now, is to find a way to "release" it within the script itself, so that you don't need to run a second script to remove the symbols.

EDIT: @gooly: If your intention is to just get the Price data for a symbol, and not necessarily add them to the MarketWatch, then you can still get it even if you don't add it to the MarketWatch. Just ignore the "SymbolSelect()" altogether by not using it. You will still be able to obtain the Price data with the rest of your code.

EDIT: Incidentally, it seems that Error 4073 only occurs with "ArrayCopyRates()" and not with any of the "iFunctions()"

 

Well to get the specs. you don't need to load the symbol in the MarketWatch (my script, a bit crippled):

double Prc, Atr;
string SYM;


void OnStart()  {
   int nSop = SymbolsTotal(true),
       nScl = SymbolsTotal(false),
       cnt;
   
   while( --nSop>=0 && !IsStopped() ) {
      ResetLastError(); 
      SYM = SymbolName(nSop,true);
      Comment("# ",nSop," ",SYM,"  ..");
      Prc = iClose(SYM,PERIOD_D1,18);
      Atr = iATR(SYM,PERIOD_D1,10,0);
      cnt = 0;
      while ( (_LastError == 4066 || Prc*Atr < 0.0000000000000001) && !IsStopped() && cnt++ < 20 ) {
         Comment("# ",nSop," ",SYM,"  Prc: ",DoubleToString(Prc,5),"  Atr: ",DoubleToString(Atr,5),"   waiting for quotes .. ",cnt);
         Sleep(1000); 
         ResetLastError();
         Prc = iClose(SYM,PERIOD_D1,18);
         Atr = iATR(SYM,PERIOD_D1,10,0);
      }
      //if (Prc*Atr < 0.0000000000000001) && cnt>20) continue;
      Comment("# ",nSop," ",SYM,"  Prc: ",DoubleToString(Prc,5),"  Atr: ",DoubleToString(Atr,5),"   ok: ",cnt);
   }

   
   while( --nScl>=0 && !IsStopped() ) {
      ResetLastError(); 
      SYM = SymbolName(nScl,false);
      Comment("# ",nScl," ",SYM,"  ..");
      Prc = iClose(SYM,PERIOD_D1,18);
      Atr = iATR(SYM,PERIOD_D1,10,0);
      cnt = 0;
      while ( (_LastError == 4066 || Prc*Atr< 0.0000000000000001) && !IsStopped() && cnt++ < 20 ) {
         Comment("# ",nScl," ",SYM,"  Prc: ",DoubleToString(Prc,5),"  Atr: ",DoubleToString(Atr,5),"   waiting for quotes .. ",cnt);
         Sleep(1000); 
         ResetLastError();
         Prc = iClose(SYM,PERIOD_D1,18);
         Atr = iATR(SYM,PERIOD_D1,10,0);
      }
      //if (Prc*Atr < 0.0000000000000001) && cnt>20) continue;
      Comment("# ",nScl," ",SYM,"  Prc: ",DoubleToString(Prc,5),"  Atr: ",DoubleToString(Atr,5),
   }
}
 
gooly:

Well to get the specs. you don't need to load the symbol in the MarketWatch (my script, a bit crippled):

Just a suggestion:

If you use a "do ... while" loop instead of a "while ..." loop, you don't have to repeat the "iClose()" and "iATR()" statements twice. Also, since you are using a Counter, you can then you use a "for ..." loop instead. Currently you have "iClose()" and "iATR()" statements before and in the loop, but with a "do ... while" or "for ..." loop, they just have to appear once inside the loop. Just remember to add an extra "if" before executing the "Sleep()".

 
FMIC:

Just a suggestion:

If you use a "do ... while" loop instead of a "while ..." loop, you don't have to repeat the "iClose()" and "iATR()" statements twice. Also, since you are using a Counter, you can then you use a "for ..." loop instead. Currently you have "iClose()" and "iATR()" statements before and in the loop, but with a "do ... while" or "for ..." loop, they just have to appear once inside the loop. Just remember to add an extra "if" before executing the "Sleep()".



gooly
:

Well to get the specs. you don't need to load the symbol in the MarketWatch (my script, a bit crippled):

Prc*Atr < 0.0000000000000001

may i ask what is it all about ^ ^. Also, if you ask me, i also like whiles rather than do while or for loops :)

 
Prc*Atr < 0.0000000000000001

The terminal does not wait (thread-race) for all the information being downloaded and error 4066 is not always correct and as long as the prices aren't available at least one of them is 0.

while() instead of do .. while() is still a habit from 'once upon a time' do .. while() didn't exist.

 

I am a beginner in MQL4 and I have read very carefully this topic about SymbolSelect (SYM, false) since I have the same problem with one of my scripts. In my case I intend to obtain the specification of the digits of one symbol. I have been able to see that with Digits () statement I can get the specification of the symbol on the chart which the script is executed. As there is no “iDigits” function, so in order to obtain the specification of the digits of a symbol presents in Market Watch I can use the MarketInfo (SYM, MODE_DIGITS) function, but this function is only effective on symbols present in Market Watch, therefore to obtain digits of any other symbol it must be previously selected by using SymbolSelect (SYM, true) and logically the symbol should be deleted from Market Watch window once obtained this parameter. But then you find the problem pointed to in topic by Carl Schreiber.

Any idea how to solve the problem related to SymbolSelect (SYM, false) or how to get digits information of a symbol not present in Market Watch without using SymbolSelect (SYM, true) previously?

This is my very simple current code:


dgts=MarketInfo(symbName,MODE_DIGITS);
if (GetLastError()>0){
   //SYM is not on Market Watch
   SymbolSelect(SYM,true);
   dgts==MarketInfo(symbName,MODE_DIGITS);
   SymbolSelect(SYM,false);
   }
 
dgts=MarketInfo(symbName,MODE_DIGITS);
if (GetLastError()>0){
   //SYM is not on Market Watch
   SymbolSelect(SYM,true);
   dgts==MarketInfo(symbName,MODE_DIGITS);
   SymbolSelect(SYM,false);

   }

What is symbName and what is SYM.

Why are you mixing them?