Download MetaTrader 5
To add comments, please log in or register
Make screenshots in MetaTrader and manage them in the gallery!
pascalboy
238
pascalboy 2014.03.15 20:48 
Hi,

Let us say in an indicator there are three buffers.

Can we attend buf_0 (i) minus buf_1 (i-1) to buf_2 (i).

Buf_2(i)=buf_0(i)-buf_(i-1).

It says out of range error.

Why? Notice time difference . (i), (i-1).
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.03.15 21:19  
pascalboy:
Hi,

Let us say in an indicator there are three buffers.

Can we attend buf_0 (i) minus buf_1 (i-1) to buf_2 (i).

Buf_2(i)=buf_0(i)-buf_(i-1).

It says out of range error.

Why? Notice time difference . (i), (i-1).


You can only do this if you have already calculated buf_1[i - 1] . . . so which way does you loop go, increment or decrement ?
pascalboy
238
pascalboy 2014.03.15 21:21  
Decrement
Keith Watford
Moderator
7906
Keith Watford 2014.03.15 22:05  
pascalboy:
Hi,

Let us say in an indicator there are three buffers.

Can we attend buf_0 (i) minus buf_1 (i-1) to buf_2 (i).

Buf_2(i)=buf_0(i)-buf_(i-1).

It says out of range error.

Why? Notice time difference . (i), (i-1).




When i = 0 buf[i-1] will give the out of range error
pascalboy
238
pascalboy 2014.03.15 22:10  
With (i+1) the same result. No change.
Ian Venner
2583
Ian Venner 2014.03.15 22:23  

Your indicator loop is decrementing ?

If Indicator loop i starts at the highest bar index what is i + 1 ? Bar does not exist.

When indicator gets down to calculating zero bar i what is i - 1 ? Bar does not exist.

pascalboy
238
pascalboy 2014.03.15 22:30  
How can its logic be then?
Ian Venner
2583
Ian Venner 2014.03.15 22:34  

Logic goes like this,

The highest available Bar is Bars-1.

If buffer1[i] begins from Bars-1 and you want buffer2 to call buffer1[i+1] all through the chart, then buffer2[i] should begin from Bars-2

or

If you want buffer2[i] to call Buffer1[i-1] you can only do that when buffer2[i] > 0 unless you make buffer1 calculate a value for Bar -1.

pascalboy
238
pascalboy 2014.03.15 22:48  
Thanks . You right.
whroeder1
13610
whroeder1 2014.03.16 15:14  
You have a lookback of 1 for buffer2. Test for it.
int counted = IndicatorCounted();

// if(counted < LB0) counted = LB0; // Do you look at earlier values for buf_0?
for(int iBuf0 = Bars - 1 - counted; iBuf0 >= 0; iBuf0--) 
   buf_0[iBuf0] = ...

#define LB1 1
if(counted < LB1) counted = LB1;    // You DO look at earlier values for buf_1
for(int iBuf1 = Bars - 1 - counted; iBuf1 >= 0; iBuf1--) 
   buf_1[iBuf1] = ... buf_0[iBuf1+LB1] ... // Look back 1
/
To add comments, please log in or register