How to use iCustom() ??

 

Hi,

First time I try to call an indi into my EA... and I got lost o_O !

Here the indicator: RSI divergence.

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Magenta
#property indicator_color4 Blue
//----
#define arrowsDisplacement 0.0001
//---- input parameters
extern int signalSMA = 9;
extern int RSI_PERIOD = 14;
extern double Long_Divergence = 40;
extern double Short_Divergence = 60;
       bool Reversed_Div = false;
extern bool drawIndicatorTrendLines = true;
extern bool drawPriceTrendLines = true;
extern bool displayAlert = true;
//---- buffers
double bullishDivergence[];
double bearishDivergence[];
double RSI[];
double signal[];
//----
static datetime lastAlertTime;
static string indicatorName;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW);
SetIndexStyle(1, DRAW_ARROW);
SetIndexStyle(2, DRAW_LINE);
SetIndexStyle(3, DRAW_LINE);
//----
SetIndexBuffer(0, bullishDivergence);
SetIndexBuffer(1, bearishDivergence);
SetIndexBuffer(2, RSI);
SetIndexBuffer(3, signal);
//----
SetIndexArrow(0, 233);
SetIndexArrow(1, 234);
//----
indicatorName = "RSI_Divergence";
SetIndexDrawBegin(3, signalSMA);
IndicatorDigits(Digits + 2);
IndicatorShortName(indicatorName);

SetLevelValue(0,50);
SetLevelStyle(STYLE_DOT,1,DimGray);

return(0);
}
// .....

 Let's say the indicator sends a signal:


I need to get it into my EA so I call it like this:

// CALL INDICATOR

 double Divergence_Indi = iCustom(NULL,0,"RSI_Divergence",9,14,40,60,0,9);


Do i call the iCustom() correctly wih external parameters?


Then how I know from my paramater "Divergence_Indi" I receive a bulish or bearish signal?


I guess I have to create 2 parameters one for long and 1 for short... but what should be iCustom(....) ?



Please help

Cheers

 
FrenchyTrader:


Do i call the iCustom() correctly wih external parameters?


There is a thread all about iCustom() on this Forum . . . use the search and you will find it.

 

Detailed explanation of iCustom - MQL4 forum 

 
RaptorUK:

There is a thread all about iCustom() on this Forum . . . use the search and you will find it.

 

Detailed explanation of iCustom - MQL4 forum 


Thank you for fast reply.



I have use the empty technic such as:

double GetValue0 = iCustom(NULL,0,"RSI_Divergence",0,0);
Print("GetValue0=",GetValue0); // => I got the value: 2147483647  I thought that was the date when last Divergence happened... but the data converted = 2038/1/19... so it's not on timeCurrent() format. 
Actually I don't know what I'm supposed to get from SetIndexBuffer0 & 1:
if( RSI[currentTrough] > RSI[lastTrough] &&
Low[currentTrough] < Low[lastTrough])
{
bullishDivergence[currentTrough] = RSI[currentTrough] -   // <= Here is SetIndexBuffer0 => bullishDivergence[]
arrowsDisplacement;
I tried to create a new SetIndexBuffer to receive TimeCurrent() when a divergence happens... Unfortunately I wan'st able to create this. I need more help... please : ) Cheers
 
I got the value: 2147483647

This is the equivalent of an Empty buffer.

This means that there is no arrow on the bar that you have looked at. 

 
GumRai:

This is the equivalent of an Empty buffer.

This means that there is no arrow on the bar that you have looked at. 


Thank you!


So is it possibly to know what should be the ID for up arrow or down narrow?

 
FrenchyTrader:

Thank you!


So is it possibly to know what should be the ID for up arrow or down narrow?


Anything but 2147483647 (enumeration EMPTY_VALUE)

If buffer value != EMPTY_VALUE, then you know that there is an arrow there 

 
GumRai:


Anything but 2147483647 (enumeration EMPTY_VALUE)

If buffer value != EMPTY_VALUE, then you know that there is an arrow there 


Thank you... now I receive the RSI value only when I got a divergence from indi.
 

I want to add one more question here-


If I call this indicator to an EA then ----------------------------------

buy signal-what will be value to get buy for this custom indicator 

RSI_Divergence

sell signal-what will be the value to get sell signal for this custom indicator 

RSI_Divergence

Thanks in advance

Mohammad

Reason: