iLowest() giving the wrong candle ID

 

I am trying to get the lowest candle ID inside for loop 


Use case:

Step 1: i am using for loop to check candle ID of the candle on which the indicator is visible most recently, and then break the loop 
Step 2: i am using iLowest() to get the candle ID of the bar having the lowest value out of 5 ,
Step3 : using the candle id (from step 2) to get low value  of that candle and then calculate the SL for that candle.

But i am getting wrong ID of candle in Step 2.

please have a look at the attached screenshot, the comment of bar should be 74 but it shows 135 

What am i doing wrong ?

Here is my code :

for(int i=0;i<1000;i++)
           {
 
          double btt1= iCustom(NULL,0,"Arrows",0,i);
          double btt2= iCustom(NULL,0,"Arrows",1,i);
          
          if(btt1!=EMPTY_VALUE)
          
            {
 
             if(Digits==5|| Digits==3)
                   {
 
                  
                    baar =iLowest(NULL,0,MODE_LOW,5+i,i);
                    lowestb = Low[baar];
                    stoploss = lowestb- 20*Point*10; 
                     
                     Comment("value of i :  ",i,"    value of baar :  " , baar );
    
                     ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0);
                     ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,xx1x);
                     ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,yy1y);
                     ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 
                     ObjectSetString(chart_ID,name,OBJPROP_TEXT, stoploss   ); 
                     ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 
                     ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 
                     ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clrRed);            
                     ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
 
                   break;
                   }
                  
                   }
                   
                   }
Files:
 
iLowest(..., 5+i,...)

Check the docs and see if that is what you want. - I don't think this is what you explained.

 
Dominik Egert:
iLowest(..., 5+i,...)

Check the docs and see if that is what you want. - I don't think this is what you explained.

You are right , i  thought i could get the candle id having the lowest value in for loop , but it seems like iLowest and iHighest only works from current candle backwards , is there any way to get the lowest and highest value from past candles? 
like for example candle 50 candle 51 candle 52 candle 53 candle 54 are the candles that i am interested in and if i want to get the candle ID of the candle that has lowest low out of the 5 mentioned candles ? 
can this be acieved using iLowest ? or am i just wasting time trying to get it with this function ?
 
Shanty94:
You are right , i  thought i could get the candle id having the lowest value in for loop , but it seems like iLowest and iHighest only works from current candle backwards , is there any way to get the lowest and highest value from past candles? 
like for example candle 50 candle 51 candle 52 candle 53 candle 54 are the candles that i am interested in and if i want to get the candle ID of the candle that has lowest low out of the 5 mentioned candles ? 
can this be acieved using iLowest ? or am i just wasting time trying to get it with this function ?
baar =iLowest(NULL,0,MODE_LOW,5,50);

As Dominik said, you should read the documentation

Reason: