Identifying Ranging from Trending Markets

 

I want to tell MT4 market is ranging by comparing the Average Range for the last N period/days against the High and Low for the last N period/days.

Getting the Average Range I can do using

for (NPeriod=shift ; Nperiod<=shift+11; Nperiodr++) {
AvgRange=AvgRange+(High[Nperiod]-Low[Nperiod]);

But how do i tell MT4 what the High and Lows are for the last N period/days?

Hope someone out there can help me out.

 

A) consider using iATR for Average Range (it takes gaps into account)

B)

double highestLast14 = High[iHighest(NULL, 0, MODE_HIGH, 14, index)];
double lowestLast14  = Low [iLowest (NULL, 0, MODE_LOW , 14, index)];

NB Just typed, not compiled or checked

Reason: