Bar Index Help - page 3

 

With a supporting buffer I am failed to get the needed results. Don't know how to do it. (Please check the 1st page)

I get back to my old coding with simplifying with counter. But results are still same. 

 int counter = 0;      
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)))
 {
   counter++;
   buffer[i] = iLow(Symbol(),0,iLowest(Symbol(),0,MODE_LOW,counter,i));  
   
 }
 counter = 0;
}
 

 

 
 if((iHigh(Symbol(),0,i-1) >= iHigh(Symbol(),0,i) && iLow(Symbol(),0,i-1) >= iLow(Symbol(),0,i)))
  1. Stop looking at future values.
  2. Simplify your code. iHigh(_Symbol,0, x) == High[x] Why use a function call instead of a Predefined Variables - MQL4 Reference
  3.  int counter = 0;      
    for(int i=limit;  i> 0; i--)
    You can't initialize counter like that. It must be set to the value it had the last time i==limit.


 
WHRoeder:
  1. Stop looking at future values.
  2. Simplify your code. iHigh(_Symbol,0, x) == High[x] Why use a function call instead of a Predefined Variables - MQL4 Reference
  3. You can't initialize counter like that. It must be set to the value it had the last time i==limit.


For 1. about future value, then how can I check Higher Higher Lower Low?

I simplified my code, about initializing counter, i==limit generally happens one time when the loop started.

for(int i=limit;  i> 0; i--)
{
  if(i == limit) counter = 0;
 if(((High[i-1] >= High[i]) && (Low[i-1] >= Low[i])))
 { 

   counter++;
   buffer[i] = iLow(Symbol(),0,iLowest(Symbol(),0,MODE_LOW,counter,i));   
   
 }
 
 if((High[i-1] <= High[i] && Low[i-1] <= Low[i]) )
 { 
  
   counter++;
   buffer[i] = iHigh(Symbol(),0,iHighest(Symbol(),0,MODE_HIGH,counter,i));
  
   }

 counter = 0;
 
 }

 Any coding example to solve the issue?

Thank you 

 
  1. cashcube: For 1. about future value, then how can I check Higher Higher Lower Low?
    Compare the current (calculating) bar to the previous one, not to the future one.
  2. cashcube: I simplified my code, about initializing counter, i==limit generally happens one time when the loop started.

    You've never shown your calculation of limit.

    If you've done it in the standard way, the first time you did all bars (to 0). The next tick limit would be zero, and you just update bar zero.

    Shouldn't counter be initialized to the same value it had the previous run for bar zero? Not zero!

 
WHRoeder:
  1. cashcube: For 1. about future value, then how can I check Higher Higher Lower Low?
    Compare the current (calculating) bar to the previous one, not to the future one.
  2. cashcube: I simplified my code, about initializing counter, i==limit generally happens one time when the loop started.

    You've never shown your calculation of limit.

    If you've done it in the standard way, the first time you did all bars (to 0). The next tick limit would be zero, and you just update bar zero.

    Shouldn't counter be initialized to the same value it had the previous run for bar zero? Not zero!

This is how I did my Limit calculation:

int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+1;

 Am i wrong here? if yes then I will use your suggested code with MathMax

you suggested compare the current bar to the previous one, as its backward loop. So this is how I did. If limit = 100 then High[100] <= High[99] 

 if(((High[i] <= High[i-1]) && (Low[i] <= Low[i-1])) )

 Result is same. If you don't mind then can you share code please if above coding is wrong.

 Shouldn't counter be initialized to the same value it had the previous run for bar zero? Not zero!

 Please check my limit calculation, any coding example will be helpful in this case for counter.

 Thank you