Store highest and lowest prices in an array

 
double maxValues[50];
      ArrayInitialize(maxValues,0);
      //double temp;
      
      for (i = 0; i < candles; i++)
      {
         max = High[iHighest(NULL, 0, MODE_HIGH, WHOLE_ARRAY, i)];
         maxValues[i] = max;
         
          
      }
            
      Comment("" + maxValues[i]);

I'm trying to store the highest prices from 20 candles in this code snippet, but I don't seem to get it done. I'd like to know what's wrong with it... Or is it another way to actually get it done? Thanks in advance. 

 

You can use the built in function ArrayMaximum(), ArrayMinimum().

But be aware of the orientation shown here: https://www.mql5.com/en/docs/series/copybuffer.

Check carefully!

Documentation on MQL5: Array Functions / ArrayMaximum
Documentation on MQL5: Array Functions / ArrayMaximum
  • www.mql5.com
//| Filling the basic part of the candlestick                        | //
 

There is no need for a loop you can just retrieve the value right away.

int index_high = iHighest(NULL, 0, MODE_HIGH, 20, 0);
double max = High[index_high];

Print(max);

See here https://docs.mql4.com/series/ihighest

iHighest - Timeseries and Indicators Access - MQL4 Reference
iHighest - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iHighest - Timeseries and Indicators Access - MQL4 Reference
 
Carl Schreiber:

You can use the built in function ArrayMaximum(), ArrayMinimum().

But be aware of the orientation shown here: https://www.mql5.com/en/docs/series/copybuffer.

Check carefully!

Thank you!

I tried that with tha code snippet and it didn't work:(

Also what I want to do, is store the price so I can later write the condition that if I am in an up trending, the Close[1] has to be > than the Highest price I stored in that array. That's what I want to do

Any idea of how can I get it done? 

 
Marco vd Heijden:

There is no need for a loop you can just retrieve the value right away.

See here https://docs.mql4.com/series/ihighest

Thank you for your reply, but I as I mentioned above, I want to store the highest value so I can later use it with a condition that I don't want to place an order if the Close[1] has not been greater than the calculated Highest price, any idea on how to that based on the code snippet?
 
Ricardos:
Thank you for your reply, but I as I mentioned above, I want to store the highest value so I can later use it with a condition that I don't want to place an order if the Close[1] has not been greater than the calculated Highest price, any idea on how to that based on the code snippet?

Since close[1] is incorporated into the 20 candles that condition is never going to become truth.

So you have to omit that candle from the calculation this means you start at candle 2.

int start_candle = 2;
int stop_candle  = 20;

int index_high = iHighest(NULL, 0, MODE_HIGH, stop_candle, start_candle);
double highest = High[index_high];
 
if(Close[1] > highest)
 { 
  // Order Something...
 }
 

Thanks for the response once again

I get that, but since the price will change every 20 candles, will the variable "highest" store every single highest Price?

I attached an image of an example. What I really want is  the Close[1] to be greater than the "last" highest. In the picture I drew an Horizontal line for you to see the highest and  below that I drew  an up trend showing that the Close[1] has to be greater than that last highest as shown in the picture. In other words, for me to open a buy trade the Close[1] has to be above the horizontal line. Is this what I show possible? That's why I wanted to store the values in an array so that I could access them.

Thank you in advance, I hope you can help me, I'm struggling a lot:(

Files:
a.png  3 kb
Reason: