Download MetaTrader 5

How to read SHIFT from inside indicator code?

To add comments, please log in or register
Mt Fan
519
Mt Fan  

Hello to everyone.

I'm trying to retrieve the SHIFT value from inside the indicator source code.

Is there any manner to do that?

I explain my need: when the indicator is called by the EA using iCustom, we have MODE & SHIFT parameters.

From inside the source code of the Indicator, I need to know which is the Shift used by the EA to call the Indicator.


Anyone can help?

Many thanks.
honest_knave
Moderator
2342
honest_knave  
Mt Fan:

Hello to everyone.

I'm trying to retrieve the SHIFT value from inside the indicator source code.

Is there any manner to do that?

I explain my need: when the indicator is called by the EA using iCustom, we have MODE & SHIFT parameters.

From inside the source code of the Indicator, I need to know which is the Shift used by the EA to call the Indicator.


Anyone can help?

Many thanks.


The shift is how many bars back you want the value from.

If you want the current value:

double val=iCustom(_Symbol,0,"SampleInd",13,1,0);

If you want the value 5 bars back:

double val=iCustom(_Symbol,0,"SampleInd",13,1,5);


Do you mean how do you find out the line index (mode)?

Mt Fan
519
Mt Fan  
honest_knave:


The shift is how many bars back you want the value from.

If you want the current value:

If you want the value 5 bars back:


Do you mean how do you find out the line index (mode)?

Thanks for writing.

I need to know FROM INSIDE the Indicator code which is the SHIFT used by the EA.

so if the EA makes this call:

double val=iCustom(_Symbol,0,"SampleInd",13,1,5);
I need to retrieve the SHIFT (5) from inside the "SampleInd" source code. Because the Indicators always calculates all values back. But I need that the indi must do some other things based on the SHIFT.
honest_knave
Moderator
2342
honest_knave  
Mt Fan:

Thanks for writing.

I need to know FROM INSIDE the Indicator code which is the SHIFT used by the EA.

You could look at Global Variables

i.e. your indicator saves the shift it is using to a GV, and your EA retrieves the GV value.

Mt Fan
519
Mt Fan  
honest_knave:


Do you mean if your EA does this:

You want your indicator to know "5"?

If so, you could look at Global Variables I suppose

i.e. your indicator saves the shift it is using to a GV, and your EA retrieves the GV value.

Yes, exactly the contrary: I need that indicator must know the SHIFT used by the EA in the iCustom call...........

Indicator must know that the EA called it using "5" as SHIFT.

honest_knave
Moderator
2342
honest_knave  
Mt Fan:

Yes, exactly the contrary: I need that indicator must know the SHIFT used by the EA in the iCustom call...........

Indicator must know that the EA called it using "5" as SHIFT.


Probably a better way than GVs is to have another input parameter in your indicator for shift. You pass this value with the iCustom call.

int shift = 5;
double val=iCustom(_Symbol,0,"SampleInd",shift,1,5);
Mt Fan
519
Mt Fan  
honest_knave:


Probably a better way than GVs is to have another input parameter in your indicator for shift. You pass this value with the iCustom call.

Yes, if there's no reserved variable of MQL4 I'll do that way ......


Many thanks to you  :)

whroeder1
17050
whroeder1  
Mt Fan: From inside the source code of the Indicator, I need to know which is the Shift used by the EA to call the Indicator.
Why? The indicator calculates all bars, it shouldn't care what values some EA might look at.
To add comments, please log in or register