Find the highest value of an indicator in a period X - page 2

 
WHRoeder:

int ArrayMaximum( double array[], int count=WHOLE_ARRAY, int start=0)

Searches for the element with maximum value. The function returns position of this maximum element in the array.

It will be the index of the element, not the element itself.

 
rodrigosm:

zzuegg, thanks for the help. I'm beginner, but I'll study how to do that you wrote. I think the first one is easier, but I still not knowing how to implement this in my formula. If possible, give me an example.


Thanks again.


i think option 2 is easier. He already gave you the pseudocode you need. just replace the function header, put in some brackets, and replace RSI(i) with the iRSI function. Pretty straightforward and there's no need to mess with additional arrays. This is how i would do it.
 
hasayama:
int ArrayMaximum( double array[], int count=WHOLE_ARRAY, int start=0)

Searches for the element with maximum value. The function returns position of this maximum element in the array.

It will be the index of the element, not the element itself.


Yeah, I tested it and did not work.
 
hasayama:
int ArrayMaximum( double array[], int count=WHOLE_ARRAY, int start=0)

Searches for the element with maximum value. The function returns position of this maximum element in the array.

It will be the index of the element, not the element itself.

So think for a change
for(int i = limit-1; i>=0; i--) // Count down for one pass 
     RSI_Buffer[i]=iRSI(NULL,0,periodoRSI,PRICE_CLOSE,i);
//   a1_Buffer[i] = ArrayMaximum(RSI_Buffer, 20, i);
     a1_Buffer[i] = RSI_Buffer[ArrayMaximum(RSI_Buffer, 20, i)];
 
WHRoeder:
So think for a change

Thanks... worked very well this change! I didn't know that it was allowable.

a1_Buffer[i] = RSI_Buffer[ArrayMaximum(RSI_Buffer, 20, i)];

Great job. I will finish the indicator and post here.

 

Thanks everybody! I finished the indicator.


//+------------------------------------------------------------------+
//|                                                  Divergência.mq4|
//|                      Copyright © 2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright 
#property link      

#property indicator_separate_window
#property indicator_minimum -1
#property indicator_maximum +1
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 LawnGreen
//-Parametros
extern int periodo=20;
extern int periodoRSI=20;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double RSI_Buffer[];
double RSI_Buffer2[];
double a1_Buffer[];
double a2_Buffer[];
double b1_Buffer[];
double b2_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(8);
//--- Internal Variables   

SetIndexBuffer(2,RSI_Buffer); 
SetIndexBuffer(3,a1_Buffer); 
SetIndexBuffer(4,a2_Buffer); 
SetIndexBuffer(5,b1_Buffer); 
SetIndexBuffer(6,b2_Buffer); 
SetIndexBuffer(7,RSI_Buffer2);    
   
//--- Plot a line   
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {
     
//---- last counted bar will be recounted
   int counted_bars = IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;


//---- Current RSI value
      for(int i = limit-1; i>=0; i--)// Count down for one pass 
         RSI_Buffer[i]=iRSI(NULL,0,periodoRSI,PRICE_CLOSE,i);
//---- Highest price in 20 periods         
      for(i = limit-1; i>=0; i--)// Count down for one pass 
         a1_Buffer[i]=High[iHighest(NULL,0,MODE_HIGH,periodo,i)];
//---- Highest RSI value in 20 periods                  
      for(i = limit-1; i>=0; i--) // Count down for one pass 
         a2_Buffer[i] = RSI_Buffer[ArrayMaximum(RSI_Buffer, periodo, i)];
//---- Lowest price in 20 periods
      for(i = 0; i<limit; i++)   
         b1_Buffer[i]=Low[iLowest(NULL,0,MODE_LOW,periodo,i)];
//---- Lowest RSI value in 20 periods
      for(i= limit-1; i>=0; i--)
         b2_Buffer[i] = RSI_Buffer[ArrayMinimum(RSI_Buffer, periodo, i)];
         
//---- Bullish Divergence 
      for(i= limit-1; i>=0; i--)
      {
         if((Close[i]<=b1_Buffer[i] && RSI_Buffer[i]>b2_Buffer[i]) || (RSI_Buffer[i]<=b2_Buffer[i] && Close[i]>b1_Buffer[i]))
            ExtMapBuffer1[i]=-1;
            else
               ExtMapBuffer1[i]=0;
               
      }          
      
//---  Bearish Divergence      
      for(i= limit-1; i>=0; i--)
      {
         if((Close[i]>=a1_Buffer[i] && RSI_Buffer[i]<a2_Buffer[i])|| (RSI_Buffer[i]>=a2_Buffer[i] && Close[i]<a1_Buffer[i]))
            ExtMapBuffer2[i]=1;
            else
               ExtMapBuffer2[i]=0;
      
      }
        
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

hi i need a code for EA based mainly not for indiactor or script only for EA code

RSI for

RSI >40 means BUY

and

RSI<20 means SELL

am new to mt4.so plss help me frnds..... thank u all

 

Hi guys,

I am a newbie and I need a code to determine the value of RSI at the end of each period (at the end of M1, M5, ....)

Thanks in advance 

 
newcoder:

Hi guys,

I am a newbie and I need a code to determine the value of RSI at the end of each period (at the end of M1, M5, ....)

Thanks in advance 

So use the code published in this thread . . . .  if that doesn't meet your needs you are off topic and shouldn't be posting in this thread.
 

I want to determine the value of a custom indicator at the end of each period (at the end of M1, M5, ....), 

I want to find the value of X= value of the buffer at the end of each periode (M1, M5, M15,....)

 

Please help 

Reason: