Download MetaTrader 5
To add comments, please log in or register
No time to learn MQL5? Order your application from a developer!
Pablo Rego
1195
Pablo Rego 2016.03.17 02:31 

Hello folks

I need to loop over all stocks in my Market Watch, so I tried, in order to get all the symbols names: 

int numberOfSymbols = SymbolsTotal(true);
string bSymbols[];
ArrayResize(bSymbols, numberOfSymbols);

for (int i=0; i< numberOfSymbols; i++){
   bSymbols[i] = SymbolName(i, true);      
}

and further I tried to add an indicator handler to each entry, so:

for (int iSym=0; iSym<numberOfSymbols; iSym++){
   string cSym = bSymbols[iSym];
   int t1Handle = iMA(cSym,MYTIMEFRAME,MYPERIOD,0,MODE_EMA,PRICE_CLOSE);
   double t1[];
   ArraySetAsSeries(t1, true);
   ArrayResize(t1, 3);

   if (CopyBuffer (t1Handle, 0, 0, 3, t1) <= 0){
      Print("Getting slow EMA is failed! Error ",GetLastError(), " ", cSym);
      return(0);
   }
}

But the error 4806 occurs in CopyBuffer call (why??).

Also, if I put _Symbol in the place of cSym in iMA definition, no error occurs. 

So, how can I fix this?

Thanks. 

Alain Verleyen
Moderator
28563
Alain Verleyen 2016.03.17 12:51  
  • Where are you checking that t1Handle is valid ?

Return Value

Returns the copied data count or -1 in case of an error.

  • Ideally the handle(s) should be initiated in OnInit() and CopyBuffer() used in OnTick() or OnTimer().
Pablo Rego
1195
Pablo Rego 2016.03.17 14:06  
Alain Verleyen:
  • Where are you checking that t1Handle is valid ?
  • Ideally the handle(s) should be initiated in OnInit() and CopyBuffer() used in OnTick() or OnTimer().

(I did this on the real code. This here is only an extract.) 

To clarify the question, the real problem is: how can I initialize an indicator using a string as the Symbol input parameter?

Because if I do this 

string cSym = "PETR4";
int t1Handle = iMA(cSym,MYTIMEFRAME,MYPERIOD,0,MODE_EMA,PRICE_CLOSE);
if (!t1Handle){
   Print("error on handle");
   return(-1);
}

double t1[];
ArraySetAsSeries(t1, true);
ArrayResize(t1, 3);

if (CopyBuffer (t1Handle, 0, 0, 3, t1) <= 0){
   Print("Getting slow EMA is failed! Error ",GetLastError(), " ", cSym);
   return(-1);
}

 

it will return error in CopyBuffer (the handler do not return error); 

/
To add comments, please log in or register