Getting maximum and minimum of the last 20 Bars

To add comments, please log in or register
mtsTrader
49
mtsTrader  

Hello all,

weeks ago I had a C-programming training. Now I will start to learn MQL5. I read some tutorials but I don`t know how I can get the maximum and minimum of bars to copy them into an own array.

Concretely I would like to create an array (e.g. double array_maximum[20]) and safe the maxima of the last 20 bars in that array.

 

Can someone please tell me which function I need to get the maxima of the last bars?

Alain Verleyen
38124
Alain Verleyen  
mtsTrader:

Hello all,

weeks ago I had a C-programming training. Now I will start to learn MQL5. I read some tutorials but I don`t know how I can get the maximum and minimum of bars to copy them into an own array.

Concretely I would like to create an array (e.g. double array_maximum[20]) and safe the maxima of the last 20 bars in that array.

 

Can someone please tell me which function I need to get the maxima of the last bars?

Welcome to mql5.com forum,

The maxima of a bar is high price, so for the maxima of the last 20 bars :

  double maxima[];
  CopyHigh(_Symbol,PERIOD_CURRENT,1,20,maxima);

Is it what you asked for ?

mtsTrader
49
mtsTrader  

Thank you for promp reply. Thats exactly what I asked for!


Thank you!

Jose Miguel Soriano
5046
Jose Miguel Soriano  
mtsTrader:

Thank you for promp reply. Thats exactly what I asked for!


Thank you!

//+---------------------------------RETORNA EL MAYOR VALOR DE nBARRAS----------------------+
double iHighest(string simb, ENUM_TIMEFRAMES marcoTmp, int modo, int nBars, int nVela= 0)
{
   double resp= 0, arPrecios[];
   ulong arVolum[];
   int posicion=0, nCopiado= 0;
   ArrayResize(arPrecios, nBars);
   ArrayResize(arVolum, nBars);
   ArraySetAsSeries(arPrecios, true);
   ArraySetAsSeries(arVolum, true);
   switch(modo)
     {
      case 0 :
         nCopiado= CopyOpen(simb,marcoTmp,nVela,nBars,arPrecios);
         break;
      case 1 :
         nCopiado= CopyClose(simb,marcoTmp,nVela,nBars,arPrecios);
         break;
      case 2 :
         nCopiado= CopyHigh(simb,marcoTmp,nVela,nBars,arPrecios);
         break;
      case 3 : 
         nCopiado= CopyLow(simb,marcoTmp,nVela,nBars,arPrecios);
         break;
      case 4 :
         nCopiado= CopyTickVolume(simb,marcoTmp,nVela,nBars,arVolum);
         break;
      case 5 :
         nCopiado= CopyRealVolume(simb,marcoTmp,nVela,nBars,arVolum);
         break;
     }
     if(nCopiado==nBars)
     {
        if(modo<4)
        {
           posicion= ArrayMaximum(arPrecios,0,WHOLE_ARRAY);
           resp= arPrecios[posicion];
        }
        else
        {
           posicion= ArrayMaximum(arVolum,0,WHOLE_ARRAY);
           resp= arVolum[posicion];
        }
     }
   return(resp);
}
To add comments, please log in or register