Use my own Indicator data in EA

 

Hi friends,

I want to know how can I use the data of the indicator that I developed it by myself in an EA.

Suppose that I've developed an indicator which it creates numerous arrays that are so important to be used in my EA and in other word, the arrays that are created through my indicator are the basic inputs for my EA.

Please be noted that my Indicator's code contains the "prev_calculated" and "rates_total" constants, so I can not copy my indicator's code into my EA. 

Thanking in advance for your kindness,

 
parham.trader:

Hi friends,

I want to know how can I use the data of the indicator that I developed it by myself in an EA.

Suppose that I've developed an indicator which it creates numerous arrays that are so important to be used in my EA and in other word, the arrays that are created through my indicator are the basic inputs for my EA.

Please be noted that my Indicator's code contains the "prev_calculated" and "rates_total" constants, so I can not copy my indicator's code into my EA. 

Thanking in advance for your kindness,

Please read the documentation on the iCustom() function which is used to retrieve the data from any custom indicator (be it yours or others). You may also need to refresh your knowledge by consulting the documentation with regards to Custom Indicators

Also read the section name Combined Use of Programs of the online Book which is about the iCustom() function and also contains some example code. However, please note that of some these examples use the old style of code, but you should try to apply the newer style which is explained in the section Updated MQL4 of the documentation.

 
parham.trader: so I can not copy my indicator's code into my EA.
Don't do that. Just get the value of the indicator. You should write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum
 
WHRoeder: Don't do that. Just get the value of the indicator. You should write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum

It might be wise to also inform the OP that in the link, the use of "." in the variable names, is no longer permitted. So, either replace with "_" or simply concatenate. So, as an example, instead of "StdDev.MA.Method" use "StdDev_MA_Method" or simply "StdDevMAMethod".

 
FMIC: It might be wise to also inform the OP that in the link, the use of "." in the variable names, is no longer permitted. So, either replace with "_" or simply concatenate. So, as an example, instead of "StdDev.MA.Method" use "StdDev_MA_Method" or simply "StdDevMAMethod".
Comment added that thread.
 
FMIC:

Please read the documentation on the iCustom() function which is used to retrieve the data from any custom indicator (be it yours or others). You may also need to refresh your knowledge by consulting the documentation with regards to Custom Indicators

Also read the section name Combined Use of Programs of the online Book which is about the iCustom() function and also contains some example code. However, please note that of some these examples use the old style of code, but you should try to apply the newer style which is explained in the section Updated MQL4 of the documentation.

Thank you so much for your kind guidance, but I need to have some other variables and some arrays in my EA that are calculated by my Indicator and I think it is inconvenient to use iCustom() funtion because it only provides a single result but I need numerous information from my Indicator so I need to use loop to get them through iCustom() function and.... . Therefore I think the best way is to write my indicator in a .mqh file that is compatible with the EA environment and then I use it through #include and calling the indicator directly from EA. Isn't it correct ?

if I'm going in a wrong way, I'd appreciate if you kindly let me know about it.

Your kind advice is highly appreciated.

 
What part of "Don't do that. Just get the value of the indicator" was unclear? There are no buffers, IndicatorCounted/PreviouslyCalculated in EAs.
 
WHRoeder:
What part of "Don't do that. Just get the value of the indicator" was unclear? There are no buffers, IndicatorCounted/PreviouslyCalculated in EAs.

First of all I need to thank you for the time you dedicated to solve my problem, Then I think you just need to keep calm because I completely get what you've advised me on your previous comment! The case is that I didn't use any indicator buffers and instead I used other alternatives to it so that it can be easily adapted to the EAs. Therefore there would be no problem regarding the buffers.

Now about the prev_calculated and IndicatorCounted , I think there would be some other possible alternatives to them to use in the EAs so I'd be grateful if you can advise me on the substitute of the prev_calculated/IndicatorCounted in EAs.

Finally , about the differences between the solutions you mentioned in you previous comment and the use of #include that I mentioned in my comment, the main difficulty that you're aware is the computer resource usage in the use of #include, is that correct or there would be some other cautions that you're aware of ?

again thank you for your kind guidance, 

 
parham.trader:

First of all I need to thank you for the time you dedicated to solve my problem, Then I think you just need to keep calm because I completely get what you've advised me on your previous comment! The case is that I didn't use any indicator buffers and instead I used other alternatives to it so that it can be easily adapted to the EAs. Therefore there would be no problem regarding the buffers.

