Bar Index Help - page 2

 
if(Supportbuffer[i] < Supportbuffer[i-1])

When i==0 you are trying to access Supportbuffer[-1] ,  it doesn't exist

Also as you are counting down in your loop, you are comparing Supportbuffer[i] to a buffer element that has not yet been assigned a value.

 
GumRai:

When i==0 you are trying to access Supportbuffer[-1] ,  it doesn't exist

Also as you are counting down in your loop, you are comparing Supportbuffer[i] to a buffer element that has not yet been assigned a value.


Thank you for your reply.

I corrected the i==0 issue with the followings:

for(int i=limit;  i>= 0; i--)
{

 if((iHigh(Symbol(),0,i-1) >= iHigh(Symbol(),0,i) && iLow(Symbol(),0,i-1) >= iLow(Symbol(),0,i)) )
 { 

   Supportbuffer[i] = iLow(Symbol(),0,i);
   if(i!=0)
   {
   if(Supportbuffer[i] < Supportbuffer[i-1])
   {
    Supportbuffer2[i] = Supportbuffer2[i] + MathAbs(i-(i-1));
    buffer[i] = iLow(Symbol(),0,Supportbuffer2[i]);
   
   }
   }
 }

 But array is still out of range on that line & even if I try to assign value like

Supportbuffer2[i] = 0; it shows array error on that line too.

 
 Supportbuffer2[i] = Supportbuffer2[i] + MathAbs(i-(i-1));

That would not give an array out of range error, but it does not make any sense

MathAbs(i-(i-1))

will always equal 1

I can still see that there are still 4 instances where you try to access index i-1

 
GumRai:

That would not give an array out of range error, but it does not make any sense

will always equal 1

I can still see that there are still 4 instances where you try to access index i-1

You are right, I realize later, that it equals 1, so i put simple 1 in the code but line still shows array out of range. Do I need to run forward loop instead of backward loop ? Regards
 Supportbuffer[i] = iLow(Symbol(),0,i);
   if(i!=0)
   {
   if(Supportbuffer[i] < Supportbuffer[i-1])
   {
    Supportbuffer2[i] = Supportbuffer2[i] + 1;
    buffer[i] = iLow(Symbol(),0,Supportbuffer2[i]);
   
   }
   }
 

Did you read my post??????

GumRai:

I can still see that there are still 4 instances where you try to access index i-1

 
cashcube: I updated the code more, declaring 3 buffer at initialization. Supportbuffer2 is integer type. But its showing, array out of range error.
SetIndexBuffer - Custom Indicators - MQL4 Reference Requires a double array.
bool  SetIndexBuffer(
   int                    index,         // buffer index
   double                 buffer[]       // array
   );
 

Hello GumRai, I understood about the 4 instance, that's why in following code I added  if(i!=0) after the loop starting. So that -1 never occurs.

Without i-1 how can I check the next bar in a backward loop?

Thank you WHRoeder I changed the data type of the buffer into double. Here is my current code. But still same problem with i-1 line even after adding i!=0 condition.

for(int i=limit;  i>= 0; i--)
{
  if(i!=0)
   {
 if((iHigh(Symbol(),0,i-1) >= iHigh(Symbol(),0,i) && iLow(Symbol(),0,i-1) >= iLow(Symbol(),0,i)) )
 { 
 
   Supportbuffer[i] = iLow(Symbol(),0,i);
   Supportbuffer3[i] = iLow(Symbol(),0,i-1);
   
  
   if(Supportbuffer[i] < Supportbuffer3[i])
   {
    Supportbuffer2[i] = Supportbuffer2[i] + 1;
    buffer[i] = iLow(Symbol(),0,(int)Supportbuffer2[i]);
   
   }
   }
 }
 

Why would you do

for(int i=limit;  i>= 0; i--)
{
  if(i!=0)

when you can just do

for(int i=limit;  i> 0; i--)

?

 
If you are still getting an array out of range error, check limit.
 
GumRai:
If you are still getting an array out of range error, check limit.

Hi with your suggestion I did i>0 so I don't need to check when i!=0 any more. 

I solved the issue. I made a silly mistake at the initialization that's why such thing...

Thank you. 

Reason: