Help to get lower price

 

Hi Guys, I want to get the lower bar price value for the period from any time the function is called to the previous 3 /for example/ higher TF bars. What I have missed in the code? This function is in cycle, and gets the lowerTF bar number in iValue.

Appreciated. Thank you in advance.

double LowLevel(int HighTF, int LowTF, int NumberBarsHighTF, int iValue)
{
   datetime time,TimeArray[];
   int i,Valueidx;
   double OrderArray[];
 
   for(i=0;i<NumberBarsHighTF;i++)
   {
      OrderArray[i]=iLow(NULL,HighTF,i);
   }
   
   int element_count=ArrayResize(OrderArray,NumberBarsHighTF);
 
   Valueidx=ArrayMinimum(OrderArray);

   return(OrderArray[Valueidx]);
}
 
elo15: Hi Guys, I want to get the lower bar price value for the period from any time the function is called to the previous 3 /for example/ higher TF bars. What I have missed in the code? This function is in cycle, and gets the lowerTF bar number in iValue. Appreciated. Thank you in advance.
What you're asking for is simple compare to what you're doing. You pass extra parameters you're not using. You're using a for loop for no good reason ... iBarShift() of the Highest_TF should be enough. You're using the array before giving it any size. You name an array OrderArray but nothing involving orders. You should probably read the book and get the basics.

https://book.mql4.com//
 
elo15:

Hi Guys, I want to get the lower bar price value for the period from any time the function is called to the previous 3 /for example/ higher TF bars. What I have missed in the code? This function is in cycle, and gets the lowerTF bar number in iValue.

Appreciated. Thank you in advance.

At this point . . .

 double OrderArray[];   //  zero elements size
 
   for(i=0;i<NumberBarsHighTF;i++)
   {
      OrderArray[i]=iLow(NULL,HighTF,i);
   }

. . . . your array has a size of zero elements.

 
elo15: What I have missed in the code?
double OrderArray[];
for(i=0;i<NumberBarsHighTF;i++) OrderArray[i]=iLow(NULL,HighTF,i);
int element_count=ArrayResize(OrderArray,NumberBarsHighTF);
  1. The array has no elements.
  2. Assigning values to a empty array does nothing.
  3. Resizing the array is fine but you never put any values in it.
  4. LowTF, time, andTimeArray[] are unused
 
ubzen:
ubzen:
What you're asking for is simple compare to what you're doing. You pass extra parameters you're not using. You're using a for loop for no good reason ... iBarShift() of the Highest_TF should be enough. You're using the array before giving it any size. You name an array OrderArray but nothing involving orders. You should probably read the book and get the basics.

https://book.mql4.com//

How I can use iBarShift() ? I would like to get the lower value for the last "
NumberBarsHighTF" bars. For example NumberBarsHighTF=3 .
 

How to use iBarShift().

void start(){
    LowestPrice(3,PERIOD_D1);
}


double LowestPrice(int NumberOfBars, int TimeFrame){
    int LowestBari=iLowest(Symbol(),TimeFrame,MODE_LOW,NumberOfBars,0);
    double ValueOf_LowestBari=iLow(Symbol(),TimeFrame,LowestBari);
    return(ValueOf_LowestBari);
}
Not tested.
elo15:
ubzen:
ubzen:
What you're asking for is simple compare to what you're doing. You pass extra parameters you're not using. You're using a for loop for no good reason ... iBarShift() of the Highest_TF should be enough. You're using the array before giving it any size. You name an array OrderArray but nothing involving orders. You should probably read the book and get the basics.

https://book.mql4.com//

How I can use iBarShift() ? I would like to get the lower value for the last "
NumberBarsHighTF" bars. For example NumberBarsHighTF=3 .
 
Thank you guys for your comments. ubzen I will test your proposal and reply.
 

Hi,

In order to use the function in cycle in indicator and in case I want to get the result for bars number 1, 17, 35, I added parameter i .


double LowestValue=LowestPrice(3,60,i);

and using function:

double LowestPrice(int NumberOfBars, int TimeFrame, int shift){
    int LowestBari=iLowest(Symbol(),TimeFrame,MODE_LOW,NumberOfBars,shift);
    double ValueOf_LowestBari=iLow(Symbol(),TimeFrame,LowestBari);
    return(ValueOf_LowestBari);
}

I get correct result only for the first bar, for the others bars the result values continue to get lower. Please advise for further updates.

Thank you.

 

just to correct myself - for the first bar the value is close but not as expected and for the others the deviation is becoming bigger.

 
elo15:

Hi,

In order to use the function in cycle in indicator and in case I want to get the result for bars number 1, 17, 35, I added parameter i

and using function:

I get correct result only for the first bar, for the others bars the result values continue to get lower. Please advise for further updates.

Thank you.

Learn from the book. Don't skip chapters. When you go past array let me know. It'll be easier to explain at that point.
 
double LowestValue=LowestPrice(3,60,i);
Where does i come from? It better be a PERIOD_H1 chart index and not the current chart index. Apples and Oranges
Reason: