ActFX allows you to work with three different collections:
1) | TradeList – all open positions (as can be seen in the Open Positions window, including the ones opened manually) |
2) | OrderList – all orders (as can be seen in the Orders window, including the ones opened manually) |
3) | AccountList – all accounts (as can be seen in the Account window) |
Lists are objects, while at the same time each individual member of the list is an object as well.
All lists have 2 methods:
1) | The Get() method |
2) | The Count method |
The Count method returns the number of objects in the list. For instance, there are 5 open positions. The following line will assign the value 5 to the variable a:
a:= TradeList.Count; |
The Get() method is used to find the required object in the list.
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 access the first object of the list, the script should include the following line:
var a: TTrade;
-------
a:= TradeList.Get(0); |
Note: the Get() method returns objects from the TTrade, TOrder and TAccount class, so the objects that receive the values must be from the same class.
Example:
You need to find the trade with a ticket number 113423.
for i:=0 to TradeList.Count-1 do if TradeList.Get(i).Id = '113423' then a:= TradeList.Get(i); |
Example: 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.
const StrategyName = 'Orders';
procedure OnStart; var i:integer; begin for i:=0 to TradeList.Count-1 do log('Trade (' + IntToStr(i) + '): ' + TradeList.Get(i).Id); for i:=0 to OrderList.Count-1 do log('Order (' + IntToStr(i) + '): ' + OrderList.Get(i).Id); for i:=0 to AccountList.Count-1 do log('Account (' + IntToStr(i) + '): ' + AccountList.Get(i).Id); end; |