Question About Indicator Variable

 

Hi All,

I'm a newbie & kind of confused by the snippet below. Could anyone explain what is actually the 'shift' or it's exact function in simple explanation?

int shift = 1;

double x1 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, 1, shift);
double x2 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, 0, shift + 1);

I need the value of the first & second last indicator bar? Can I simply use the snippet below instead without the shift & will it have any effect?

double x1 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, 1);
double x2 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, 0);

I tested both and the first snippet(with shift) above gave the value of previous bars not current bar.

Thanks!

 

It is not possible to answer since we don't know which external variables your iX indicator has.


//z

 
Sorry, I thought it will be clearer by by renaming to iX. It's actually Heiken Ashi Smoothed indicator. double x1 = iCustom(NULL, 0,"HeikenAshiSmoothed", 2, 6, 3, 2, 1, shift); double x2 = iCustom(NULL, 0,"HeikenAshiSmoothed", 2, 6, 3, 2, 0, shift + 1);
 
Invalid:

I'm a newbie & kind of confused by the snippet below. Could anyone explain what is actually the 'shift' or it's exact function in simple explanation?

int shift = 1;

double x1 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, 1, shift);
double x2 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, 0, shift + 1);

I need the value of the first & second last indicator bar? Can I simply use the snippet below instead without the shift & will it have any effect?

double x1 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, 1);
double x2 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, 0);

I tested both and the first snippet(with shift) above gave the value of previous bars not current bar.

Format is iCustom( symbol, TF, "CustomIndicator", arg1 .. argN, Buffer, shift)

Shift is which bar you want, zero=current, one=last. You probably want

int shift = 1; #define buf=0;

double x1 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, buf, shift);
double x2 = iCustom(NULL, 0,"iX", 1, 2, 3, 4, buf, shift + 1);

so you can compare the same value from two bars. Normally it doesn't make sense to compare two different buffers from two different bars.

The second problem is how many parameters does the indicator have. The first two iCustom's contains four (1,2,3,4, plus buffer and shift). The second pair contains three (1,2,3) with buffer number 5.

Using Alligator.mq4 as an example you see

extern int JawsPeriod=13;
extern int JawsShift=8;
extern int TeethPeriod=8;
extern int TeethShift=5;
extern int LipsPeriod=5;
extern int LipsShift=3;
//---- indicator buffers
double ExtBlueBuffer[];
double ExtRedBuffer[];
double ExtLimeBuffer[];
So the call would be
JawsPeriod=13;
JawsShift=8;
TeethPeriod=8;
TeethShift=5;
LipsPeriod=5;
LipsShift=3;
#define ALL_BLUE 0
#define ALL_RED  1
#define ALL_LIME 2
double value = iCustom(NULL,0, "Alligator", 
                       JawsPeriod, JawsShift, TeethPeriod, TeethShift, LipsPeriod, LipsShift,
                       ALL_LIME, shift);
                       
 
Thanks a million, WHRoeder! That explain a lot!