MQL5 indics

 

Hello everyone


I start porting an MQL4 EA to MQL5.

It is a multipair EA, running 28. It uses 4 indicators.


For the use of these, is it better to create the handles once in OnInit () in a table 28X4 or is it possible to create them in OnTicks () on the fly before using them?


Will it create a multitude of different handles that will quickly block the PC?
 
stanislass:

I start porting an MQL4 EA to MQL5.

It is a multipair EA, running 28. It uses 4 indicators.

For the use of these, is it better to create the handles once in OnInit () in a table 28X4 or is it possible to create them in OnTicks () on the fly before using them?

Will it create a multitude of different handles that will quickly block the PC?

It is generally recommended to create indicator handles in OnInit of your EA.

Then within your OnTick, it's good practice to check whether those handles are ready, before proceeding:

   if(BarsCalculated(handle)<rates_total) return(0); 

On whether your PC will get blocked, that really depends on your PC's specs.

 
Seng Joo Thio:

It is generally recommended to create indicator handles in OnInit of your EA.

Then within your OnTick, it's good practice to check whether those handles are ready, before proceeding:

On whether your PC will get blocked, that really depends on your PC's specs.

if(BarsCalculated(handle)==0) return(0);   // or eventually <1000 or something depending of your needs

Comparing to rates_total with multiple pairs will lead to trouble.

 
Alain Verleyen:

Comparing to rates_total with multiple pairs will lead to trouble.

You're right. I copied that line from my codes without much thinking 😅.

And obviously handle should be <handle> since there'll be many different handles.

 


Yes you are right. In the end I do it in a table in OnInit (), and it's much easier to manage than I thought, since I already had the pointer (unused) in the MQL4 version!


I should think more before imagining things. :(


Another question. I copy only the last value of the indicators with CopyBuffer in 1-box arrays, am I forgetting to use ArraySetAsSeries since in fact there is no sense?


I try to make the code as fast as possible


Thank you and have a good weekend
 
stanislass:

Another question. I copy only the last value of the indicators with CopyBuffer in 1-box arrays, am I forgetting to use ArraySetAsSeries since in fact there is no sense?

The best thing about programming is that you can easily trial and error.

So whether you need to call ArraySetAsSeries or not for a 1 box array - you can easily try and see what's the output :).

 
Seng Joo Thio:

The best thing about programming is that you can easily trial and error.

So whether you need to call ArraySetAsSeries or not for a 1 box array - you can easily try and see what's the output :).

What you say is true and that's how I learned(a little).

Reason: