Find Last 2 iHighest

 

Hi Guys,

When the new candle generates, I would like to get the last one and last two iHighest.

My code is

double lasthi1=iHighest(Symbol(),0,MODE_HIGH,50,1);

double lasthi2=iHighest(Symbol(),0,MODE_HIGH,50,2);


if(Close[2]>lasthi2 && Close[1] > lasthi1)

{

return(true);

}

But it seems I can get last one iHighest but cannot get the last 2 iHighest.

Is there anybody could give me a hand ?

Thanks a lot.

 

Maybe create an array of the last 50 Highs

Find the highest in the array and assign its value to your first variable.

Then set the value of that call in the array to 0

Scan the array for the highest again, and this time you will find the second highest.

You can use

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.
 
chihmingtsao:

Hi Guys,

When the new candle generates, I would like to get the last one and last two iHighest.

You can do this but you need to think a little, you find the highest in the last 50 bars, then the next highest can be before this highest in time, or after this highest in time . . . so you then need to do two more iHighest() calls, one either side of the Highest and then compare the Highs of these 2 Highest bars to see which is higher . . . then you will have your 2nd highest bar . . .
 
Simon Gniadkowski #:
You can do this but you need to think a little, you find the highest in the last 50 bars, then the next highest can be before this highest in time, or after this highest in time . . . so you then need to do two more iHighest() calls, one either side of the Highest and then compare the Highs of these 2 Highest bars to see which is higher . . . then you will have your 2nd highest bar . . .

thx m8

 
Chihming Tsao: I would like to get the last one and last two iHighest.

My code is

double lasthi1=iHighest(Symbol(),0,MODE_HIGH,50,1);

double lasthi2=iHighest(Symbol(),0,MODE_HIGH,50,2);

  1. Perhaps you should read the manual. iHighest does not return a double.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

  2. The calls will not return next/secondary. It must be coded explicitly.
    Not compiled, not tested, just typed.
    double arr[50][2];
    for(int i=50; i>0; --i){ arr[i-1][0]=High[i]; arr[i-1][1]=i]; }
    ArraySort(arr);
    int iHH=arr[49][1], iSec=arr[48][1];
    Printformat("Highest=%d at %i, next=%d at %i, etc.", High[iHH], iHH, High[iSec], iSec);
    Not compiled, not tested, just typed.

    or

    Not compiled, not tested, just typed.

    int iHH[3]={0}
    for(int iBar=50; iBar>0; --iBar){ 
       double v=High[iBar];
       for(int iHighs=0; i < 3; ++i){
          if(v > High[iHH[iHighs]]){
             for(int i=2; i>= iHighs; --i) iHH[i+1]=iHH[i];
             iHH[iHighs]=iBar;
             break;
          }
    }
    int iHH=iHH[0], iSec=iHH[1];
    Printformat("Highest=%d at %i, next=%d at %i, etc.", High[iHH], iHH, High [iSec], iSec);

    Not compiled, not tested, just typed.

Reason: