Download MetaTrader 5

how to update some variables in custom indicators from expert advisor

To add comments, please log in or register
zifu wang
636
zifu wang  
Is it possiable to update some variables in custom indicators from expert advisor? can you share some examples?
Step on New Rails: Custom Indicators in MQL5
  • 2009.11.23
  • Андрей
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
ChuckM
77
ChuckM  

My EA updates Global Variables with the threshold levels of the Stochastic Indicator it uses for trading.  Then my custom Stochastic Indicator reads these same Global Variables so it displays using the same parameters as the EA. 

Hope this helps...ChuckM

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events - Documentation on MQL5
zifu wang
636
zifu wang  
ChuckM:

My EA updates Global Variables with the threshold levels of the Stochastic Indicator it uses for trading.  Then my custom Stochastic Indicator reads these same Global Variables so it displays using the same parameters as the EA. 

Hope this helps...ChuckM

Yes, it should work by the way you metioned.

but best solution is that we can access the indicators just like accessing class objects which have a number of virtual methods.  

Handle of this indicator should be treated as pointer of the object. 

Is it possiable? 

Brett Luedtke
114
Brett Luedtke  

You create a static variable in your indicator's class file. This way the EA's parameters can be set and manipulated with a custom set of parameters, and the indicator reads the same static (unchanging) "handle" at that location. You can use the data parameters/settings and retrieved by accessing the returned pointer and reinitialize your indicator.

Hopefully this can solve your scenario.

Local variables can be declared with the access specifier static. In this case, the compiler has a variable in the global pool of memory. Therefore, the lifetime of a static variable is equal to the lifetime of the program. Here the scope of such a variable is limited to the block in which it is declared.

 https://www.mql5.com/en/docs/basis/variables/static

Documentation on MQL5: Language Basics / Variables / Static Variables
  • www.mql5.com
Language Basics / Variables / Static Variables - Documentation on MQL5
zifu wang
636
zifu wang  
Lugner:

You create a static variable in your indicator's class file. This way the EA's parameters can be set and manipulated with a custom set of parameters, and the indicator reads the same static (unchanging) "handle" at that location. You can use the data parameters/settings and retrieved by accessing the returned pointer and reinitialize your indicator.

Hopefully this can solve your scenario.

 https://www.mql5.com/en/docs/basis/variables/static

Lugner, 

Can you give an example for this? it will be easy to understand... thanks a lot. 

Brett Luedtke
114
Brett Luedtke  
kwang1:

Lugner, 

Can you give an example for this? it will be easy to understand... thanks a lot. 

It will be best if you give the situation you are trying to solve.
To add comments, please log in or register