Using a custom indicator in an EA

 

I have several custom indicators that I like.  They all work great when attached to a chart and do the job they were intended to...

I am new to the world of creating an Expert Advisor, I now want to build my own EA that trades the world based on my selection of custom indicators. 

So... How do I access the signals from my custom indicators within my EA?  Do I include them, if so how?  Do I rewrite the code in the EA? (No, I don't think so).  Is there some way of referring to the custom indicator's signals from within the EA?

Can anyone please tell me in CONCEPT how this is done or, if not, perhaps point me in the right direction within the massive library of documentation we have within MT4/5?

I love you guys! - Many thanks in advance :)

 
icuucme:

I have several custom indicators that I like.  They all work great when attached to a chart and do the job they were intended to...

I am new to the world of creating an Expert Advisor, I now want to build my own EA that trades the world based on my selection of custom indicators. 

So... How do I access the signals from my custom indicators within my EA?  Do I include them, if so how?  Do I rewrite the code in the EA? (No, I don't think so).  Is there some way of referring to the custom indicator's signals from within the EA?

Can anyone please tell me in CONCEPT how this is done or, if not, perhaps point me in the right direction within the massive library of documentation we have within MT4/5?

I love you guys! - Many thanks in advance :)

Use the iCustom function. it is in the documentation https://www.mql5.com/en/docs/indicators/icustom

Essentially, you tell the iCustom function where the custom indicator is,  what symbol, the timeframe, and the input parameters. Go through the documentation, write some code and see how it works. It really is pretty easy to do.

Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
Technical Indicators / iCustom - Reference on algorithmic/automated trading language for MetaTrader 5
 
CappinJack:

Use the iCustom function. it is in the documentation https://www.mql5.com/en/docs/indicators/icustom

Essentially, you tell the iCustom function where the custom indicator is,  what symbol, the timeframe, and the input parameters. Go through the documentation, write some code and see how it works. It really is pretty easy to do.

CappinJack -

You are a gentleman Sir, thank you! :)

I had seen the i{nameofindicator) functions (all 37 of them) but missed the iCustomfunction... Thank you.

 

Hi,

I would like to ask a question related with the topic.


A quote from the reference:

Indicators that require testing are defined automatically from the call of the iCustom() function, if the corresponding parameter is set through a constant string.
For all other cases (use of the IndicatorCreate() function or use of a non-constant string in the parameter that sets the indicator name) the property #property tester_indicator is required.


I thought that these statements are referring to the drawing of the custom indicators in the visulization mode when testing an EA.

But, when I call a custom indicator with the IndicatorCreate() within an EA, I still can see the drawing of the indicator in the visualization mode without the indicated #property.

So, my original assumption proved to be wrong.

What are the above statements referring to?

Thanks a lot.

 
kemalturgay:

Hi,

I would like to ask a question related with the topic.


A quote from the reference:


I thought that these statements are referring to the drawing of the custom indicators in the visulization mode when testing an EA.

But, when I call a custom indicator with the IndicatorCreate() within an EA, I still can see the drawing of the indicator in the visualization mode without the indicated #property.

So, my original assumption proved to be wrong.

What are the above statements referring to?

Thanks a lot.

It doesn't depend of the method used (iCustom or IndicatorCreate) but on the way you are specifying the name of the indicator :

if the corresponding parameter is set through a constant string.
iCustom(....,"MyIndicator",...;

or 

const string indiname="MyIndicator";
iCustom(...,indiname,...);

are constant string.

string indiname;

indiname="MyIndi1";

iCustom(...,indiname,...);
is not constant, so you need to use #property tester_indicator
 
angevoyageur:

It doesn't depend of the method used (iCustom or IndicatorCreate) but on the way you are specifying the name of the indicator.

I see ... thanks for the examples.

 
Alain Verleyen:

It doesn't depend of the method used (iCustom or IndicatorCreate) but on the way you are specifying the name of the indicator :

are constant string.

is not constant, so you need to use #property tester_indicator

Hi, I try to write an EA that let users input their custom indicators and optimize parameters. So in my case the name of the indicator will be different each time, same for the number of parameters.


int iCustomArray(string symbol, ENUM_TIMEFRAMES timeframe, string indicator, double &params[]){
   int len = ArraySize(params);
   const string indicator_const = indicator;
   if(len == 0){
      return iCustom(symbol, timeframe, indicator_const);   
   }
   else if(len == 1){
      return iCustom(symbol, timeframe, indicator_const, params[0]);
   }
   else if(len == 2){
      return iCustom(symbol, timeframe, indicator_const, params[0], params[1]);   
   }
   else if(len == 3){
      return iCustom(symbol, timeframe, indicator_const, params[0], params[1], params[2]);   
   }
   else if(len == 4){
      return iCustom(symbol, timeframe, indicator_const, params[0], params[1], params[2], params[3]);   
   }
   return 0;
}

int OnInit(){
   double arr[];
   int handle = iCustomArray(Symbol(), PERIOD_CURRENT, "aroonMTF", arr);
   return(INIT_SUCCEEDED);
}

When i run this, it logs this:

2020.06.08 17:10:33.040 program file Experts\Advisors\aroonMTF.ex5 read error
2020.06.08 17:10:33.041 program file added: Indicators\aroonMTF.ex5. 44181 bytes loaded

I have an error, but the indicator is still loaded, I don't know if this error is critical for the rest of my EA to behave as it should.

I welcome any thoughts on this, thank you.

 
turfu22:

Hi, I try to write an EA that let users input their custom indicators and optimize parameters. So in my case the name of the indicator will be different each time, same for the number of parameters.


When i run this, it logs this:

I have an error, but the indicator is still loaded, I don't know if this error is critical for the rest of my EA to behave as it should.

I welcome any thoughts on this, thank you.

Not sure what this error is, but it's a problem for sure.
Reason: