Download MetaTrader 5

how to specific High[5] in MQL5?

To add comments, please log in or register
LEE Chun Wing
831
LEE Chun Wing  

I want to get the last 5 bar high in MQL5

 how to do it? 

 

THANKS 

Wackena
648
Wackena  
kelly posted  :

I want to get the last 5 bar high in MQL5

 how to do it? 

 

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);
LEE Chun Wing
831
LEE Chun Wing  
wackena:

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

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

 

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

To add comments, please log in or register