Find the highest value of an indicator in a period X

rodrigosm
362
rodrigosm  

Hi,

I'm trying to find a value for the RSI highest value in 20 bars.

I can't use "iHighest(NULL,0,RSI_Buffer[i],20,i), because it accepts only OPEN/LOW/HIGH/CLOSE/VOLUME/TIME. How can I find it?

Thanks

hasayama
697
hasayama  
iHigh is for prices only. Use iRSI for rsi value.
rodrigosm
362
rodrigosm  
hasayama:
iHigh is for prices only. Use iRSI for rsi value.

Yeah, but I'm trying to get the RSI highest value. I don't understand how to do this, since the parameters does not show any tip to do a reference to highest value in a period.

Do I need to change something on 'Shift" parameter? Like this : iRSI(NULL,0,periodoRSI,PRICE_CLOSE,(iHighest(NULL,0,MODE_HIGH,periodo,i))?


Thanks hasayama

hasayama
697
hasayama  

You need rsi on highest bar or highest rsi?

Just loop through all values and search max value.

double max_rsi = 0;
double tmp = 0;

//--to find max rsi between current bar and NUMBER_OF_BARS bar

for ( int i = 0; i < NUMBER_OF_BARS; i ++ )
{
   tmp = iRSI( Symbol(), Period(), perRSI, PRICE_CLOSE, i );
   if ( tmp > max_rsi ) { max_rsi = tmp; }
}
zzuegg
1503
zzuegg  

be creative:

option 1: create a array filld with the RSI values and use iHighestOfArray

option 2: write your own function here is pseudo code:

function findHighestRSI 
currhigh = 0
for i=0 i<20 i++
if RSI(i)>currhigh then currhigh = RSI(i)
return currhigh
rodrigosm
362
rodrigosm  
hasayama:

You need rsi on highest bar or highest rsi?

Just loop through all values and search max value.


I need the highest RSI value. I understood what you wrote, but when I implemented this, the value was always the same, didn't change never. I tried a loop inside a loop, but It returned no value, I'm probably doing some mistakes.

zzuegg
1503
zzuegg  
rodrigosm:

I need the highest RSI value. I understood what you wrote, but when I implemented this, the value was always the same, didn't change never. I tried a loop inside a loop, but It returned no value, I'm probably doing some mistakes.


let us see some code


//z

rodrigosm
362
rodrigosm  
zzuegg:

be creative:

option 1: create a array filld with the RSI values and use iHighestOfArray

option 2: write your own function here is pseudo code:


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.

rodrigosm
362
rodrigosm  
zzuegg:

let us see some code


//z


I'm trying to do a RSI divergence indicator. I stopped in this part (search for the highest RSI value of 20 periods)

Here it is the code:

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

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

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

SetIndexBuffer(2,RSI_Buffer); 
SetIndexBuffer(3,a1_Buffer); 
SetIndexBuffer(4,a2_Buffer); 
SetIndexBuffer(5,b1_Buffer); 
SetIndexBuffer(6,b2_Buffer);    
   
//--- 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()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

//---- Current RSI value
      for(int i = 0; i<limit; i++) 
         RSI_Buffer[i]=iRSI(NULL,0,periodoRSI,PRICE_CLOSE,i);
//---- Highest price in 20 periods         
      for(i = 0; i<limit; i++)   
         a1_Buffer[i]=High[iHighest(NULL,0,MODE_HIGH,periodo,i)];
//---- Highest RSI value in 20 periods 
hasayama
697
hasayama  

Well I haven't tested my code, just gave you an idea. It will return just one value - max rsi which was reached from 0 (current bar) to some spesified bar, as your "limit".

Run it in loop for 10 values (from 0 to 9th bar) and check the result inside Data Window.

William Roeder
25379
William Roeder  
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);