iMa data in loop

 

Hello,


I have a iMa inside a loop, whitch opens symbols in the marketwatch. See below. The problem is that when there are many symbols in the marketwatch the script becomes unstable and slow. How can I fix this issue?


 for(int i=0; i< ArraySize(selectedSymbols); i++)

     {

     maHdl = iMA(selectedSymbols[i], PERIOD_D1, 64, 0, MODE_LWMA, PRICE_CLOSE);

     CopyBuffer(maHdl,0,0,7,maD1);

      IndicatorRelease(maHdl);

     Print("Getting data for: " + selectedSymbols[i]);

     }
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2.  maHdl = iMA(selectedSymbols[i], PERIOD_D1, 64, 0, MODE_LWMA, PRICE_CLOSE);
     CopyBuffer(maHdl,0,0,7,maD1);

    Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
              How to call indicators in MQL5 - MQL5 Articles 12 March 2010

  3. On MT5: Unless the chart is that specific pair/TF, you must synchronize the terminal Data from the Server before accessing candle/indicator values.
              Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum 2019.05.31
              Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
              Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum
              SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum 2019.09.03
              OnCalculate during weekend MT5 - General - MQL5 programming forum

 
It is a script I use, so I don’t have oninit. 
 
Wotikar: It is a script I use, so I don’t have oninit. 

Then you must wait and verify. Your code doesn't. Re-read the links in #1.3