iHighest & iLowest MQl5

Anwar Ben
14
Anwar Ben  

Hi there,


I am trying to find the highest & lowest closes for the last five bars in an array excluding bar 0.


So far I have this. Can someone please double check this is correct. MQL5


//      Create array of price data
        MqlRates priceInfo[];

//      Sort array from current candle downwards
        ArraySetAsSeries(priceInfo,true);

//      Fill array with price data
        int priceData=CopyRates(_Symbol,_Period,0,6,priceInfo);

//      create empty int's to hold highest and lowest values of last five bars
        int highFive;
        int lowFive;

//      Find highest and lowest close of last five bars excluding bar 0 (current bar) and populate highFive and lowFive with those values
        highFive = priceInfo[iHighest(_Symbol,Period_M5,MODE_CLOSE,5,1)];
        lowFive = priceInfo[iLowest(_Symbol,Period_M5,MODE_CLOSE,5,1)];




For some reason I am getting an error '=' - illegal operation use when attempting to set highFive and lowFive values.


Any help would be appreciated.


Thanks in Advance

Anwar Ben
14
Anwar Ben  

SOLVED: PS This forum kinda had the answer but was too specific and focusing on lines of code not an overall example which worked straight away...

For example


//+------------------------------------------------------------------+
//|                           Highest Close FOr previous Candles.mq5 |
//|                                Copyright 2020, Anwar Ben Goulouh |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Anwar Ben Goulouh"
void OnTick()
        {
                //int for the bar number which is has highest close
                int HighestClosingBar;

                //Array to hold closes or opens or highs or whatever
                double closeArray[];

                //Array to hold all data
                MqlRates ratesData[];

                //Sort Arrays downwards
                ArraySetAsSeries(closeArray,true);
                ArraySetAsSeries(ratesData,true);

                //Copy CloseData starting at previous bar and counting back for 5 bars
                CopyClose(_Symbol,_Period,0,5,closeArray);

                //Copy all data to data array
                int priceData=CopyRates(_Symbol,_Period,0,5,ratesData);

                //Set HighestClosingBar int with the bar number which has the highest close 
                HighestClosingBar=ArrayMaximum(closeArray,0,5);

                //Get the actual close value for the bar with the highest close and set a variable with the value
                double closeRate=ratesData[HighestClosingBar].close;

                //Comment to prove it works
                Comment ("High Candle Number: ", HighestClosingBar, "\n",
                               "High Candle Close Value: ", closeRate
                              );

        }

Can be used for all bar data close, high, low, open, real_volume, spread, tick_volume, time

simply replace CopyClose with CopyHigh etc

and 

ratesData[HighestClosingBar].close;
with
ratesData[HighestClosingBar].High;
etc


 
Keith Watford
Moderator
26186
Keith Watford  

This may seem to be a silly question, but

why don't you just use iHighest() and iLowest() ?