How does iCustom calculate value

 

From the technical documentation of iCustom 

https://docs.mql4.com/indicators/icustom


It is said that the return value is "Numerical value of the specified custom indicator

Returned value

Numerical value of the specified custom indicator. The custom indicator must be compiled (*.EX4 file) and be in the terminal_directory\MQL4\Indicators\ directory.

Example:

  double val=iCustom(NULL,0,"SampleInd",13,1,0);


However, i don't get what does it mean by "Numerical value of the specified custom indicator"

Consider the source code of this Aroon_Up_Down.mq4

//---- indicator settings

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Red

//---- indicator parameters
extern int AroonPeriod = 14;
extern bool MailAlert = false; //Alerts will be mailed to address set in MT4 options
extern bool SoundAlert = false; //Alerts will sound on indicator cross

//---- indicator buffers
double AroonUpBuffer[];
double AroonDnBuffer[];

int LastBars = 0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(4);
SetIndexBuffer(0, AroonUpBuffer);
SetIndexBuffer(1, AroonDnBuffer);

//---- drawing settings
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexDrawBegin(0,200);
SetIndexDrawBegin(1,200);
IndicatorDigits(1);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("Aroon Up & Dn("+AroonPeriod+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Aroon Up & Dn |
//+------------------------------------------------------------------+
int start()
{
double AroonUp,AroonDn;
int ArPer,limit,i;
int UpBarDif,DnBarDif;
int counted_bars=IndicatorCounted();
ArPer=AroonPeriod; //Short name
//---- check for possible errors
if(counted_bars<0) return(-1);
if(AroonPeriod<1) return(-1);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=ArPer;i++) AroonUpBuffer[Bars-i]=0.0;
for(i=1;i<=ArPer;i++) AroonDnBuffer[Bars-i]=0.0;
}

//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

//----Calculation---------------------------
for( i=0; i<limit; i++)
{
   int HH = Highest(NULL,0,MODE_HIGH,ArPer,i); //Periods from HH   
   int LL = Lowest(NULL,0,MODE_LOW,ArPer,i);     //Periods from LL

UpBarDif = i-HH;   //Period substraction
DnBarDif = i-LL;   //Period substraction
AroonUpBuffer[i]=100+(100/ArPer)*(UpBarDif); //Adjusted Aroon Up
AroonDnBuffer[i]=100+(100/ArPer)*(DnBarDif); //Adjusted Aroon Down

if (LastBars != Bars)
{
if ((AroonUpBuffer[0] > AroonDnBuffer[0]) && (AroonUpBuffer[1] <= AroonDnBuffer[1]))
{
if (MailAlert) SendMail("Aroon Up & Down Indicator Alert", "The indicator produced a cross (Blue ABOVE Red) on " + Year() + "-" + Month() + "-" + Day() + " " + Hour() + ":" + Minute());
if (SoundAlert) Alert("Aroon Up & Down produced a cross (Blue ABOVE Red)");
}
else if ((AroonUpBuffer[0] < AroonDnBuffer[0]) && (AroonUpBuffer[1] >= AroonDnBuffer[1]))
{
if (MailAlert) SendMail("Aroon Up & Down Indicator Alert", "The indicator produced a cross (Blue BELOW Red) on " + Year() + "-" + Month() + "-" + Day() + " " + Hour() + ":" + Minute());
if (SoundAlert) Alert("Aroon Up & Down produced a cross (Blue BELOW Red)");
}
LastBars = Bars;
}
}
return(0);
}

It is not obvious what would be the "Numerical value of the specified custom indicator", The value might be in this case are number in AroonUpBuffer and AroonDnBuffer, Since these are 2 seperate array, I don't understand how to calculate this.

I want to understand how this is calculate since the problems i am trying to solve is to Eliminate the use of ICustom and embeded the indicator calculation logic inside the EA directly so people who get the EA can use it directly without having to install any additional indicators so it would be much more eaiser to use.

iCustom - Technical Indicators - MQL4 Reference
iCustom - Technical Indicators - MQL4 Reference
  • docs.mql4.com
[in]  Custom indicator compiled program name, relative to the root indicators directory (MQL4/Indicators/). If the indicator is located in subdirectory, for example, in MQL4/Indicators/ The passed parameters and their order must correspond with the declaration order and the type of extern variables of the custom indicator...
 
I always find it easier to design such things from scratch over reading articles describig solutions made by others with other needs. 
But maybe you can find some guidelines here

 
Golf:

It is not obvious what would be the "Numerical value of the specified custom indicator", The value might be in this case are number in AroonUpBuffer and AroonDnBuffer, Since these are 2 separate arrays, I don't understand how to calculate this.

When you call iCustom(), you specifiy the "mode value," or "Line index value," which specifies which buffer.

Per the documentation: "Can be from 0 to 7 and must correspond with the index, specified in call of the SetIndexBuffer() function."

In your case, these are:

SetIndexBuffer(0, AroonUpBuffer);
SetIndexBuffer(1, AroonDnBuffer);

So:

double val=iCustom(NULL,0,"Aroon Up & Dn",14, false, false, 0,0);

Gives you the current value of buffer 0, i.e. AroonUpBuffer[].

 
Anthony Garot:

Per the documentation: "Can be from 0 to 7 and must correspond with the index, specified in call of the SetIndexBuffer() function."

No longer limited to 8 buffers. Can't remember the limit, think that it may be 256 or 512. Whatever it is it is far more than I will ever use.

 
Thank you so much everyone.
Reason: