Detailed explanation of iCustom

Back to topics list  | 1 2 3 To post a new topic, please log in or register
avatar
14167
RaptorUK 2012.03.22 11:36 #
 
NewCoder47:

Thanks Dabbler. I have attached the full EA and Indicator. I have read the statements on iCustom, and understand everything apart from the parameters part,

What goes into the parameters are the values that you want to use for the extern variables in the Indicator . . . in this case these . . .

//---- indicator parameters
extern string PairName = "";   // Leave blank for the pair of the chart, enter other pair name to compare correlated pairs

extern int StdDev.MA.Period=12;  // D1=20
extern int StdDev.MA.Shift=0;    //
extern int StdDev.MA.Method = 0; // 0=SMA 1=EMA 2=Smoothed 3=Linear Weighted
extern int StdDev.MA.Price = 0;  // 0 Close price, 1 Open price, 2 High price, 3 Low price, 4 Median price, (high+low)/2, 5 Typical price, (high+low+close)/3, 6 Weighted close price, (high+low+close+close)/4

extern int MA.Fast.Period = 3;
extern int MA.Fast.Method = 2;   //  0=SMA 1=EMA 2=Smoothed 3=Linear Weighted
extern int MA.Fast.Shift = 0;

extern bool CheckOncePerBar = true;

 
avatar
1001
dabbler 2012.03.22 19:53 #
 

Let's look at the help file again.

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

looking at the definition of the ... part.

... - Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.


You have 9 extern variables and therefore need 9 parameters in the correct order and with the correct type

     double     STDBuffer = iCustom(Null,0,"SFX","",12,0,0,0,3,2,0,true,0,0);
     double     stddevma =  iCustom(Null,0,"SFX","",12,0,0,0,3,2,0,true,1,0);

Easy peasy.

Then you ask "Also, is there any way to physically see what values are being sent to the EA?"

Sure.

Comment("StdBuffer=" + STDBuffer+"\nstddevma=" + stddevma);
avatar
12983
WHRoeder 2012.04.27 15:25 #
 
dabbler:
 double     STDBuffer = iCustom(Null,0,"SFX","",12,0,0,0,3,2,0,true,0,0);
 double     stddevma =  iCustom(Null,0,"SFX","",12,0,0,0,3,2,0,true,1,0);

Yep, except Null is a typo.

Start with the indicator and generate the code.

Indicator
EA
Indicator filename without extension, including blanks if any.
#define SFX "SFX"
#define since it is constant. Define it once so there's no typos.
extern string PairName = "";     // Leave blank for ...

extern int StdDev.MA.Period=12;  // D1=20
extern int StdDev.MA.Shift=0;    //
extern int StdDev.MA.Method = 0; // 0=SMA 1=EMA 2=Sm...
extern int StdDev.MA.Price = 0;  // 0 Close price, 1 O...
extern int MA.Fast.Period = 3;
extern int MA.Fast.Method = 2;   //  0=SMA 1=EMA 2=Sm ...
extern int MA.Fast.Shift = 0;

extern bool CheckOncePerBar = true;
string  PairName            = "";     
int     StdDev.MA.Period    = 12;  
int     StdDev.MA.Shift     =  0;    
int     StdDev.MA.Method    =  MODE_SMA; 
int     StdDev.MA.Price     =  PRICE_CLOSE;  
int     MA.Fast.Period      =  3;
int     MA.Fast.Method      =  MODE_SMMA;
int     MA.Fast.Shift       =  0;
#define CheckOncePerBar        true;
Values that do NOT affect the buffers, can be made constant.
   SetIndexBuffer(0, STDBuffer);
   SetIndexBuffer(1, stddevma);
