How To Use Our Indicators In Your EAs 8

Salve a tutti,

in the past weeks we’ve been asked a few times on how to embedd our indicators into custom EAs.

Well, it’s quite simple.

MQL4 (the programming language of MT4) let you do that by using the “iCustom” function. It calculates the specified custom indicator and returns its value. The custom indicator must be compiled (*.EX4 file) and be in the “YOUR_MT4\experts\indicators” directory.

Here’s how the function is called:

iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)

The parameters are:

  • symbol – Is the symbol the data of which should be used to calculate indicator. NULL (or 0 or “Symbol()”) means the current symbol.
  • timeframe – It can be any of  timeframe value. 0 means the current chart timeframe.
  • name – Is the name of the indicator compiled program name. The name must be exaclty the name of the file without the “.ex4″.
  • – Indicator’s parameters set (optional). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator. It is very important that the order is exact and pay attention to it.
  • mode – Is the line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions (more on that later).
  • shift – Is the shift relative to the current bar the given amount of periods ago.

OK, it may seems difficult but let’s do an example with the PotenzaFX Powerlines indicator.

The PotenzaXF Powerlines is made of 8 lines (1 for each currency) so we use all the 8 possible buffers (see “mode” parameter above) that in MT4 and indicator can use.

Each buffer corresponds to a currency:

0 – AUD
1 – CAD
2 – CHF
3 – EUR
4 – GBP
5 – JPY
6 – NZD
7 – USD

If we apply the indicator to a EURUSD chart it’ll by default calculates the value of buffer 3 (EUR) and buffer 7 (USD)… only.

So if you apply it to a EURUSD chart and want to know the scores of EUR and USD for the current bar, in your EAs you should write something like:

double euro_value = iCustom(Symbol(),0,"PotenzaFX_Powerlines",3,0); // 3 for EUR
double usd_value = iCustom(Symbol(),0,"PotenzaFX_Powerlines",7,0); // 7 for USD

if you want it for the previous bar:

double euro_value = iCustom(Symbol(),0,"PotenzaFX_Powerlines",3,1); // 3 for EUR
double usd_value = iCustom(Symbol(),0,"PotenzaFX_Powerlines",7,1); // 7 for USD

We use “1” for the shift for the previous bar, that is also the first closed bar.

Now let’s say that you want to know the scores forALL the 8 currencies. By default the PotenzaFX Powelines only calculates it for the two of the chart it is applied to. If you want all 8 you have to set “”show_all” to true. How we do that? We have to set all the parameters in the “iCustom” up to the “show_all” one.

So we can use a for cicle to populate an array with all the scores like:

for (int i = 0; i < 8; i++){
	scores[i] = iCustom(Symbol(),0,"PotenzaFX_Powerlines","",2,true,20,1,true,i,0);
	previous_scores[i] = iCustom(Symbol(),0,"PotenzaFX_Powerlines","",2,true,20,1,true,i,1);

that way we have the actual score for each of the 8 currencies in the scores[] array, and the previous bar (first closed) score in the previous_score[] one.

As you can see we had to set a value for each of the parameters up to the ones we are interested too (the last “true” of the iCustom). We can do that for ALL the PotenzaFX Powerlines parameters, like the “algo”, the “period”, etc. To avoid unwanted graphical object I suggest you to set “show_labels” and “show_entry_signals” to false.

By using the iCustom function with PotenzaFX Powerlines you can “only” have any or all of the 8 scores. If you want to know the correlation score you need to use the PotenzaFX Correlations indicator.

One note… you don’t need to apply the PotenzaFX Powerlines indicator to the chart. The “iCustom” function does take the value it needs by itself.

You can use that procedure for your EAs, scipts or even other indicators.

This is exactly the same procedure we used in developing the coming “PotenzaFX DLS Trader EA“.

Please let us know if you are interested in that kind of post as we may write more about that (and EA/Indicators programming in general). Sincerely I don’t know how many of you are interested in programming so I need some feedback from you… in any case, we are here to help you 😉

If you are not programmer but want to use our indicators to develop something, feel free to contact us. We are quite busy but we usually try to do out best to help you.

A presto,

Leave a comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

8 thoughts on “How To Use Our Indicators In Your EAs

  • Enrico

    Ciao Andrea, Paolo…

    awesome! If you guys could start a programming course I’ll be in the first row! I did already programmed several indis but, as you know, learning is an addicting and never ending experience.

    Your advices will be really appreciated!



    • Andrea Post author

      Ciao Enrico,
      good to know. I think we love programming as much as trading. Doing both things together is perfect for us.
      Maybe we won’t start a real programming course but we’d like to teach some of the tricks that we’ve learned in years.
      Coding is usually the easiest part of the whole process but you have to learn a lot of things about how MT4 works to make it at best as it has a lot of “quirks” 😀
      Anyway… good to know you’re interested 😉

  • Brad


    I love programming but haven’t done much in MT4. This info is very interesting and useful and I hope you can spare the time for more.

    Keep up the good work.


  • Todd

    I would love to learn to write some EA’s. But I would have to take baby steps to understand. Do you know were one could find those steps for mtq4? Like programing for dummies?
    This might help with my flustrations. Like for an example the ea in mt4 platform basicmacd, this could work out desent if there was a stop loss.
    I am so looking forward to your new EA. I hope that the back test are going good for all are sake.
    I was curiouse what all little things you are going to put in so we won’t get whip lashed as win the market is going through a transition of change. It got me when they first came out following scale in and scale out. I learned just to hang on a little longer like when it goes from 1 to none I will still hold my position till there is a definite wrong trade.
    Pip On

  • bruno

    Hi Andrea, Hi Polo

    Took sometime to respond, but YES, this is just great stuff and being myself an it developer, it is something I really do appreciate, and very good added value to your indicators.

    This is a refreshing place to come because it is everything about serious education and the ‘no black box’ approach is really innovating on a commercial trading software blog.

    This is the right way and I wish you a growing success.

    • Andrea Post author

      Ciao Bruno,

      really thanks a lot!

      Yes we are trying to develop something new and make it public in a very different way. The only thing that we don’t give is the source code. Other than that everything is explained in great details. Those with programming skills can even do by themselves.

      But understanding in depth things is the only way to master them.