Help Needed ( Sorting a Label data)

 

Summary


Hi Experts

I have created this Label but unable to sort this label.

{

   SetLabel("objSymbol", "Symbol", White, 1050, 40);

   SetLabel("objTrades", "#", White, 990, 40);

   SetLabel("objLots", "Lots", White, 900, 40);

   SetLabel("objOpenPnL", "Current", White, 760, 40);

   SetLabel("objClosedPnL", "Today", White, 650, 40);

   

   

   Assign_Symbols();

   totlots =0.0; tottrades = 0.0; totopnl =0.0; totcpnl =0.0;

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

      if(StringLen(symbols[i])==0) break;

      Output_Row(i, symbols[i]);

   }

   int row = i;

   int clr = Lime; if(totcpnl <0) clr = Red;

   int clr2 = Lime; if(totopnl <0) clr2 = Red;

   SetLabel("objSymbol" + row, "GRAND TOTAL", Aqua, 980, 266+ (row + 1)*19,1,20);

   SetLabel("LINE" + row, "------------------------------- xx --------------------------------------------", White,654, 1300+ (row + 1)*19,1,18);

  // SetLabel("objTrades" + row, DoubleToStr(tottrades,0), Aqua, 220, 25 + (row + 1)*19);

  // SetLabel("objLots" + row, DoubleToStr(totlots,2), Aqua, 170, 25 + (row + 1)*19);

   SetLabel("objOpenPnL" + row, DoubleToStr(totopnl,2), clr2, 800, 260 + (row + 1)*19,1,26);

   SetLabel("objClosedPnL" + row, DoubleToStr(totcpnl,2), clr, 637, 260 + (row + 1)*19,1,26);

  

  

//----

   

//----

   return(0);

  }

//+------------------------------------------------------------------+



void Output_Row(int row, string sym)

{

   SetLabel("objSymbol" + row, sym, Yellow,1030, 50 + (row + 1)*30);

   double trades =0;

   double lots = 0.0;

   double opnl = 0.0;

   double cpnl =0.0;

   double clots = 0.0;

   double ctrades = 0;

   int pos = 1, lcolor = DimGray;

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

      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

      if((OrderMagicNumber() == MagicNumber || MagicNumber == -1 ) && OrderType ()== OP_BUY  && OrderSymbol() == sym || OrderType ()== OP_SELL && OrderSymbol()==sym) {

         opnl += OrderProfit()+OrderCommission()+OrderSwap();

         lots += OrderLots();

         trades +=1;

         if(OrderType() == OP_SELL) pos = -1;

         

      }

   }

   if (pos == 1) lcolor = Lime;

   if (pos ==-1) lcolor = Red;

   int clr = Black; if(opnl <0.0) clr = Red; if(opnl >0.0) clr = Lime;

   int clr1 = Black; if(trades >0) clr1 = White; if(trades >5) clr1 = Red;

   int clr2 = Black; if(lots >0) clr2 = Lime;

   int clr3 = Lime; if(opnl <0) clr3 = Red;

   

   SetLabel ("objTrades" + row, DoubleToStr(trades,0), clr1, 990, 50 + (row + 1)*30);

   SetLabel("objLots" + row, DoubleToStr(lots,2), clr2, 900, 50 + (row + 1)*30);

   SetLabel("objOpenPnL" + row, DoubleToStr(opnl,2), clr, 775, 50 + (row + 1)*30) ;

I want to sort the label ascending or descending either as per number of open trades in an instrument or as per running profit or loss.

will appreciate the help 

Regards

 
  1. Either write your own sort function or
  2. use the integrated one: https://www.mql5.com/en/docs/array/arraysort
    and create (an) array(s) that are suitable to sorted by that function.
Documentation on MQL5: Array Functions / ArraySort
Documentation on MQL5: Array Functions / ArraySort
  • www.mql5.com
"The indicator analyzes data for the last month and draws all candlesticks with small" "to define such candlesticks. The candlesticks having the volumes comprising the first InpSmallVolume" "per cent of the array are considered small. The candlesticks having the tick volumes comprising ...
 
Carl Schreiber:
  1. Either write your own sort function or
  2. use the integrated one: https://www.mql5.com/en/docs/array/arraysort
    and create (an) array(s) that are suitable to sorted by that function. 

Dear Carl

I already been through these links but unable to understand how to integrate or make sort function out of them to apply into my script, I tried couple of things but vain, thats the reason I asked here if anyone can just create that particular code for me.

Regards

 
drali.ksa:

Dear Carl

I already been through these links but unable to understand how to integrate or make sort function out of them to apply into my script, I tried couple of things but vain, thats the reason I asked here if anyone can just create that particular code for me.

Regards

For this exists the Freelancer. I guess it's not so expensive!

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • www.mql5.com
Hello my friend, I hope you are doing fine. You did well in the other order. Now Convert the already existing EA from Mq4 to Mq5. We will need to have two versions just like in the other order. Lock the EA. I would like to have 2 versions. I might share EA with a few friends but I don't want to give them the source-code or to allow them to back...
 
Carl Schreiber:

For this exists the Freelancer. I guess it's not so expensive!

Thats the piece of just a single code,, like ArraySort or other Sorting Code,, I am not asking to program everything I just need a sorting code to sort my already available data, isn't it a just matter of lil help??