Access indicator value for X bars ago

Created at 09 Sep 2013, 00:25
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
SI

sim_trader

Joined 03.08.2013

Access indicator value for X bars ago
09 Sep 2013, 00:25


Dear Forum,

Sorry for the really simple question. I have been reading for 3 hrs and cannot work it out.

I want to get the value of the zigzag indicator for X bars ago, where X is an external integer.

I thought I could change this line

double lastValue = _zigZag.Result.LastValue;

and use this instead

 double lastValue = _zigZag.Result[backstep_bars];
        

backstep_bars is a declared external integer.

While it compiles it does not seem to return the correct value. I would have assumed that if I set "backstep_bars" to 0 or 1
it would be the same value as _zigZag.Result.LastValue; but it does not ?

 

What am I missing ? I have been trading in MQL4 for sometime but have no experience in C#. But will to learn.

 

Thanks for your helps, Cheers, Sim


@sim_trader
Replies

adaled
09 Sep 2013, 11:57

RE:

sim_trader said:

I want to get the value of the zigzag indicator for X bars ago, where X is an external integer.

var lastValue = _zigZag.Result.Result[index - backstep_bars];
 


@adaled

sim_trader
10 Sep 2013, 15:56

RE: RE:

adaled said:

sim_trader said:

I want to get the value of the zigzag indicator for X bars ago, where X is an external integer.

var lastValue = _zigZag.Result.Result[index - backstep_bars];
 

Hi Adaled,

 

Thanks so much !!!!, Cheers, Sim


@sim_trader

cAlgo_Fanatic
10 Sep 2013, 16:08

RE:

sim_trader said:

Dear Forum,

Sorry for the really simple question. I have been reading for 3 hrs and cannot work it out.

I want to get the value of the zigzag indicator for X bars ago, where X is an external integer.

I thought I could change this line

double lastValue = _zigZag.Result.LastValue;

and use this instead

 double lastValue = _zigZag.Result[backstep_bars];
        

backstep_bars is a declared external integer.

While it compiles it does not seem to return the correct value. I would have assumed that if I set "backstep_bars" to 0 or 1
it would be the same value as _zigZag.Result.LastValue; but it does not ?

 

What am I missing ? I have been trading in MQL4 for sometime but have no experience in C#. But will to learn.

 

Thanks for your helps, Cheers, Sim

Please note that the ZigZag is not simple indicator. That is, you can not read intermediate values (so you need to interpolate).

 


@cAlgo_Fanatic

sim_trader
10 Sep 2013, 21:22

RE: RE:

cAlgo_Fanatic said:

sim_trader said:

Dear Forum,

Sorry for the really simple question. I have been reading for 3 hrs and cannot work it out.

I want to get the value of the zigzag indicator for X bars ago, where X is an external integer.

I thought I could change this line

double lastValue = _zigZag.Result.LastValue;

and use this instead

 double lastValue = _zigZag.Result[backstep_bars];
        

backstep_bars is a declared external integer.

While it compiles it does not seem to return the correct value. I would have assumed that if I set "backstep_bars" to 0 or 1
it would be the same value as _zigZag.Result.LastValue; but it does not ?

 

What am I missing ? I have been trading in MQL4 for sometime but have no experience in C#. But will to learn.

 

Thanks for your helps, Cheers, Sim

Please note that the ZigZag is not simple indicator. That is, you can not read intermediate values (so you need to interpolate).

Hi CAlgo,

Thanks so much for your help. I am not 100% sure what you mean. In MT4 I used to cycle through the bars and check if the ZZ indicator has a value. Once a value is found it return the value as the local extreme.

The code would be

 

double GetExtremumZZPrice(int ne=0) {
   double zz;   
   int    i, k=iBars(Symbol(), 0), ke=0;
   for (i=1; i<k; i++) {
      zz=iCustom(Symbol(),0, "ZigZag", ExtDepth,ExtDeviation,ExtBackstep,0,i);
      if (zz!=0) {
         ke++;
         if (ke>ne) return(zz);     
      }   
   }   
   return(0);
}

Is there anyway you could help me convert this function to return most recent extreme price. I am really struggling with it in CAlgo.

 

Thanks so so much, Cheers

 

Andre


@sim_trader

Spotware
03 Jul 2014, 08:58

cAlgo code snippet to access values of ZigZag indicator has been posted there:

/forum/cbot-support/3089?page=1#4


@Spotware