how to get value of previous period of an indicator ?

 

i define :

double indicator;

double x;

indicator=example(-----------------)

If x=(indicator-indicator(i-1))

How do i need to define i to be a period?

 

do u want to get previous bar indicator value..

is yes, like this:

double indicator = icustom(NULL,0,"your Indicator name",0,0); // this is indicator value at curent bar..

0 first is your indicator buffer..

0 second is period..

double indicator1 = icustom(NULL,0,"your Indicator name",0,1); // this is indicator value at last 1 bar..

double indicator2 = icustom(NULL,0,"your Indicator name",0,2); // this is indicator value at last 2 bar..

ok..

 
hardyyanto:

do u want to get previous bar indicator value..

is yes, like this:

double indicator = icustom(NULL,0,"your Indicator name",0,0); // this is indicator value at curent bar..

0 first is your indicator buffer..

0 second is period..

double indicator1 = icustom(NULL,0,"your Indicator name",0,1); // this is indicator value at last 1 bar..

double indicator2 = icustom(NULL,0,"your Indicator name",0,2); // this is indicator value at last 2 bar..

ok..


Thank you
 
hardyyanto:

do u want to get previous bar indicator value..

is yes, like this:

double indicator = icustom(NULL,0,"your Indicator name",0,0); // this is indicator value at curent bar..

0 first is your indicator buffer..

0 second is period..

double indicator1 = icustom(NULL,0,"your Indicator name",0,1); // this is indicator value at last 1 bar..

double indicator2 = icustom(NULL,0,"your Indicator name",0,2); // this is indicator value at last 2 bar..

ok..

But will this make the indicator executed twice and thus slower? I am looking for something as an array when I first call 'indicator1' and can retrieve indicator[0], indicator[1], etc.
 
lingwuchung:
But will this make the indicator executed twice and thus slower? I am looking for something as an array when I first call 'indicator1' and can retrieve indicator[0], indicator[1], etc.
No. iCustom just retreives the value in the buffer. It does not make the indicator run at all. The indicator has run BEFORE the EA's start() was called.
 
WHRoeder:
No. iCustom just retreives the value in the buffer. It does not make the indicator run at all. The indicator has run BEFORE the EA's start() was called.

But I only code which indicators to use within start(). So how could it knows which indicators I want before the EA's start()? I think an indicator will run at least (and hopefully at most) once within start().

 

On the FIRST iCustom call (each unique name/parameter combination,) it adds the indicator (hidden) to the chart, the indicator runs and iCustom retrieves the buffer value.

On the next tick, the indicator runs, THEN (if EA is not already in start,) start is called. The iCustom finds the indicator already on the chart and just retrieves the buffer value.

Reason: