Using a custom indicator

 

Can some one help me on how to use a custom indicator in an expert?

 

iCustom function

forextrend:
Can some one help me on how to use a custom indicator in an expert?

There are two kind of indicators you can use in your expert advisor:

Built-in indicators:

The MQL4 has a number of built-in indicators which you can use them as a function for example:

double iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)

[/CODE]

double iATR( string symbol, int timeframe, int period, int shift)

Any other indicator:

To use any other indicator in your expert advisor you use the function iCustom:

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

For more details about iCustom see my post:

https://www.mql5.com/en/forum/173108

 

what to look for to call custom indicator

I see a few custom indicators with more than one line. what do i look for to tell what to put in the iCustom call?

for example heres an indicator that draws 2 lines one red and one blue

and i want to call the current bar of each if i wanted

double ccired

double cciblue

ccired=iCustom(NULL, 0, "CCITrigger", 0, 0); <-----?

cciblue=iCustom(NULL, 0, "CCITrigger", 0, 0); <-----?

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_color2 Red

// Ergo Variables

extern int pq =2;

extern int pr = 10;

extern int ps = 5;

extern int trigger =3;

//---- indicator buffers

string signal;

double mtm[];

double absmtm[];

double ErgoCCI[];

double MainCCI[];

double var1[];

double var2[];

double var2a[];

double var2b[];

//double valor1[];

//double valor2[];

//double extvar[];

//double cciSignal[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- 2 additional buffers are used for counting.

IndicatorBuffers(8);

//---- drawing settings

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Blue);

SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Red);

SetIndexBuffer(0,ErgoCCI);

SetIndexLabel(0,"Egodic CCI");

SetIndexBuffer(1,MainCCI);

SetIndexLabel(1,"Trigger Line");

SetIndexBuffer(2,mtm);

SetIndexBuffer(3,var1);

SetIndexBuffer(4,var2);

SetIndexBuffer(5,absmtm);

SetIndexBuffer(6,var2a);

SetIndexBuffer(7,var2b);

//---- name for DataWindow and indicator subwindow label

//---- initialization done

return(0);

}

//+------------------------------------------------------------------+

//| Calculations |

//+------------------------------------------------------------------+

int start()

{

int limit;

int i;

int counted_bars=IndicatorCounted();

//---- check for possible errors

if(counted_bars<0) return(-1);

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//---- main loop

//---- done

for(i=0; i <= Bars; i++)

{

mtm= Close- Close;

}

for(i=0; i <= Bars-1; i++)

{

absmtm = MathAbs(mtm);

}

for(i=0; i <= Bars-1; i++)

{

var1= iMAOnArray(mtm,0,pq,0,MODE_EMA,i);

}

for(i=0; i <= Bars-1; i++)

{

var2= iMAOnArray(var1,Bars,pr,0,MODE_EMA,i);

}

for(i=0; i <= Bars-1; i++)

{

var2a= iMAOnArray(absmtm,0,pq,0,MODE_EMA,i);

}

for(i=0; i <= Bars-1; i++)

{

var2b= iMAOnArray(var2a,0,pr,0,MODE_EMA,i);

}

for(i=0; i <= Bars-1; i++)

{

ErgoCCI = (500 * iMAOnArray(var2,0,ps,0,MODE_EMA,i))/(iMAOnArray(var2b,0,ps,0,MODE_EMA,i)); //var2a/var2b;

}

for(i=0; i<=Bars; i++)

{

MainCCI=iMAOnArray(ErgoCCI,0,trigger,0,MODE_EMA,i);

}

for(i=0; i<=Bars; i++)

{

if(MainCCI > ErgoCCI)

{signal = "SHORT";}

if (MainCCI < ErgoCCI)

{signal = "LONG";}

if (MainCCI == ErgoCCI)

{signal = "NEUTRAL";}

IndicatorShortName("FX Sniper's Ergodic CCI & Trigger: "+signal);

return(0); }

}

//+------------------------------------------------------------------+

 

thanks for the information

Reason: