iHighest & iLowest MQl5

 

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

 

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


 

	          
 

This may seem to be a silly question, but

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

 

Haha indeed Mr. Watford.

I am still learning.

I certainly did try for a decent amount of time before asking and doing the above solution, but was unable to correctly interpret other posts/documentation instructions fully. 

There's no such thing as a silly question which I am sure my post/Question? could be interpreted as.

Is it a silly question to ask if it is a sillier question to ask why I don't use iHighest() and iLowest() or to answer the first silly question from me?

Are we at three silly questions now. 

I'm sure I could eventually develop a trading strategy based on our silly questions...We just need more data.

I will try again.