Now about the prev_calculated and IndicatorCounted , I think there would be some other possible alternatives to them to use in the EAs so I'd be grateful if you can advise me on the substitute of the prev_calculated/IndicatorCounted in EAs.

Finally , about the differences between the solutions you mentioned in you previous comment and the use of #include that I mentioned in my comment, the main difficulty that you're aware is the computer resource usage in the use of #include, is that correct or there would be some other cautions that you're aware of ?

again thank you for your kind guidance, 

In you first post, you stated that you were using "prev_calculated" and "rates_total", which implies that you were using buffers in your indicators, which is the correct way to implement it. The use of Graphical Chart Objects should be kept to a minimum and where possible, used for visual cues only and not for maintaining indicator values. Indicators are best implemented using "buffers" and its values referenced in an EA with the aid of the iCustom() function (in MQL4, because in MQL5, things are a little different).

There are underlying reasons to do it this way, because of the mechanisms in place, that make this the most efficient method, especially when structuring the use of iCustom() (e.g. the way mentioned by WHRoeder).

However, in your most recent post, you state that you are NOT using buffers, but an alternative method, putting into question why you even nonsensically mentioned "prev_calculated" and "rates_total" in the first place. If by premeditation, you have decided to implement your Indicator this way in order to facilitate the development of your EA with this alternative method, then there is little advice we can offer you, because:

  1. ... it is not the most efficient method,
  2. ... it is not the usual way to do it,
  3. ... you have taken an unsupported route (thus, leaving you very much to your own devices),
  4. ... you have not provided any code (so we cannot, even evaluate if such an alternative has merit or not).

So, for your next post, consider the following and make a decision on what route to take:

  1. You accept our guidance, and re-implement your code using buffers and iCustom(), thus scrapping your current design.
  2. You believe in your current design ...
    1. ... and present it as an alternative, showing your code and allow open debate about its pros/cons and possible merits.
    2. ... or you keep it to yourself, closing this discussion, and go about with your research and development by your own devices.
 

I don't believe that including the code in an EA instead of using an iCustom call would save any resources or at least not significantly.

I don't know exactly how an EA accesses an indicator's data, but I think that the indicator is running in the background, allowing the EA to access the buffers' values.

It could be argued that including the code in the EA to calculate indicator values may slow down that EA, possibly causing missed ticks?

 
FMIC:

In you first post, you stated that you were using "prev_calculated" and "rates_total", which implies that you were using buffers in your indicators, which is the correct way to implement it. The use of Graphical Chart Objects should be kept to a minimum and where possible, used for visual cues only and not for maintaining indicator values. Indicators are best implemented using "buffers" and its values referenced in an EA with the aid of the iCustom() function (in MQL4, because in MQL5, things are a little different).

There are underlying reasons to do it this way, because of the mechanisms in place, that make this the most efficient method, especially when structuring the use of iCustom() (e.g. the way mentioned by WHRoeder).

However, in your most recent post, you state that you are NOT using buffers, but an alternative method, putting into question why you even nonsensically mentioned "prev_calculated" and "rates_total" in the first place. If by premeditation, you have decided to implement your Indicator this way in order to facilitate the development of your EA with this alternative method, then there is little advice we can offer you, because:

  1. ... it is not the most efficient method,
  2. ... it is not the usual way to do it,
  3. ... you have taken an unsupported route (thus, leaving you very much to your own devices),
  4. ... you have not provided any code (so we cannot, even evaluate if such an alternative has merit or not).

So, for your next post, consider the following and make a decision on what route to take:

  1. You accept our guidance, and re-implement your code using buffers and iCustom(), thus scrapping your current design.
  2. You believe in your current design ...
    1. ... and present it as an alternative, showing your code and allow open debate about its pros/cons and possible merits.
    2. ... or you keep it to yourself, closing this discussion, and go about with your research and development by your own devices.

I do not know how can I thank you for your complete and clarifying response,

No problem, I'll re-write my code using buffers and then we can continue our discussion about the procedure of using it in an EA and distinguish them if it is possible. 

If I change my indicator design and use the buffers ,the very first problem I'll face with, which is also of a high importance, is the arrays that contain " Datetime " and " String " variables that I can not assign them to buffers but I need them in my EA. How can I overcome this issue ?