iCustom Function in MetaTrader 4 (MQL4 Language) Complete Guide

The iCustom Function in MQL4 is great for the inclusion of custom indicators in your Expert Advisor. It is also a good way to verify that an indicator works as it is supposed to do. Using the iCustom Function can help with backtesting certain so-called "sure-fire" systems and indicators that are found on forums. Your ability to use the iCustom Function can be incredibly useful in dictating your automated trading experience. This function can also help you understand whether an indicator is actually coded well, which is very good knowledge to have if or when you choose to create your own indicator.

Why the MQL4 iCustom Function Exists in the First Place

MQL4 has different functions that automatically act upon a set of parameters and there are some pre-set functions based on the most "popular" indicators and oscillators. The way the non-custom indicators are singled out is by the i[insert function] here. Here is a list of the recognized indicator function calls, iCustom does not apply to these functions.

iAC: Bill Williams' Accelerator/Decelerator oscillator

iAD: Accumulation/Distribution

iADX: Average Directional Movement Index

iAlligator: Alligator Indicator

iAO: Awesome Oscillator

iATR: Average True Range

iBearsPower: Bears Power Indicator

iBands: Bollinger Bands

iBandsOnArray: Bollinger Bands on an Array

iBullsPower: Bulls Power Indicator

iCCI: Commodity Channel Index Indicator

iCCIOnArray: Commodity Channel Index Indicator on an Array

iDeMarker: DeMarker Indicator

iEnvelopes: Envelopes Indicator

iEnvelopesOnArray: Envelopes Indicator on an Array

iForce: Force Index Indicator

iFractals: Fractors Indicator

iGator: Gator Oscillator

iIchimoku: Ichimoku Cloud Indicator

iBWMFI: Market Facilitation Index indicator

iMomentum: Momentum Indicator

iMomentumOnArray: Momentum Indicator on an Array

iMFI: Money Flow Index Oscillator

iMA: Moving Average

iMAOnArray: Moving Average on an Array

iOsMA: Moving Average of Oscillator indicator

iMACD: Moving Averages Convergence/Divergence indicator

iOBV: On Balance Volume indicator

iSAR: Parabolic SAR Indicator

iRSI: Relative Strength Indicator

iRSIOnArray: Relative Strength Indicator on an Array

iRVI: Relative Vigor Index indicator

iStdDev: Standard Deviation

iStdDevOnArray: Standard Deviation of an Array

iStochastic: Stochastic Oscillator

iWPR: Larry Williams' Percent Range

Any other indicator requires iCustom to be called in an Expert Advisor Program. It is a Function that is not explained very well, but within the context of a few examples, it will become very easy to understand. In fact, there is a case where the iCustom Function would not actually work.

The MQL4 iCustom Function Broken Down

The iCustom Function has several parameters inside of it and this is the way that it is presented in the manual by MetaQuotes.

It's a bit on the confusing side, especially with the '...' in the Function, which would seem to indicate that the Function has an indefinite number of parameters to fill and it is very difficult to know how to fill them. Here's an example of how to use iCustom.

What we first need is a custom indicator and we have one, it is called "RegularPivot". "RegularPivot" creates Support and Resistance Lines along with a Pivot Point. These Support and Resistance Lines are S1, S2, S3, Pivot Point, R1, R2, and R3.

The pre-initialization and initialization sections of the code will provide you with all of the information you need to extract the necessary parameters.

To call the "RegularPivot" indicator in the code, you need to do the following. It is broken down into parts.

double [Variable of Choice Name] =

iCustom(

For the Symbol, you have two options:

Symbol(), which means the symbol upon which chart the Expert Advisor is applied. This means that it can work for any symbol as long as it is applied to the particular chart. It can be used for USDJPY, EURUSD, GBPCHF, etc. It is currency pair/CFD/indice agnostic.

A specific symbol. "EURUSD", "USDJPY","JP225USD", etc. You can only choose one at a time.

The Timeframe you want this to apply, you have two options:

"0" - Whatever the chart timeframe may be or the Strategy Tester setting is as far as timeframe.

A specific timeframe for your chart. PERIOD_D1, PERIOD_H1, PERIOD_M1, etc. are just examples.

The exact name of your timeframe in quotes. "RegularPivot"

The Line Buffer, which is where you look at the number associated with the particular line. Sometimes, it is made easy and other times, it is a bit more difficult to determine. Look at the indicator in question and find the applicable SetIndexBuffer number for the characteristic. This particular indicator made it easy.

The Bar Shift. The current candle is 0, the candle that came before it is 1, the candle that came before the candle that came before the current is 2 and it goes on from there.

Those that wish to call "RegularPivot" for any currency pair from the prior candle on a 1 Hour Chart as it relates to the 2nd Support Level would simply do this.

Generally speaking, most of the time the iCustom Function will be called like the way it is presented here. This is the most basic way to call an indicator in an Expert Advisor. However, it can get more specific based on the inputs.

How can one customize these extra inputs that could be very useful in the Expert Advisor beyond what is standard in the most basic structure? Go in order from top-to-bottom and include ALL of these inputs. If a coder wishes to use one of the inputs, the coder must include all of them, even if it is a default value. It would resemble something that looks like this for "RegularPivot" if one wanted to apply it to an Expert Advisor for AUDJPY for a 1 Hour Period that would trigger two candles prior and

It is a matter of just inserting the desired numbers or criteria that is expected in the inputs that change how the indicator functions rather than how the particular indicator fits within the goals of the Expert Advisor. The StartHour, StartMinute, and DaysToPlot would change how the actual indicator behaves and perceives Support and Resistance Lines. If the default settings work for the Expert Advisor, then these extra parameters are not needed to be added.

However, think of it like a sandwich. The standard parts are the bread, they are on the outside and they could apply to ANY indicators. These extra parameter inputs that were placed in bold above are the inputs that are totally unique to the indicator, they are the meat, dressing, cheese and condiments to the sandwich.

However, there are some indicators that do not behave this way. In fact, it would result in a very frustrating experience filled with backtesting and forward testing experiences that do not make much sense. After all, what does one do with code that looks like this?

This is not going to work with the iCustom model explained and it will act irrationally. How does one make use of such an indicator? That's for next Tuesday's article. Try to see what happens in a backtest when running the above code in the fashion learned in this article, it is going to not result very well. To get the desired result with this particular indicator, it requires a different function because you will be looking to have the Expert Advisor take action when the price does or does not do something within the parameters created. It's a different sort of a code that is more object-heavy rather than a mere calculation.

Term Deposit Comparison

Risk Disclosure

This site is not intended for U.S. citizens and residents. Using it means you agree to our Terms of Use page.

All investments involve risks, including possible loss of principal. Generally, those offering potential for higher returns are accompanied by a higher degree of risk. Forex Trading involves significant risk to your invested capital. Performance of the signals and portfolios may vary significantly. The use of leverage in trading poses additional risks to traders as it implies an additional loss due to possible non-fulfillment of their obligations to the creditor. Before starting to trade with signals, clients should make an independent judgment as to whether trading is appropriate for them in the light of their financial condition, investment experience, risk tolerance and other factors. Please read the risk notice associated with Forex Trading and signals in general.