how do i code a counter the amount of candles since the last lowest low.

 

ive been trying to make an indicator but am stuck on this one part. below is the code ive been trying


   int i;

   int limit = 100;

   int test = 0; 

int OnInit()

  {

   return(INIT_SUCCEEDED);

void OnDeinit(const int reason)

  {

  }

void OnTick()

  {   

  int lowest = iLowest(NULL,0,MODE_LOW, limit,0);

 

   for(i=1; test=lowest||i<limit; i++);

      test = iLowest(NULL,0,MODE_LOW, i,0);

   if(test=lowest);

   Alert(i);

  }

 
SladeMcBride:

ive been trying to make an indicator but am stuck on this one part. below is the code ive been trying

Couple of issues:

(1) prices are 'double', not 'int'.

(2) '=' is used when you assign a value to a variable, whereas '==' is used when you want to compare two values/variables;

(3) ';' indicates to the compiler that your statement has ended, so it should not appear after 'for' and 'if';

(4) enclose related statements in {} - such as for statements within the same 'for' loop, or 'if' statement.

So the highlighted parts in this code segment requires some fixing:

for(i=1; test=lowest||i<limit; i++);
{
      test = iLowest(NULL,0,MODE_LOW, i,0);

   if(test=lowest);

   Alert(i);
}

Also, using iLowest within the 'for' loop is not efficient since it'll be going through ALL candles from 0 to i again, every time.

Anyway, here's what I think should work better:

double test = 0; 

void OnTick()
  {   
   double lowest = iLowest(NULL,0,MODE_LOW, limit,0);

   for(i=0; i<limit; i++)
   {
      test = iLow(NULL,0,i);
      if(test==lowest)
         Alert(i);
   }
  }
 

If you want the lowest low bar number of all the data on chart simply use ArrayMinimum(Low,0,0) - it will return you the bar number of the lowest low