MT4 get indicator value

 

Hi!

I am beginner in MQL4.

How can get some info from an added indicator? For example, the indicator color and value.


G.

 

AFAIK iCustom is the only way to 'look inside' an indicator & get info. You can get values (up to 8 = buffers used) for each bar.

When using iCustom to 'look inside' an indicator, AFAIK there is no 'simple' way to discover colour, only value.

 
brewmanz:

AFAIK iCustom is the only way to 'look inside' an indicator & get info. You can get values (up to 8 = buffers used) for each bar.

When using iCustom to 'look inside' an indicator, AFAIK there is no 'simple' way to discover colour, only value.

I like to get info from "Slope Direction Line" indicator (see attached file).

I tried it:

double iSDL;
iSDL = iCustom( NULL, 0, "Slope Direction Line", somevalue, 13, 1, 0 );

Print("Indicator: ", iSDL);

What can I use in place of "somevalue" variable? I would like to get color and indicator value.


G.

Files:
 
makgab:

I like to get info from "Slope Direction Line" indicator (see attached file).

I tried it:

double iSDL;
iSDL = iCustom( NULL, 0, "Slope Direction Line", somevalue, 13, 1, 0 );

Print("Indicator: ", iSDL);

What can I use in place of "somevalue" variable? I would like to get color and indicator value.

G.


Hi Makgab,

First you need to spell the indicator exactly in your iCustom - your indicator is all one word with an extra "q" and "t" in it = "SlopeqDirectiontLine"

Second you need to include all "extern's" in the iCustom.

//---- input parameters
extern int period=80;
extern int method=3; // MODE_SMA
extern int price=0; // PRICE_CLOSE

Third you need to use the proper indicator buffers to get the values/colors

//---- Buffers
Buffer 0 - double Uptrend[]; #property indicator_color1 LightBlue
Buffer 1 - double Dntrend[]; #property indicator_color2 Tomato
Buffer 2 - double ExtMapBuffer[]; No color

Examples:
Uptrend = iCustom( NULL, 0, "SlopeqDirectiontLine", period, method, price, 0, 0 ); // BUFFER 0 - LightBlue
Dntrend = iCustom( NULL, 0, "SlopeqDirectiontLine", period, method, price, 1, 0 ); // BUFFER 1 - Tomato

Hope this helps,
Robert
 
cosmicbeing:
//---- Buffers
Buffer 0 - double Uptrend[]; #property indicator_color1 LightBlue
Buffer 1 - double Dntrend[]; #property indicator_color2 Tomato
Buffer 2 - double ExtMapBuffer[]; No color

Examples:
Uptrend = iCustom( NULL, 0, "SlopeqDirectiontLine", period, method, price, 0, 0 ); // BUFFER 0 - LightBlue
Dntrend = iCustom( NULL, 0, "SlopeqDirectiontLine", period, method, price, 1, 0 ); // BUFFER 1 - Tomato


Ok,thanks!

What is the mode in " double iCustom( string symbol, int timeframe, string name, ...params, int mode, int shift)"?

In this case 0 and 1.

I don't understand these 2 values. :( What does it mean?

"Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions." <--- I do not quite understand.

 
makgab:


Ok,thanks!

What is the mode in " double iCustom( string symbol, int timeframe, string name, ...params, int mode, int shift)"?

In this case 0 and 1.

I don't understand these 2 values. :( What does it mean?

"Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions." <--- I do not quite understand.


Hi Makgab,

Yes...the "mode" is the BUFFERS...in this case Buffer 0 and Buffer 1.

For the Indicator -

Buffers are used as the storage for indicator values...

For the EA -

Buffers are what iCustom statements use to get the values from the indicator...and apply them to your buy/sell strategy.

These buffers are the Values/Colors for the indicator you are using...

Not sure your last question. Read more about BUFFERS...and look on this site for many other Buffer code examples.

Hope this helps,

Robert

 

cosmicbeing:

For the Indicator -

Buffers are used as the storage for indicator values...

For the EA -

Buffers are what iCustom statements use to get the values from the indicator...and apply them to your buy/sell strategy.

These buffers are the Values/Colors for the indicator you are using...


Hi,

I think I begin to understand. :)

My test code:

// variables from SDL indicator buffers, indicator name: "Slope Direction Line.mq4"
double Uptrend[]; #property indicator_color1 LightBlue
double Dntrend[]; #property indicator_color2 Tomato
double ExtMapBuffer[];

// running
Uptrend[0] = iCustom( NULL, 0, "Slope Direction Line", period, method, price, 0, 0 ); // BUFFER 0 - LightBlue
Dntrend[0] = iCustom( NULL, 0, "Slope Direction Line", period, method, price, 1, 0 ); // BUFFER 1 - Tomato

Print("EA UP: ", Uptrend[0], " -> SDL DN: ", Dntrend[0]);


It prints:

EA UP: 0 -> SDL DN: 0


It get 0 values. What am I doing wrong?

G.


 
makgab:
What is the mode in " double iCustom( string symbol, int timeframe, string name, ...params, int mode, int shift)"?
In this case 0 and 1.
I don't understand these 2 values. :( What does it mean?
Buffer 0 - double Uptrend[]; #property indicator_color1 LightBlue
Buffer 1 - double Dntrend[]; #property indicator_color2 Tomato
Buffer 2 - double ExtMapBuffer[]; No color
Self documenting code helps:
#define SDL       "SlopeqDirectiontLine"
#define LightBlue 0
#define Tomato    1
#define clear     2
...
Uptrend[0] = iCustom( NULL, 0, SDL, period, method, price, LightBlue, 0 );
Dntrend[0] = iCustom( NULL, 0, SDL, period, method, price, Tomato,    0 );

 

hi everyone,

how to set the variable with value in indicator and give the value into EA ?

i have variable buy_val in indicator file and i just want to pass this value into EA (print the value)..


thanks

 

Hello CosmicBeing,


I just had to thank you so so so so so so much.....I've been searching for my problem to trying to call the ipanel_trend indicator for days and your explanation just saved me the hassle. I now fully grasp iCustom.


I believe it is Up value = iCustom (Symbol(), 0, "ipanel_trend", 1, 0, 140, 0, 0) with the second to the last 0 representing the value for the up buffer. 1 will represent the value of the down buffer.


THANKS AGAIN!!!


If anyone could help with my next problem. How does EMPTY_VALUE work? I tried using it to calc reversal fractals but it doesn't work unless i place in zero (0).

RevFracValue1 = iCustom(Symbol(),0,"ReversalFractals",CalculateOnBarClose,0,0);
RevFracValue2 = iCustom(Symbol(),0,"ReversalFractals",CalculateOnBarClose,1,0);

if (RevFracValue1 != EMPTY_VALUE)
{
RevFracBuy = True;
RevFracSell = False;
}
if (RevFracValue2 != EMPTY_VALUE)
{
RevFracSell = True;
RevFracBuy = False;
}
   }


Thanks.

Reason: