MQL4 - automated forex trading   /  

Forum

Highest and lowest value of indicator

Back to topics list To post a new topic, please log in or register

avatar
22
fryfly 2008.08.12 21:27 

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.

article

Interview with Thomas Bopp

Thomas Bopp is the Jury Member representing the TRADERS' magazine. In his interview, he tells where and how he studied technical analysis, as well as about his work at Der Zyklus-Analyst. Thomas has also revealed some details of his own Expert Advisor and his estimation of the Automated Trading Championship 2006.


avatar
2462
phy 2008.08.12 22:06 

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.


avatar
18
highrise 2008.11.01 06:42 
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?

avatar
2462
phy 2008.11.01 07:00 

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


avatar
18
highrise 2008.11.01 07:20 
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.

avatar
18
highrise 2008.11.05 06:30 
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?


avatar
128
Mehmet 2008.11.05 06:58 
//+------------------------------------------------------------------+
//|                                         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);
}



avatar
2462
phy 2008.11.05 10:32 

Any ideas on how to get this?

   double x = array[ArrayMaximum(array)];

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

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

   }



Back to topics list  

To add comments, please log in or register