Download MetaTrader 5
To add comments, please log in or register
Unable to find the answer to your question? Use the search!
Elo
82
Elo 2013.12.11 17:16 

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]);
}
Ubzen
Moderator
5394
Ubzen 2013.12.11 18:06  
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/
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.12.11 18:07  
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.

whroeder1
13610
whroeder1 2013.12.11 18:09  
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
Elo
82
Elo 2013.12.11 19:19  
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 .
Ubzen
Moderator
5394
Ubzen 2013.12.11 19:34  

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 .
Elo
82
Elo 2013.12.12 06:30  
Thank you guys for your comments. ubzen I will test your proposal and reply.
Elo
82
Elo 2013.12.12 09:35  

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.

Elo
82
Elo 2013.12.12 09:43  

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.

Ubzen
Moderator
5394
Ubzen 2013.12.12 09:48  
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.
whroeder1
13610
whroeder1 2013.12.12 14:16  
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
/ /12
To add comments, please log in or register