Download MetaTrader 5

iLowest does not give the right shift...

To add comments, please log in or register
Bert
28
Bert  

In OnCalculate() I have a ArraySetAsSeries with reverse order

....
ArraySetAsSeries(open,false);
ArraySetAsSeries(high,false);
....

Then I want the Lowest Value over a specific range. I do this with:

x=low[iLowest(NULL,0,MODE_LOW,IdLastBullish-IdLastBearish,IdLastBearish)]

But this is not given me the correct value. I did a test for checking the program-line:

Alert (iLowest(NULL,0,MODE_LOW,16,12162));
Alert (low[iLowest(NULL,0,MODE_LOW,16,12162)]);
Alert (low[12178]);
Alert (low[12162]);

This gives me the values as shown in the attachment.

The red-arrow is the found value for low[12162] (plotted correctly by the program)
The green-arrow is the found value for low[12178] (plotted correctly by the program)
The blue-arrow is the found value for the lowest low in this range (plotted by the program)....?! Well this is ofcourse not the lowest low of this range.... but what I'm doing wrong??

I can't see what I'm doing wrong here..... :( Hope somebody gives me the light :D



Regards,

Fernando Carreiro
2279
Fernando Carreiro  

Use "ArrayMinimum()" and not "iLowest()" in this case specifically! "iLowest()" works directly on the full history data (ordered as a Series Array), and not on the "low[]" array passed to the "OnCalculate()" function.

ArrayMinimum() - https://docs.mql4.com/array/arrayminimum

whroeder1
14779
whroeder1  
RTFM

There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the predefined variables (e.g. Low[])

To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.



Bert
28
Bert  

Thanks!


It works perfectly!!

x = low[ArrayMinimum(low,IdLastBullish-IdLastBearish,IdLastBearish)]


To add comments, please log in or register