Loop on stocks from Market Watcher
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);
Hello folks
I need to loop over all stocks in my Market Watch, so I tried, in order to get all the symbols names:
and further I tried to add an indicator handler to each entry, so:
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.