Discussion of article "Graphical interfaces X: Advanced management of lists and tables. Code optimization (build 7)" - page 11

 

I still don't understand how to update the table....

There is dynamic data in the table, we need to update it by timer.

I try to clear it first using Clear() method, but an error pops up:

 invalid pointer access in 'Element.mqh' (106,70)

How to update it? I haven't found an example anywhere in the articles. In all articles the table is filled with static data.

 
Juer:

How to update the table I haven't understood....

There is dynamic data in the table, we need to update it by timer.

I try to clear it first using Clear() method, but an error pops up:

How to update it? I have not found an example anywhere in the articles. In all articles the table is filled with static data.

 
Anatoli Kazharski:

Thank you. Except it doesn't take sorting into account.

When sorting, rows can change their position....

 
Juer:

Thank you. Except it doesn't take sorting into account.

When sorting, rows can change their position...

You can control the sorting yourself. There is a public method CTable::SortData() for this purpose.

Example and the latest version of CTable class here: EasyAndFast library updates

 
Anatoli Kazharski:

You can control the sorting yourself. There is a public method CTable::SortData() for this purpose.

Example and the latest version of CTable class here: EasyAndFast library updates

It's still unclear. There is no method to determine how many rows in the table are non-empty. I am uploading information on open orders to the table. Orders can appear or close. I have to go through all the values each time in the table and compare by ticket.... It is inconvenient, but it is possible.

Also, could you help me with sorting. I need to make a row in the table analogue to the one on the Trade tab. A row summarising the profit on open positions, commissions, etc. That is, the columns of this row will be the same as in the table, but with total values. So, how can I put this row first in the list so that sorting is not applied to it?

 
Juer:

Still not clear. There is no method to determine how many rows in the table are non-empty. I am uploading information on open orders to the table. Orders can appear or close. I have to go through all the values each time in the table and compare by ticket.... It is not convenient, but it is possible.

...

Go through the rows yourself and see if they are empty or not.

The article Trading Expert Advisor with GUI: Filling with functionality (Part II) shows in detail how this can be implemented.

Juer:

...

Also, can you tell me about sorting. I need to make a row in the table analogue to the one on the Trade tab. A row summarising the profit on open positions, commissions, etc. That is, the columns of this row will be the same as in the table, but with total values. So, how can I put this row first in the list and not have sorting applied to it?

There is no such possibility in the library. As an option, you can create a second table without headers with one row above the first table and output total values in it.

 
Anatoli Kazharski:

Go through the lines yourself and see if they are empty or not.

The article Trading Expert Advisor with GUI: Filling with functionality (Part II) shows in detail how it can be implemented.

The library does not have this feature. As an option, you can create a second table without headers with one row above the first table and output total values in it.

In the example in the article, again, the number of rows is constant, but mine is dynamic. But I realised that I have to do it by hand.

The second table from above is not a bad solution, but how to deal with changing the width of columns in the main table...? How to synchronise with the second?

Another question. If I have the first column simply indicates the serial number of the record. It is not subject to sorting. Is there any way to make a certain column unsorted?

 
Juer:

In the example in the article, again, the number of rows is constant, but mine is dynamic. But I get it, it's handmade, so what's wrong with it.

Where did you see a constant number of lines? The number of positions and the number of characters used changes and these changes are reflected in the tables.


Juer:

The second table from above is not a bad solution, but what about changing the width of columns in the main table...? How to synchronise with the second one?

Another question. If I have the first column simply indicates the serial number of the record. It is not subject to sorting. Is there any way to make a certain column unsorted?

No, there's no way.

 
Anatoli Kazharski:

Where did you see a constant number of rows? The number of positions and the number of characters used changes and these changes are reflected in the tables.

Honestly, I don't really understand how you update the positions there. I see that to update the character table you just delete all rows. But I don't understand how the position table is updated yet:

//+------------------------------------------------------------------+
//| Set values in the position table |
//+------------------------------------------------------------------+
void CProgram::SetValuesToPositionsTable(string &symbols_name[])
  {
//--- Check for out of range
   uint symbols_total =::ArraySize(symbols_name);
   uint rows_total    =m_table_positions.RowsTotal();
   if(symbols_total<rows_total)
      return;
//--- Let's get the indicators in the table
   for(uint r=0; r<rows_total; r++)
     {
      int    positions_total =PositionsTotal(symbols_name[r]);
      double pos_volume      =PositionsVolumeTotal(symbols_name[r]);
      double buy_volume      =PositionsVolumeTotal(symbols_name[r],POSITION_TYPE_BUY);
      double sell_volume     =PositionsVolumeTotal(symbols_name[r],POSITION_TYPE_SELL);
      double pos_profit      =PositionsFloatingProfitTotal(symbols_name[r]);
      double buy_profit      =PositionsFloatingProfitTotal(symbols_name[r],POSITION_TYPE_BUY);
      double sell_profit     =PositionsFloatingProfitTotal(symbols_name[r],POSITION_TYPE_SELL);
      double average_price   =PositionAveragePrice(symbols_name[r]);
      string deposit_load    =::DoubleToString(DepositLoad(false,average_price,symbols_name[r],pos_volume),2)+"/"+
                              ::DoubleToString(DepositLoad(true,average_price,symbols_name[r],pos_volume),2)+"%";
      //--- Set values
      m_table_positions.SetValue(0,r,symbols_name[r]);
      m_table_positions.SetValue(1,r,(string)positions_total);
      m_table_positions.SetValue(2,r,::DoubleToString(pos_volume,2));
      m_table_positions.SetValue(3,r,::DoubleToString(buy_volume,2));
      m_table_positions.SetValue(4,r,::DoubleToString(sell_volume,2));
      m_table_positions.SetValue(5,r,::DoubleToString(pos_profit,2));
      m_table_positions.SetValue(6,r,::DoubleToString(buy_profit,2));
      m_table_positions.SetValue(7,r,::DoubleToString(sell_profit,2));
      m_table_positions.SetValue(8,r,deposit_load);
      m_table_positions.SetValue(9,r,::DoubleToString(average_price,(int)::SymbolInfoInteger(symbols_name[r],SYMBOL_DIGITS)));
      //--- Set the colour
      m_table_positions.TextColor(3,r,(buy_volume>0)? clrBlack : clrLightGray);
      m_table_positions.TextColor(4,r,(sell_volume>0)? clrBlack : clrLightGray);
      m_table_positions.TextColor(5,r,(pos_profit!=0)? (pos_profit>0)? clrGreen : clrRed : clrLightGray);
      m_table_positions.TextColor(6,r,(buy_profit!=0)? (buy_profit>0)? clrGreen : clrRed : clrLightGray);
      m_table_positions.TextColor(7,r,(sell_profit!=0)?(sell_profit>0)? clrGreen : clrRed : clrLightGray);
     }
  }

I don't understand something. If there are less symbols than rows in the table, you just don't update it?

I need to update the values actually on every tick. How correct would it be to delete all rows and fill the table again every time?

 

Juer:

I need to update the values actually on each tick. How correct would it be to delete all rows and fill the table again each time?

If you just need to update the values, you don't need to delete anything.

If you need to change the number of rows in the table, then one way to do it is shown.

The second way is to use the CTable::Rebuilding() method. But then you will have to set some table properties (headers, column widths, etc.) again.