May have to read the code to find the meaning of the buffers. E.g.
STDBuffer[i]= iStdDev(...)
stddevma[i] = iMAOnArray(
#define SFX_STD   0
#define SFX_STDMA 1
The calls then are
double     STDBuffer = iCustom(NULL,0,SFX,
                        PairName, StdDev.MA.Period, StdDev.MA.Shift, 
                        StdDev.MA.Method, StdDev.MA.Price, MA.Fast.Period, 
                        MA.Fast.Method, MA.Fast.Shift, CheckOncePerBar,
                                SFX_STD, 0)
double     stddevma =  iCustom(NULL,0,SFX,
                        PairName, StdDev.MA.Period, StdDev.MA.Shift, 
                        StdDev.MA.Method, StdDev.MA.Price, MA.Fast.Period, 
                        MA.Fast.Method, MA.Fast.Shift, CheckOncePerBar,
                                SFX_STDMA, 0)
 
avatar
13
Mafeng 2012.06.27 23:40 #
 

Thank you for your response. so


 ExtMapBuffer1[i+3] = lower_fractal_7b;     could be used as calculated value when reversal fractal is called?

avatar
18
12BPRO2 2013.05.07 14:56 #
 
ubzen:
Yes. All the time. I'm talking about Extern Values. And I'm guessing you're talking about Buffers.

Yes UBZEN,


I also tried what you suggested and it did return the value as what is stated in my indicator....

it is simply, easy to add or used with out all of those long parameters....  especially the one with arrays.......

I could get lost in compiling the parameters not you guy's............ the PRO'S here

thanks very much.... I was looking this this answer for a few days

avatar
12983
WHRoeder 2013.05.28 15:04 #
 
WHRoeder: The calls then are:
double     STDBuffer = iCustom(NULL,0,SFX,
                        PairName, StdDev.MA.Period, StdDev.MA.Shift, 
                        StdDev.MA.Method, StdDev.MA.Price, MA.Fast.Period, 
                        MA.Fast.Method, MA.Fast.Shift, CheckOncePerBar,
                                SFX_STD, 0)
double     stddevma =  iCustom(NULL,0,SFX,
                        PairName, StdDev.MA.Period, StdDev.MA.Shift, 
                        StdDev.MA.Method, StdDev.MA.Price, MA.Fast.Period, 
                        MA.Fast.Method, MA.Fast.Shift, CheckOncePerBar,
                                SFX_STDMA, 0)
Which should then be encapsulated.
double getSFX(int eBuf, int iBar = 0, int eTF=0){ 
   return( iCustom(NULL, eTF ,SFX,
                      PairName, StdDev.MA.Period, StdDev.MA.Shift, 
                      StdDev.MA.Method, StdDev.MA.Price, MA.Fast.Period, 
                      MA.Fast.Method, MA.Fast.Shift, CheckOncePerBar,
                   eBuf, iBar) ); 
}
:
double     STDBuffer = getSFX(SFX_STD, 0);
double     stddevma  = getSFX(SFX_STDMA, 0);
:
avatar
9
Maurice1985 2015.11.05 01:31 #
 
RaptorUK:

iCustom allows you to access your Indicators buffers . . . it's that simple.

For example, you are writing an EA that has a strategy based on 2 Indicators, you could build the Indicator code into the EA, that is possible but iss a little involved as Indicator buffers don't work on EAs, you would have to use arrays and handle them in an "as series" fashion . . . the alternative is to have the Indicators running and access their buffers from the EA . . . this is what iCustom facilitates. No changes are needed to the Indicators . . . . the EA simply accesses the buffers it needs at the shift values it needs. In the iCustom call it can also pass any extern variables that are needed to setup the Indicator as applicable

Dear RaptorUK (and others who might be able to help),


in the quoted post you describe two ways to use custom indicator values in an EA. The first is with iCustom which i'm already aware of. The second is one i would really like to learn more about because i've tried internalizing the code of custom indicators into the body of the main indicator before but without succes. You see, when i turned an indicator into a function and let it return its most current value (the value in element 0) i always get the EMPTY_VALUE for a double variable instead of the calculated value itself. I tried using the iCustom function, setting the shift to 0, the most recent value. When i do this the terminal starts by returning 0 coupled with the error STACK OVERFLOW in the experts tab. On the second tick it does return a value but after every couple of printed [0] values it gives another STACK OVERFLOW error, this keeps recurring over and over again. Because iCustom returns the value 0 and STACK OVERFLOW on first inititialization (and only after starts giving correct values) i can't use icustom in my EA because it calls the icustom for a different symbol every time Start() gets activated and it calls multiple custom indicators for that. This causes the EA to crash. I don't understand why i get a STACK OVERFLOW error whenever i want icustom to return the most recent value [0] but i would sure like to know. I prefer however to internalize the code of all the indicators that are being called by transforming them into functions inside the main indicator. You said something about using arrays and handle them in an "as series fashion". Could you please elaborate this?

I have added an mq4 file of the classic ADX.mq4 indicator. Inside the value of ADX gets printed twice. Once by Icustom, and secondly by the ADX code that has been turned into a function inside the ADX. Icustom(ADX) returns a value but ADX(symbol,timeframe) does not. It keeps returning the same EMPTY_VALUE of 247456457457 or something over and over again. Please explain why this is happening and how i can remedy this both in an EA template as in a mq4 custom indicator file.


Kind regards and thanks in advance


PS: attach file doesen't seem to be working. But you can download both the CallicustomvsFunction example indicator as the ADX custom indicator from http://www.forexfactory.com/showthre...37#post8569537 (my name there is Codix)

Attached files:
  callicustomvsfunction_1.mq4  (4.94 KB)
avatar
12983
WHRoeder 2015.11.05 16:09 #
 
  1. Don't double post
  2. Don't hijack other threads; Your questions are not about how to use iCustom.
avatar
12983
WHRoeder 2016.09.07 16:52 #
 

In the above posts (https://forum.mql4.com/46941/page3#627521 and https://forum.mql4.com/46941/page3#797401) I used dots and word separators.

That isn't allowed since February 3, 2014 (Build 600) Use an underscore or camel case.

Back to topics list   | 1 2 3  

To add comments, please log in or register