How to get the last X bars?

How to get the High of the last 5 bars?

THANKS

Here are two ways to find previous 5 bar high. Both have not been tested and I hope are correct.

input int PastBars = 5;  // Number of past bars to find highest bar.
double High[];
double BarHigh=0;       // Highest bar value from PastBars range.

ArraySetAsSeries(High,true);
int copied=CopyHigh(symbol,0,0,PastBars),High);
if(copied>0 && PastBars<copied) BarHigh=High[PastBars];
Print("Highest bar value from previous ",PastBars," bars is ",BarHigh);

Can use following code to find Open, High, Low, Close and Tick_Volume values.

input int PastBars = 5;  // Number of past bars to find highest bar.
double BarHigh = 0;     // Highest bar value from PastBars range.

MqlRates rates[];
ArraySetAsSeries(rates,true);
double copied=0;
copied=CopyRates(Symbol(),0,0,PastBars,rates);
   
if(copied>0)
  {
    double size=fmin(copied,PastBars);
    for(int i=0;i<size;i++)
      {
         If(rates[i].high > BarHigh) BarHigh=rates[i].high;
      }
  }
Print("Highest bar value from previous ",PastBars," bars is ",BarHigh);

thankyou to wavkena, it seems to be do more in mql5~ ~

Absolutly!!!

this comment was deleting now they are censoring bad comments about MQL5!!

Metaquotes you are just one point to loose client, One minipoint!

The more I learn about MQL5 the more I hate it. And now you are censoring bad comments regarding it. Just started learning the language a week ago and I cant believe how many stupid decisions where made regarding the compatibility and easy access for users of MT4 to the new language.

Horrible!

Learn the lesson and change soon instead of censoring.