Highest and lowest value of indicator

 

Can anyone explain to me how I would set a custom indicator into a series array? I need to find the highest/lowest value of an indicator for a certain number of bars. I did read somewhere that explained I would need to place the indicator into a series array then do ArrayMaximum and ArrayMinimum to get the value for the highest and lowest values. But I have no idea how to do this?

I understand why it would need to be done, as the values of the custom indicator would need to be stored and sorted probably so that the function arraymaximum can find the value wheres it would not be able to do so if it wasnt a series array.

 

Declare an array, type double.

Set it as a series array.

Copy the indicator values to the array.

Perform ArrayMaximum and ArrayMinimum to find the array element index of the high/low

Extract the values from the array.

 
phy wrote >>

Declare an array, type double.

Set it as a series array.

Copy the indicator values to the array.

Perform ArrayMaximum and ArrayMinimum to find the array element index of the high/low

Extract the values from the array.

I am trying to use the ArrayMaximum and ArrayMinimum functions to identify the max & min of a array. But I am not sure how the index is determined when there are multiple highs or lows. To give an example, I am producing the code from the help:

double num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9};
int    maxValueIdx=ArrayMaximum(num_array);
Print("Max value = ", num_array[maxValueIdx]);
The index is 4 in this case. But why not 9 & 15?
 

The index is 4... meaning that num_array[4] contains the high value.

Why not index 9 or 15? The question is "what is the highest value". The answer is 9, which can be found in index 4

 
Agreed Phy. But the highest value can also be found at index 9 & 15. So, is it safe to assume that the first index corresponding to the highest value is returned by ArrayMaximum? If I need to find as many index as possible representing the highest value, how do I get them? Thanks for the help.
 
highrise wrote >>
Agreed Phy. But the highest value can also be found at index 9 & 15. So, is it safe to assume that the first index corresponding to the highest value is returned by ArrayMaximum? If I need to find as many index as possible representing the highest value, how do I get them? Thanks for the help.

Correction: Other indices are 9 & 14 and not 15.

Any ideas on how to get this?

 
//+------------------------------------------------------------------+
//|                                         HighsLowsSignalAlert.mq4 |
//|         Copyright © 2006, Robert Hill                            |
//+------------------------------------------------------------------+

/*
  +------------------------------------------------------------------+
  | Allows you to enter a number and it will then show you at        |
  | which point that many higher highs/higher lows or                |
  | lower highs/lower lows candles occur.                            |
  | It also give an alert if the current bar has the                 |
  | required number of candles before it.                            |
  +------------------------------------------------------------------+
*/   
#property copyright "Copyright © 2006, Robert Hill"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red
#property indicator_width1 3
#property indicator_width2 3

extern bool SoundON=true;
extern int HowManyCandles = 3;

double TrendUp[];
double TrendDown[];
double alertTag;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//   IndicatorBuffers(4);
   SetIndexStyle(0, DRAW_ARROW, EMPTY, 3);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, TrendUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY, 3);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, TrendDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double Range, AvgRange;
   int HigherHighs,HigherLows;
   int LowerHighs,LowerLows;
   
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
      
      HigherHighs=0;
      HigherLows=0;
      LowerHighs=0;
      LowerLows=0;
      for (counter=i;counter<i+HowManyCandles;counter++)
      {
         if (High[counter] > High[counter+1]) HigherHighs++;
         if (Low[counter] > Low[counter+1]) HigherLows++;
         if (High[counter] < High[counter+1]) LowerHighs++;
         if (Low[counter] < Low[counter+1]) LowerLows++;
      }
      
      if (HigherHighs == HowManyCandles && HigherLows == HowManyCandles)
      {
         TrendUp[i] = Low[i] - Range*0.75;
         if ( alertTag!=Time[0])
         {
          PlaySound("news.wav");// buy wav
          Alert(Symbol(),"  M",Period(),HowManyCandles," HigherHighs/HigherLows");
         }
          alertTag = Time[0];
          
      }
      else if (LowerHighs == HowManyCandles && LowerLows == HowManyCandles)
      {
         TrendDown[i] = High[i] + Range*0.75;
         if ( alertTag!=Time[0])
         {
          PlaySound("news.wav"); //sell wav
           Alert(Symbol(),"  M",Period(),HowManyCandles," LowerHighs/LowerLows");
         }
          alertTag = Time[0];
      }
   }
   return(0);
}

 

Any ideas on how to get this?

   double x = array[ArrayMaximum(array)];

   for(i = 0; i < ArraySize(array); i++){

      if(array[i] == x) FoundOneDoSomething();

   }