Need help with leader-board indicator glitch.

 

I have a leader-board style indicator that shows the most profitable comments from order history. The problem is if there's a tie it overwrites one of the values instead of showing both tied comments in order.


This is how it looks normally.


This is after I tried to fix it.

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int historyTotal=OrdersHistoryTotal();
   static int lastHistoryTotal=0;
   if(lastHistoryTotal!=historyTotal)
     {
      ArrayResize(comments,0);
      ArrayResize(commentCounts,0);
      ArrayResize(commentProfits,0);
      ArrayResize(commentLots,0);
      ArrayResize(topProfits,0);
      for(int i=historyTotal-1; i>=0; i--)
        {
         ResetLastError();
         if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
           {
            Print("Failed to select history orders in "+__FUNCTION__+", error="+(string)GetLastError());
            return false;
           }
         if((OrderSymbol()==InpSymbol || InpSymbol=="ALL") && (OrderMagicNumber()==InpMagicNumber || InpMagicNumber==-1) && OrderComment()!="ADJUSTMENT" && OrderComment()!="Financing" && OrderComment()!="")
           {
            bool found=false;
            for(int j=0; j<ArraySize(comments); j++)
              {
               if(comments[j]==OrderComment())
                 {
                  commentCounts[j]++;
                  commentProfits[j]+=OrderProfit()+OrderSwap()+OrderCommission();
                  commentLots[j]+=OrderLots();
                  found=true;
                  break;
                 }
              }

            if(!found)
              {
               int newSize=ArraySize(comments)+1;
               ArrayResize(comments,newSize);
               ArrayResize(commentCounts,newSize);
               ArrayResize(commentProfits,newSize);
               ArrayResize(commentLots,newSize);
               int j=newSize-1;
               comments[j]=OrderComment();
                           commentCounts[j]++;
               commentProfits[j]+=OrderProfit()+OrderSwap()+OrderCommission();
              }
           }
        }

      ArrayResize(topProfits,DisplayTopCount);
      ArrayResize(DashKeys,DisplayTopCount);
      ArrayResize(DashValues,DisplayTopCount);
      ArrayFill(topProfits,0,0,-999999999);
      int lastIndex=-1;
      int thisIndex=0;
      for(int i=0; i<DisplayTopCount; i++)
        {
        topProfits[i]=-999999;
         for(int j=0; j<ArraySize(comments); j++)
           {
            if(commentProfits[j]>topProfits[i] && (i==0 || commentProfits[j]<topProfits[i-1]) && (j!=lastIndex))
              {
              thisIndex=j;
              topProfits[i]=commentProfits[j];
              DashKeys[i]=""+comments[j]+" : profit ";
              DashValues[i]="$"+DoubleToStr(topProfits[i],2)+" / "+"lots : "+DoubleToStr((commentLots[j]+1),2);
              }
           }
           
           lastIndex=thisIndex;
        }
     }
     
     int dashRows=ArraySize(DashKeys);
   if(ShowDashBoard)
     {
      DisplayDashboard(281,dashRows-1);
     }

   lastHistoryTotal=historyTotal;

//--- return value of prev_calculated for next call
   return(rates_total);
  }


I've tried every way I can think of, any help is much appreciated.

 

Try this one. Maybe it is possible to work.

Line 111 to 133

      //ArrayResize(topProfits, DisplayTopCount);
      ArrayResize(DashKeys, DisplayTopCount);
      ArrayResize(DashValues, DisplayTopCount);
      //ArrayFill(topProfits, 0, 0, -999999999);
      //int lastIndex = -1;
      //int thisIndex = 0;
      double TempDouble;
      string TempString;
      
      for(int i = 0; i < DisplayTopCount; i++)
      {
         //topProfits[i] = -999999;
         for(int j = i + 1; j < ArraySize(comments); j++) //for(int j = 0; j < ArraySize(comments); j++)
         {
            //if(commentProfits[j] > topProfits[i] && (i == 0 || commentProfits[j] < topProfits[i - 1]) && (j != lastIndex))
            if (commentProfits[j] >= commentProfits[i])
            {
                TempDouble = commentProfits[i]; commentProfits[i] = commentProfits[j]; commentProfits[j] = TempDouble;
                TempDouble = commentLots[i];    commentLots[i]    = commentLots[j];    commentLots[j]    = TempDouble;
                TempString = comments[i];       comments[i]       = comments[j];       comments[j]       = TempString;

               //thisIndex = j;
               //topProfits[i] = commentProfits[j];
               //DashKeys[i] = "" + comments[j] + " : profit ";
               //DashValues[i] = "$" + DoubleToStr(topProfits[i], 2) + " / " + "lots : " + DoubleToStr((commentLots[j] + 1), 2);
            }
         }
                        
         DashKeys[i]   = "" + comments[i] + " : profit ";
         DashValues[i] = "$" + DoubleToStr(commentProfits[i], 2) + " / " + "lots : " + DoubleToStr((commentLots[i] + 1), 2);
         //lastIndex = thisIndex;
      }
   }
 
Nagisa Unada:

Try this one. Maybe it is possible to work.

Line 111 to 133

I tried this and It just made the indicator disappear.

Thank you for trying.

 
Jesse Phipps:

I tried this and It just made the indicator disappear.

Thank you for trying.

I've checked it works on my PC, so it shouldn't disappear.

 
Nagisa Unada:

I've checked it works on my PC, so it shouldn't disappear.

My mistake I had too refresh the indicator after changing the code, however that way it skips "Comment2" and "Comment5".


With Fix:


Orignal:


 

Isn't the "DisplayTopCount" set to 5 in your indicator's settings panel?

Increase it.

Setting

 
Nagisa Unada:

Isn't the "DisplayTopCount" set to 5 in your indicator's settings panel?

Increase it.



When its set to 5, It looks like this.



Set to 10, It disappears(Tried loading it fresh with 10 setting, And waiting a few minutes for it update).

 

Aditional change from line 30 ~

string DashKeys[]; //string DashKeys[8];
string DashValues[]; //string DashValues[8];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
        ArrayResize(DashKeys, DisplayTopCount);
        ArrayResize(DashValues, DisplayTopCount);
//---
   return(INIT_SUCCEEDED);
}
 
Nagisa Unada:

Aditional change from line 30 ~

If I set it to 7 or less(the number of comments available) it shows right. But at greater than 7 it still disappears.

 
You can complete the rest on your own.
 
Nagisa Unada:
You can complete the rest on your own.

Thank you very much for the help, I do believe I can complete the rest.

Reason: