Find 5 greatest number in array

 

Hello, I'm trying to get 5 best profits from my last 1000 closed trades. I wrote code which almost gives me what I want.

   string BestProfit;
   for(int b =0; b < 1000; b++){ //Chek last 1000 trades
       double Barray[1000];
              Barray[b]      = RecentProfits(b+1); //This function gives me last 1000 trades
       int    BestProfitCount = ArrayMaximum(Barray); //This gives me highest Profit from 1000s
   for(int ib =0; ib < 5; ib++){ //Here I'm writing text 5 times to get last 5 highest profit
       BestProfit = "BestProfits_" + IntegerToString(ib);
       WriteText (del + BestProfit, DoubleToStr(Barray[BestProfitCount],2), "Arial", 11, White, 399, BestProfits_y[ib], "\n", 1, ANCHOR_LEFT_LOWER, FALSE);
   }
   }

I think I'm doing somethin wrong in Arrays. It only gives me 1 highest profit and prints 5 times. How can I fix it?

 
Fill the array, then look for the maximum.
 
William Roeder:
Fill the array, then look for the maximum.

Like I said, it gives me maximum. I need to get 5 maximum profit, not one

 
Any ideas?
 
mr-roma:
Any ideas?

This topic was answered just 2 days ago. Don't you read the forum?

https://www.mql5.com/en/forum/358198#comment_19783381

selecting first 2 highest values in Arrays and first 2 lowest values in Arrays (Help)
selecting first 2 highest values in Arrays and first 2 lowest values in Arrays (Help)
  • 2020.12.17
  • www.mql5.com
Hello dear developers, I have this code below: The Array " SymbolsROC " store the roc of the symbols(in double) stated on the function " WeakAndStr...
 

Don't answer if you can't/won't help. I'm already getting maximum number, I just want to get second maximum.

I don't even know why this forum exists. Did I requested full indicator for free? No! Just a little help ...

Thanks anyway

 
The link I posted shows 2 code snippets, both of them are solving your problem. Just spend a little time to think over it. The code you are showing above is broken, by the way.
 
mr-roma: I don't even know why this forum exists. … Just a little help ...
  1. This forum exists to help people. It does not have slaves working on your beck and call.

  2. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help 2017.04.21

 
mr-roma:

Like I said, it gives me maximum. I need to get 5 maximum profit, not one

You make an ArraySort, and you take the first 5...
Reason: