EA calling an indicator with iCustom() or IndicatorCreate()

 

Hi All,

I am trying to transition from MQL4 to MQL5, yet some things are still confusing me.

After having created a custom indicator I created a simple EA to just call it. Using both iCustom() and IndicatorCreate() there is no indicator output (I am using only buffers no objects in my indicator)  on my terminal. Having read older posts in forum I realized that this is standard behavior in MQL5 (at least for iCustom()).

1)Would there be a way to output the indicator output when being called from an EA?

2)What is the standard practice to see what an EA is doing when calling indicators? You manually add the indicators on the chart as well?

Any help much appreciated,

Thanks Leonidas

 
leon321:

I am trying to transition from MQL4 to MQL5, yet some things are still confusing me.

After having created a custom indicator I created a simple EA to just call it. Using both iCustom() and IndicatorCreate() there is no indicator output (I am using only buffers no objects in my indicator)  on my terminal. Having read older posts in forum I realized that this is standard behavior in MQL5 (at least for iCustom()).

1)Would there be a way to output the indicator output when being called from an EA?

2)What is the standard practice to see what an EA is doing when calling indicators? You manually add the indicators on the chart as well?

Both iCustom() and IndicatorCreate() should be called within the init function, and will initiate computation of the indicator. These functions only return a handle, not computation results.

1) When you need to get the computed values, you'll have to use CopyBuffer(). And to ensure the computation has been completed, it is useful to call BarsCalculated() first to check.

2) Yes, you add the indicator to the chart as well.

https://www.mql5.com/en/docs/series/copybuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
Counting of elements of copied data (indicator buffer with the index buffer_num) from the starting position is performed from the present to the past, i.e., starting position of 0 means the current bar (indicator value for the current bar). When copying the yet unknown amount of data, it is recommended to use a dynamic array as a buffer[]...
 

Thanks Seng,

Not really what i am looking for. I know how to retrieve the values form the indicator and use them in my EA logic. What i can't find is how to make my EA plot the indicator that i am calling.

 
leon321:

Thanks Seng,

Not really what i am looking for. I know how to retrieve the values form the indicator and use them in my EA logic. What i can't find is how to make my EA plot the indicator that i am calling.

ChartIndicatorAdd().
 
leon321:

2)What is the standard practice to see what an EA is doing when calling indicators? You manually add the indicators on the chart as well?

Sometimes I do that when it's the expedient solution.

For example, if I am running an EA through the tester, and my EA isn't showing my custom indicator because I have:

TesterHideIndicators(true);

and I don't want to recompile, I will just add that indicator to Tester.tpl.

I also use @Alain Verleyen 's suggestion of ChartIndicatorAdd() if I want to show/hide an indicator by pushbutton.

 

So simple! Feel like an idiot. Not sure why i was only looking at functions like iCustom(), IndicatorCreate().

Thanks Alain!


Forum on trading, automated trading systems and testing trading strategies

EA calling an indicator with iCustom() or IndicatorCreate()

Anthony Garot, 2019.05.31 02:19

Sometimes I do that when it's the expedient solution.

For example, if I am running an EA through the tester, and my EA isn't showing my custom indicator because I have:

TesterHideIndicators(true);

and I don't want to recompile, I will just add that indicator to Tester.tpl.

I also use @Alain Verleyen 's suggestion of ChartIndicatorAdd() if I want to show/hide an indicator by pushbutton.

Haven't quit reached in the Tester functionality yet but this advice will come handy soon. Thanks Anthony.
Reason: