GetExtremums – library MetaTrader 5

The GetExtremums() function is designed to identify extremums over a given period of history. The search algorithm is similar to that used in the FastZZ indicator and uses only one parameter – the minimum price change – to identify an extremum.

int GetExtremums(double range,      //minimum price change
                 MqlRates &rates[], //array of history quotes
                 dextremum &ge[],  //returned array of extremums
                 int total=0)      //required number of extremums or zero for all extremums        
Parameters:
  •     double range – minimum price change required to identify an extremum;
  •     MqlRates &rates[] – array of quotes;
  •     dextremum &ge[] – array that stores identified extremums in consecutive order, the extremum closest in time being stored in the first element (0 index).
  •     int total – limit for the total number of extremums to be found. All extremums are searched for by default (total==0).
Returned value:
  •     Number of elements in the array of extremums.

The following structure is used for the description of extremums.

Alternative:   T3 floating levels (2) - indicator MetaTrader 5
struct dextremum         //description of extremum
{
   int        type;      //1 - peak, -1 - trough
   datetime   time;
   double      value;
};

An example of using GetExtremums().

#include <GetExtremums.mqh>
//----
void OnStart()
{
   MqlRates rt[];
   dextremum zz[];
   CopyRates(_Symbol,_Period,TimeCurrent(),100,rt);
   //the first variant - to get 10 extremums
   int cnt=GetExtremums(100*_Point,rt,zz,10);
   for(int i=0; i<cnt; i++)
        Print(i,") ",zz[i].time," >> ",zz[i].type==1?"Peak":"Trough","=",zz[i].value);
   //the second variant - to get all extremums 
   cnt=GetExtremums(100*_Point,rt,zz);
   Print("Found ",cnt," extremums");
}
//----


📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks