parameters of indicators handle change in OnTick() in MT5, how to assign the handle in OnInit()

 
I have been always told the indicator handle should be assigned in the OnInit() in MT5, however if the indicator parameters will be changed in the OnTick(), for example indicators MA 's period will be varied in the OnTick(), how to address this problem.
 
Lei Zhu: I have been always told the indicator handle should be assigned in the OnInit() in MT5, however if the indicator parameters will be changed in the OnTick(), for example indicators MA 's period will be varied in the OnTick(), how to address this problem.

Release the handle and reassign it with new parameters, but only do it when parameters need to change.

Also, remember that every time you do it the entire indicator has to be recalculated and there will be a delay before you can use CopyBuffer to access the data.

The delay in recalculating an indicator is one of the reasons (but not the only one) why it is best to assign the indicator handles during OnInit() for what you need and not keep changing parameters on the go.

 
Lei Zhu:
I have been always told the indicator handle should be assigned in the OnInit() in MT5, however if the indicator parameters will be changed in the OnTick(), for example indicators MA 's period will be varied in the OnTick(), how to address this problem.

Will the parameters be changed or will you be using more than 1 MA?

Create a handle for each MA in OnInit ie. Handle MA100,   Handle MA200,   Handle MA300.

 
Lei Zhu: however if the indicator parameters will be changed in the OnTick(),

Why are they changing? How?
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

 

The experts need to varied parameters , for instance the programs calculate the suitable MA period to further process, to adapt the varied purposes, when I prepared the coding, the specific parameters are unknown. Therefore for example, I don't which specific MA periods will be generated in the programs, perhaps hundreds possibles, EA will get the specific MA period value in the actual running time.

@Fernando Carreiro  Thank you for feedback , also  I noted that the MQL 5 HELP document reads "When working in the strategy tester, the IndicatorRelease() function is not executed"

In addition, the charts will overlap in the testing if Experts will redefine handle in OnTick() part, you used to reply me about this question.

Is there the other perfect solution for this?

 
Lei Zhu #: The experts need to varied parameters , for instance the programs calculate the suitable MA period to further process, to adapt the varied purposes, when I prepared the coding, the specific parameters are unknown. Therefore for example, I don't which specific MA periods will be generated in the programs, perhaps hundreds possibles, EA will get the specific MA period value in the actual running time. @Fernando Carreiro  Thank you for feedback , also  I noted that the MQL 5 HELP document reads "When working in the strategy tester, the IndicatorRelease() function is not executed". In addition, the charts will overlap in the testing if Experts will redefine handle in OnTick() part, you used to reply me about this question. Is there the other perfect solution for this?

When your EA needs to adapt and adjust parameters, then select Indicator calculations that are adaptable, preferably methods where calculations are incremental, and choose one of the following options:

  • Create a Custom Indicator that carries out those parameter adjustments internally and incrementally without needing to recalculate everything, so that you only need to initialise it once in the EA.
  • Transfer the indicator calculations to the EA, so that you don't need to use the indicator at all.
Both the above options resolve the Strategy Tester issue where multiple indicators overlap and overload the system.
 
Fernando Carreiro #:

When your EA needs to adapt and adjust parameters, then select Indicator calculations that are adaptable, preferably methods where calculations are incremental, and choose one of the following options:

  • Create a Custom Indicator that carries out those parameter adjustments internally and incrementally without needing to recalculate everything, so that you only need to initialise it once in the EA.
  • Transfer the indicator calculations to the EA, so that you don't need to use the indicator at all.
Both the above options resolve the Strategy Tester issue where multiple indicators overlap and overload the system.

Thank you for reply.

However the point is the parameters of indicator which generate the results that is interim result. For example, in the 1st tick indicator need one set parameters which is came out a series calculation , the indicator will generate  one value, that value still need to further process..., in the  5 minutes later, the indicator need another set parameters which is also came out a series calculation will generate  one value, that value still need to further process... In this case, indicators need the parameters are depend on program, parameter is varied randomly as much like market fluctuation. 

 
Lei Zhu #: However the point is the parameters of indicator which generate the results that is interim result. For example, in the 1st tick indicator need one set parameters which is came out a series calculation , the indicator will generate  one value, that value still need to further process..., in the  5 minutes later, the indicator need another set parameters which is also came out a series calculation will generate  one value, that value still need to further process... In this case, indicators need the parameters are depend on program, parameter is varied randomly as much like market fluctuation. 

Then redesign your indicator and your EA to properly account for that. Constantly reinitialising indicators and recalculating them is highly inefficient and will cause problems in the Strategy Tester.

You have a design issue, not a codding issue. Return to the drawing board.

 
Fernando Carreiro #:

Then redesign your indicator and your EA to properly account for that. Constantly reinitialising indicators and recalculating them is highly inefficient and will cause problems in the Strategy Tester.

You have a design issue, not a codding issue. Return to the drawing board.

Right, return to the drawing board to redesign program to adapt the MQL5 language requirement.