ArraySort - sorting floating point variables - page 2

 
James Cater #:

Thank you very much James. It is working now.

 

Another problem, how to prevent the second column text from waving by filling the missing zeros.

Is something like this possible or is it wrong?

This is not properly working example:

for(c=0; c<28; c++)
      {
      m[c]=(MathMod(rsi[c],1));
      if(m[c]==0)
         zeros[c]=".00";
      if(m[c]==0.1||m[c]==0.2||m[c]==0.3||m[c]==0.4||m[c]==0.5||m[c]==0.6||m[c]==0.7||m[c]==0.8||m[c]==0.9)
         zeros[c]="0";

...
    
     }
Files:
waving.jpg  53 kb
 
losdelamos #: Another problem, how to prevent the second column text from waving by filling the missing zeros.
  1. Use a fixed width font like “Courier New”.
  2. Always add the trailing zeros with StringFormat.
 
William Roeder #:
  1. Use a fixed width font like “Courier New”.
  2. Always add the trailing zeros with StringFormat.

Thank you very much William, StringFormat is exactly the command I was looking for.  Now the code works exactly as I imagined.

Is it possible to change the  font for the Comment command ? How? Thank you.

The result code:

#define nl "\n"
int OnInit()
  {
   EventSetMillisecondTimer(500);
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
   EventKillTimer();
  }
void OnTimer()
  {
   string pairs[28]={"EURUSD","GBPUSD","USDJPY","AUDCAD","AUDNZD","AUDUSD","CADCHF","EURGBP","GBPAUD","GBPCAD","GBPNZD","NZDCAD","NZDUSD","USDCAD",
                     "USDCHF","AUDCHF","AUDJPY","EURAUD","EURCHF","EURNZD","GBPCHF","NZDCHF","CADJPY","CHFJPY","EURCAD","EURJPY","GBPJPY","NZDJPY"};
   string cm[28],sp="              ",sp2="   ",sp3="              ",sp4="                 ";
   double rsi[28],num_array_de[28][2],num_array_as[28][2];
   ArrayInitialize(num_array_de,2);ArrayInitialize(num_array_as,2);
   for(uchar a=0; a<28; a++)
     {
      rsi[a]=iRSI(pairs[a],_Period,14,PRICE_CLOSE,0);num_array_de[a][0]=rsi[a];num_array_de[a][1]=a;num_array_as[a][0]=rsi[a];num_array_as[a][1]=a;
     }
   ArraySort(num_array_de,WHOLE_ARRAY,0,MODE_DESCEND);ArraySort(num_array_as,WHOLE_ARRAY,0,MODE_ASCEND);     
   for(uchar b=0; b<28; b++)
     {
      cm[b]=pairs[(int)num_array_de[b][1]]+sp2+StringFormat("%.2f",num_array_de[b][0])+sp3+
            pairs[(int)num_array_as[b][1]]+sp2+StringFormat("%.2f",num_array_as[b][0])+nl;
     }   
   Comment(nl+" RSI descending"+sp4+"RSI ascending"+nl+"------------------------"+sp+"------------------------"+nl+cm[0]+cm[1]+cm[2]+cm[3]+cm[4]+
           cm[5]+cm[6]+cm[7]+cm[8]+cm[9]+cm[10]+cm[11]+cm[12]+cm[13]+cm[14]+cm[15]+cm[16]+cm[17]+cm[18]+cm[19]+cm[20]+cm[21]+cm[22]+cm[23]+cm[24]+
           cm[25]+cm[26]+cm[27]);
  }
Files:
screen.jpg  58 kb
Reason: