Download MetaTrader 5
To add comments, please log in or register
Any questions regarding MQL5 Cloud Network? FAQ will help you!
Carl Schreiber
5938
Carl Schreiber 2016.05.15 17:09 

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?)

whroeder1
13602
whroeder1 2016.05.15 17:48  
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.
Carl Schreiber
5938
Carl Schreiber 2016.05.15 17:50  
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..
Fernando Carreiro
1439
Fernando Carreiro 2016.05.15 17:56  

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.

Fernando Carreiro
1439
Fernando Carreiro 2016.05.15 18:34  

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()"

Carl Schreiber
5938
Carl Schreiber 2016.05.16 10:30  

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),
   }
}
Fernando Carreiro
1439
Fernando Carreiro 2016.05.16 11:02  
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()".

Demos Stogios
184
Demos Stogios 2016.05.16 13:30  
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 :)

Carl Schreiber
5938
Carl Schreiber 2016.05.16 15:04  
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.

/
To add comments, please log in or register