Lists of Objects

Lists are objects, while at the same time each individual member of the list is an object as well.

ActFX allows you to work with 4 different collections:

1)TradeList – all open positions (as can be seen in the Open Positions window, including the ones opened manually)
2)ClosedTradeList – specified list of closed positions, depends on LoadSettings* property of ClosedTradeList.
3)OrderList – all orders (as can be seen in the Orders window, including the ones opened manually)
4)AccountList – all accounts (as can be seen in the Account window)


Each of lists has 3 methods:

1)Count - returns number of objects in the list
2)Get - returns objects by Index
3)Find - returns objects by Id


The ClosedTradeList has additional method

4)LoadData - loads a list of closed trades from server



function Count(): Integer;

function Get(const Index: Integer): TTrade;//or TClosedTrade, TOrder, TAccount

function Find(const Id: String): TTrade;   //or TClosedTrade, TOrder, TAccount

procedure LoadData();

Note: the Get() and Find() methods return objects of the TTrade, TClosedTrade, TOrder and TAccount types, so the objects that receive the values must be from the same class.


* ClosedTradeList.LoadSettings

Unlike other lists the ClosedTradeList works with historical data, the volume of which can be unlimited.

For comfort handling of this data the ClosedTradeList has a property LoadSettings which is an object of TClosedTradeDataLoadSettings type.

The LoadSettings object is a container for a few ClosedTradeList's settings:



property Count: Integer;   // number of last closed trades to load from server

property DaysAgo: Integer; // number of last days(from now) for which to load closed trades from server

property Account: String; // specify the account number for which the closed trades should be loaded


Any or all off these settings are not required, in case you didn't specify them the next values will be applied as default:

Account - the first from account list;

Count - 100;

DaysAgo - Ignored;

Note: In case you specified both settings Count and DaysAgo - the last one will have priority:

Data will be loaded for last 'DayAgo' number of days and the setting Count will be ignored.


Example for ClosedTradeList:

procedure OnStart;


 i: Integer;          



 ClosedTradeList.LoadSettings.Count := 50;

 ClosedTradeList.LoadSettings.DaysAgo := 5;

 ClosedTradeList.LoadSettings.Account := '8';


 Log('ClosedTradeList.Count: ' + IntToStr(ClosedTradeList.Count));

for i := 1 to ClosedTradeList.Count - 1 do

   Log('ClosedTrade Id: ' + ClosedTradeList.Get(i).Id);



procedure OnTradeChange(const Action: TDataModificationType; const Trade: TTrade);


if Action = dmtDelete then

   Log('Closed Trade CloseRate: ' + FloatToStr(ClosedTradeList.Find(Trade.Id).CloseRate));



Each list has an index, which allows us to refer to individual objects.

The objects are numbered from 0 to (Count-1). For instance, there are 3 orders in the list.

The first one will be index number 0, the second one will be index number 1, and the last one will be index number 2.

Therefore, to get the first object of the list, you should use 0 (zero) as passed index, like TradeList.Get(0);


Note: the Get() method returns objects from the TTrade, TClosedTrade, TOrder and TAccount class, so the objects that receive the values must be from the same class.


Example 1 General:


You need to use the open trade with a ticket number 113423.



 a: TTrade;


procedure MyProc;


 a:= TTradeList.Find('113423');



Example 2 General:


Let us create a strategy that will output the tickets of all open positions, the id numbers of all orders, and the numbers of all accounts into the log.


procedure OnStart;




  for TradeList.Count-1   downto i:=0 do log('Trade (' + IntToStr(i) + '): ' + TradeList.Get(i).Id);

  for OrderList.Count-1   downto i:=0 do log('Order (' + IntToStr(i) + '): ' + OrderList.Get(i).Id); 

  for AccountList.Count-1 downto i:=0 do log('Account (' + IntToStr(i) + '): ' + AccountList.Get(i).Id);