You're reading...
EA development, MQL4

MQL4: Get the highest price of a set number of periods, candles, bars

High[x] returns the high price of the period at shift x.
iHighest() returns the shift of where the highest price is observed for the defined periods.

Combine them to obtain the highest price for the defined periods:

double highestPrice = High[iHighest(Symbol(), 0, MODE_HIGH, 10, 1)];

In this example, the last parameter being “1” means it starts to look 1 period before the current period, which is indexed as “0”, and the second last parameter being “10” means it searches for 10 periods backwards. That is, it searches periods indexed 1,2,3,4,5,6,7,8,9,10.

In this very example, the high of periods 6 and 7 are identical. The return of iHighest(Symbol(), 0, MODE_HIGH, 10, 1) is the later index, i.e. 7.
This point is not made anywhere else on the web. I suspect it’s because it’s rather rare for high prices to be identical, and more probably that it’s not materially impactful enough for anyone to bother. But here you go. 😉



Comments are closed.



Flag Counter
%d bloggers like this: