How to get the position of highest or lowest point of Indicator?

 

I am looking for a method to get the position of highest or lowest point of Indicator(MACD,etc) from a period(for example from 0 to 30 bars), when i found out the point of a indicator from them,i also want to know the number of the bar it corresponded. it's so kind of you telling me how to find it out, I'm a new one, at present, I only know how to found out a highest or lowest bar from a period, and the indicator point they corresponded,but it seems not what I am looking for.

 

look at the indicator data for each bar, see if it is higher than any other data you've seen, if it is, remember the bar number.

int theBar;
double theHighest;

for(int i = 0; i <= 30; i++){

   if( theIndicatorData[i] > theHighest ) {

      theHighest = theData;
      theBar = i;
   }
}
 

Thank you very much for fast reply, I'm a beginner, let me study it first, and i will be back later .

 
phy:

look at the indicator data for each bar, see if it is higher than any other data you've seen, if it is, remember the bar number.


Dear Sir:

I nearly understand your mean, I'm a beginner and cannot write it the code out by myself at present, will you please give me a complete code? sorry for demanding that, i want to serch the highest point of RSI indicator from nearest 30 bars, will you help me to do that?

 
int theBar;
double theHighest;
for(int i = 0; i <= 30; i++){
   double rsi = iRSI(NULL,0,14,PRICE_CLOSE, i);
   if( rsi > theHighest ) {
      theHighest = rsi;
      theBar = i;
   }
}
 
WHRoeder:

thank you very much, they work very on Rsi, but they seems won't work on the indicators which have 2 buffers, such as Macd and Stochastic, will you please write a code about them for me?
 

thank you very much, It work very well on Rsi, but they seems won't work on the indicators which have 2 buffers, such as Macd and Stochastic, will you please write a code about them for me?

int theBar;
double theHighest;
for(int i = 0; i <= 30; i++)
{
   double mac;
   //stoch=iStochastic(NULL,0,5,3,3,MODE_SMA,1,MODE_MAIN,i);
   mac=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
   //rsi = iRSI(NULL,0,14,PRICE_CLOSE, i);
   if( mac > theHighest ) 
   {
      theHighest = mac;
      theBar = i;
   }

 

Thank you very much for you all, it has worked,it's nice of both of you to help me about that.

 

When I looking for the highest, it work well, when i looking for the lowest, it won't work, will you teach me how to repair it ?

int theBar;
double thelowest;
for(int i = 0; i <= 30; i++)
{
   double rsi; rsi = iRSI(NULL,0,14,PRICE_CLOSE, i);
   if( rsi < thelowest )//I just changed the ">" code there. 
    {
      thelowest = rsi;
      theBar = i;
   }
}
 

You need to initialize theLowest to a value above the highest expected value of rsi, so you can later find an rsi value that is lower.

double theLowest = 99999999;

 

Thank you very much phy, it has worked.

Reason: