Cannot get iCustom to work

 
Can somebody please post a very simple example of
a) an EA that uses iCustom to get 2 parameters back. No code is needed to do anything with the parameters, except perhaps print them
b) the corresponding indicator that produces the 2 parameters. The code to produce the contents can be hard-coded

Comments in these would be appreciated.

I have tried everything, followed all examples, but somewhere I am doing something wrong.
 
Similar Expert Advisor you can download from https://www.mql5.com/ru/users/agalindo
There is indicator with 5 buffers which calls from EA.
 
Thank you. I had looked at that, and the following does not make sense to me:

tm0=iCustom(Symbol(),0,"FX_FISH_2MA",10,0,False,False,9,45,"-", "-",0,3,3,0); means there are two numeric parameters, two boolean, two numeric, two strings, 4 numeric.

In the indicator, I find 2 numeric, two boolean, one numeric, two strings, two numeric parameters. How can this work if there is such a mismatch?
extern int period=10;
extern int price=0; // 0 or other = (H+L)/2
// 1 = Open
// 2 = Close
// 3 = High
// 4 = Low
// 5 = (H+L+C)/3
// 6 = (O+C+H+L)/4
// 7 = (O+C)/2
extern bool Mode_Fast= False;
extern bool Signals= False;
extern int MA1period=9, MA2period=45;
extern string TypeHelp = "SMA- 0, EMA - 1, SMMA - 2, LWMA- 3";
extern string TypeHelp2 = "John Hyden settings TypeMA1=0, TypeMA2=3";
extern int TypeMA1=0;
extern int TypeMA2=3;

And where in the indicator does the value get set that must be returned to the EA, ie that gets stored in tm0?

Can anybody provide one EA and one indicator, with no special code to actually do anything except to pass parameters back and forth, and comments to show what must be done and why it must be done?
 
Here is my EA code that I cannot get to work. I want to have ExtMapBuffer1[0],ExtMapBuffer2[0] from the following
indicator returned to my EA.
 
int init()
  {
   return(0);
  }
//-------------------------------------------------------------------------------------------------------------------
int start()
  {
Print(iCustom("",0,"Heiken_Ashi_Smoothed_Alert",2,6,3,2,false,false,false,0,0));
// no matter which values I enter in place of the '0,0' above, it always prints zero.
 
  return(0);
}
 
 
 
 
 
Indicator which works:
 
//+------------------------------------------------------------------+
//|                                   Heiken_Ashi_Smoothed_Alert.mq4 |
//+------------------------------------------------------------------+
//|                                                      mod by Raff |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "https://www.forex-tsd.com/"
#property link      "Alerts added by cja"
 
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 RoyalBlue
#property indicator_color3 Red
#property indicator_color4 RoyalBlue
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3
 
//---- parameters
extern int MaMetod  = 2;
extern int MaPeriod = 6;
extern int MaMetod2  = 3;
extern int MaPeriod2 = 2;
 
extern bool EmailON=false;
extern bool POP_UP_Box_Alert = false;
extern bool Sound_Alert = false;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
//---- indicators
   IndicatorBuffers(8);
 
   SetIndexStyle(0,DRAW_HISTOGRAM, 0);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0);
   SetIndexBuffer(3, ExtMapBuffer4);
//----
   SetIndexDrawBegin(0,5);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexBuffer(7,ExtMapBuffer8);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
  return(0);
  }  
bool Crossed (double haOpen , double haClose )
{
 
static string last_direction = "";
string current_direction = "";
 
if(haOpen<=haClose) current_direction = "LONG";
if(haOpen>haClose) current_direction = "SHORT";
 
if(current_direction != last_direction) 
{
      if(POP_UP_Box_Alert==true)Alert ("Change "+current_direction+"  " ,Symbol()," ",Period(),
      " @ ",Bid," ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS));
      if(Sound_Alert==true) PlaySound("alert2.wav"); 
      last_direction = current_direction;
      
      return (true);
      
}
else
{
      return (false);
 
}
 
  
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double maOpen, maClose, maLow, maHigh;
   double haOpen, haHigh, haLow, haClose;
   if(Bars<=10) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
   int pos=Bars-ExtCountedBars-1;
   while(pos>=0)
     {
      maOpen=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_OPEN,pos);
      maClose=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_CLOSE,pos);
      maLow=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_LOW,pos);
      maHigh=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_HIGH,pos);
 
      haOpen=(ExtMapBuffer5[pos+1]+ExtMapBuffer6[pos+1])/2;
      haClose=(maOpen+maHigh+maLow+maClose)/4;
      haHigh=MathMax(maHigh, MathMax(haOpen, haClose));
      haLow=MathMin(maLow, MathMin(haOpen, haClose));
 
      if (haOpen<haClose) 
        {
         ExtMapBuffer7[pos]=haLow;
         ExtMapBuffer8[pos]=haHigh;
        } 
      else
        {
         ExtMapBuffer7[pos]=haHigh;
         ExtMapBuffer8[pos]=haLow;
        } 
      ExtMapBuffer5[pos]=haOpen;
      ExtMapBuffer6[pos]=haClose;
 
        pos--;
     }
 
   int i;
   for(i=0; i<Bars; i++) ExtMapBuffer1[i]=iMAOnArray(ExtMapBuffer7,Bars,MaPeriod2,0,MaMetod2,i);
   for(i=0; i<Bars; i++) ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer8,Bars,MaPeriod2,0,MaMetod2,i);
   for(i=0; i<Bars; i++) ExtMapBuffer3[i]=iMAOnArray(ExtMapBuffer5,Bars,MaPeriod2,0,MaMetod2,i);
   for(i=0; i<Bars; i++) ExtMapBuffer4[i]=iMAOnArray(ExtMapBuffer6,Bars,MaPeriod2,0,MaMetod2,i); 
 
     Print("Crossed:",Crossed (ExtMapBuffer1[0],ExtMapBuffer2[0]));
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
change strings var to int, maybe OK
 
ren518:
change strings var to int, maybe OK
Which strings var, please?
 

Try this:

It should work if you set variables to values you want in Heiken_Ashi_Smoothed_Alert code and compiled. If these are correct, you do not need to reset or change them in the iCustom() call. This code should print all 4 indicator buffers for current period.

int init()
  {
   return(0);
  }
//-------------------------------------------------------------------------------------------------------------------
int start()
  {
int mode=4;
for(int cnt=0;cnt<=mode;cnt++) {
Print(iCustom(Symbol(),0,"Heiken_Ashi_Smoothed_Alert",0,mode-1,0));
} 
  return(0);
}
 
Hi,

Here's an example of working indicator which outputs two values: the first value is a little bit over the high, and the second under the low for the respective index. It serves on two purposes:
- review how you can export two values from a single indicator
- will be called from a different indicator using iCustom for retrieving first / second value

Key points:
- first thing to note is the
#property indicator_buffers 2
. You always have to specify how many values your indicator is exporting
- declare the two buffers holding the values:
double ExtMapBuffer1[];
double ExtMapBuffer2[];


- assign values for each of the buffers depending on your logic


In order to call it from a different indicator / expert and so on, you would have to match exactly the format of iCustom and the parameters expected by the indicator you need to call. For example, this indicator has two parameters: an int and a string. In order to retrieve the values in the latest bar from chart you can call it like this:

double exported1 = iCustom(NULL, 0, "Sample Indicator", 25, "param2 value", 0, 0);
double exported2 = iCustom(NULL, 0, "Sample Indicator", 25, "param2 value", 1, 0);

The documentation on iCustom could have provided more examples, but here's a little explanation for each of the entries:
- argument1: NULL means use the current symbol
- argument2: 0 means the current time frame
- argument3: is the exact name of the indicator you need to call
- argument4, argument5: those are the parameter values you want to pass to the Sample Indicator in order to get the results back. It's like entering values in the indicator editor window. The number of arguments and the exact type needs to be known; in this case the first is the integer, the second parameter of the Sample Indicator is a string; there could have been more arguments or even none
- in order to specify which of the custom indicator values you need to retrieve, use the last but one parameter (which shows up bold). Retrieve the first value of the indicator by specifying 0, for second value specify 1 and so on. You can have up to 8 different values there (0 to 7) as this is the maximum number of values an indicator can export. Note how I had to call it twice in order to get both values from iCustom.
- the last argument represents the number of bars counted from the end (the last bar has index 0) for which to compute the indicator value for. If you need to get the value for 10 bars behind the latest one, then use that argument to specify it.


Hope it helps,
Evariste
Files:
 
EvaristeGalois7:
Hi,

Here's an example of working indicator which outputs two values: the first value is a little bit over the high, and the second under the low for the respective index. It serves on two purposes:
- review how you can export two values from a single indicator
- will be called from a different indicator using iCustom for retrieving first / second value

Key points:
- first thing to note is the
. You always have to specify how many values your indicator is exporting
- declare the two buffers holding the values:


- assign values for each of the buffers depending on your logic


In order to call it from a different indicator / expert and so on, you would have to match exactly the format of iCustom and the parameters expected by the indicator you need to call. For example, this indicator has two parameters: an int and a string. In order to retrieve the values in the latest bar from chart you can call it like this:


The documentation on iCustom could have provided more examples, but here's a little explanation for each of the entries:
- argument1: NULL means use the current symbol
- argument2: 0 means the current time frame
- argument3: is the exact name of the indicator you need to call
- argument4, argument5: those are the parameter values you want to pass to the Sample Indicator in order to get the results back. It's like entering values in the indicator editor window. The number of arguments and the exact type needs to be known; in this case the first is the integer, the second parameter of the Sample Indicator is a string; there could have been more arguments or even none
- in order to specify which of the custom indicator values you need to retrieve, use the last but one parameter (which shows up bold). Retrieve the first value of the indicator by specifying 0, for second value specify 1 and so on. You can have up to 8 different values there (0 to 7) as this is the maximum number of values an indicator can export. Note how I had to call it twice in order to get both values from iCustom.
- the last argument represents the number of bars counted from the end (the last bar has index 0) for which to compute the indicator value for. If you need to get the value for 10 bars behind the latest one, then use that argument to specify it.


Hope it helps,
Evariste



Thank you for this post! Now i understand how it works! :-) It's really helped me!

 
  1. Thank you for bringing up a eight (8) year old post with a useless comment.
  2. Detailed explanation of iCustom - MQL4 forum
 
Evariste Galois:
Hi,

Here's an example of working indicator which outputs two values: the first value is a little bit over the high, and the second under the low for the respective index. It serves on two purposes:
- review how you can export two values from a single indicator
- will be called from a different indicator using iCustom for retrieving first / second value

Key points:
- first thing to note is the
. You always have to specify how many values your indicator is exporting
- declare the two buffers holding the values:


- assign values for each of the buffers depending on your logic


In order to call it from a different indicator / expert and so on, you would have to match exactly the format of iCustom and the parameters expected by the indicator you need to call. For example, this indicator has two parameters: an int and a string. In order to retrieve the values in the latest bar from chart you can call it like this:


The documentation on iCustom could have provided more examples, but here's a little explanation for each of the entries:
- argument1: NULL means use the current symbol
- argument2: 0 means the current time frame
- argument3: is the exact name of the indicator you need to call
- argument4, argument5: those are the parameter values you want to pass to the Sample Indicator in order to get the results back. It's like entering values in the indicator editor window. The number of arguments and the exact type needs to be known; in this case the first is the integer, the second parameter of the Sample Indicator is a string; there could have been more arguments or even none
- in order to specify which of the custom indicator values you need to retrieve, use the last but one parameter (which shows up bold). Retrieve the first value of the indicator by specifying 0, for second value specify 1 and so on. You can have up to 8 different values there (0 to 7) as this is the maximum number of values an indicator can export. Note how I had to call it twice in order to get both values from iCustom.
- the last argument represents the number of bars counted from the end (the last bar has index 0) for which to compute the indicator value for. If you need to get the value for 10 bars behind the latest one, then use that argument to specify it.


Hope it helps,
Evariste
GABOR DELI:


Thank you for this post! Now i understand how it works! :-) It's really helped me!

Yes it is indeed a big help, no matter how long ago it was posted. Makes noobs find the answer they need faster.

Reason: