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.
https://docs.mql4.com/predefined/high
iHighest() returns the shift of where the highest price is observed for the defined periods.
https://docs.mql4.com/series/ihighest

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. 😉

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Archives

Visitors

Flag Counter
%d bloggers like this: