Strategy Data Types

The strategy script in ActFX utilizes different classes of objects:

 

hmtoggle_plus1TInstrument

TInstrument is a class which can be used to store an instrument along with all of its properties.

In order to use an object from this class, you must declare it:

 

Var

 Instrument : TInstrument;

 

The objects belonging to this class have 7 fields:

 

a) Name: String – the instrument name

b) Buy: Double – the Ask rate

c) Sell: Double – the Bid rate

d) PointSize: Double – the smallest rate change that a given dealing rate can make. Also known as a pip (for example, the PointSize of EURUSD is 0.0001)

e) Id: String – the number of instrument in the instrument list

f) CondDistance: Integer – the condition distance of the instrument (in pips)

g) ContractSize: Double – the contract size of the instrument (amount of 1 lot)

h) TradeStep: Double – the Trading Step of the instrument

i) PipValue: Double – the value of one pip per one contract in system base currency at the current moment

j) NotionalValue(const BuySell: TBuySell): Double – this function returns the Notional Value* on instrument per one lot (amount of 1 contract) according to trade direction (buy or sell), which should be set as an argument

 

Below is an example of using an object Instr from the TInstrument class.

 

Example:

Let's assume that the object Instr holds the instrument EURUSD. EURUSD is the first on the instrument list, the current rate is 1.4223/1.4228, and the script includes the following lines:

 

Var

 Instr : TInstrument;

 Number, Name : String;

 CondDst: Integer;

 Bid, Ask, PntSize, ContrSz, TradeStep, PipValue, NotVal : Double;

 

// The ways how an instrument can be assigned to the object will be described in the following chapters

...

Number := Instr.Id;

Name := Instr.Name;

Ask := Instr.Buy;

Bid := Instr.Sell;

PntSize := Instr.PointSize;

CondDst := Instr.CondDistance;

ContrSz := Instr.ContractSize;

TradeStep := Instr.TradeStep;

PipValue := Instr.PipValue;

NotVal := Instr.NotionalValue(bsBuy);

 

 

As a result we will get:

Number = 1

Name = EURUSD

Bid = 1.4223

Ask = 1.4228

PntSize = 0.0001

CondDst = 8

ContrSz = 10000

TradeStep = 10000

PipValue = 10

NotVal = 134950

 

* Notional Value

Trade's Notional value is the value of a trade in the system base currency.

Basically, notional value is calculated by multiplying the trade amount by the rate of the instrument’s first currency to the system base currency. The trade amount = [number of lots * contract size], measured in the first currency of the instrument (also called the contract or transaction currency).

1) For indirect currency pairs (where the system base currency is the first currency) the notional value is equal to the trade amount – there is no need to convert it.

2) Direct pair: The system base currency is currency2 (quote currency), therefore the trade amount should be converted into System Base Currency. In this case the notional value of trade changes with every new tick, because the rate of the first currency in the pair changes relative to the System Base Currency rate.

3) Cross pair: Requires the MID price of the first currency / base currency. The MID price is the average of the Dealer’s Bid and Ask rate: MID = (BID + ASK)/2. In this case the notional value of trade also changes with every new tickat the current moment

 

hmtoggle_plus1TAccount

TAccount is a class which can be used to store an account along with all of its properties.

In order to use an object from this class, you must declare it:

 

Var

 Acc: TAccount;

 

The objects belonging to this class have 5 properties:

a) Id: String – the account number

b) Balance: Double – the account balance

c) Equity: Double – the account equity

d) UsedMargin: Double – the used margin

e) EquityLevel: Double – the equity level, % (Equity Level= Equity/Used Margin*100)

 

Below is an example of using an object Acc from the class TAccount.

 

Note: In the strategy's testing mode Balance, Equity, Used Margin and Equity Level values will not change.

 

Example:

Let's assume that the object Acc holds the account number 12434, with a $2000 balance, and a $2250 equity. The used margin is $500, and the equity level is 450%. The script includes the following lines:

 

Var

 Acc : TAccount;

 AccNum: String;

 Balance, Equity, UsedM, EqLevel : Double;

 

// The ways how an account can be assigned to the object will be described in the following chapters

...

AccNum := Acc.Id;

Balance := Acc.Balance;

Equity := Acc.Equity;

UsedM := Acc.UsedMargin;

EqLevel := Acc.EquityLevel;

 

As a result we will get:

AccNum = 12434

Balance = 2000

Equity = 2250

UsedM =  500

EqLevel =  450

 

hmtoggle_plus1TOrder

TOrder is a class which can be used to store an order along with all of its properties.

In order to use an object from this class, you must declare it:

 

Var

 Ordr : TOrder;

 

The objects belonging to this class have 7 properties:

a) Id: String – the ticket number of the order

b) Instrument: TInstrument– the instrument on which the order is placed

c) Account: TAccount – the account on which the order is placed

d) Tag: String - the order tag which can be used to mark an order in the script

e) Rate: Double – the order rate

f) BuySell: TBuySell – the direction of order . See TBuySell type below in this section.

g) OrderType: TOrderType – the type of order. There are 14 different types of orders:

0: otInit – a market order to open a position

1: otRejInit – a market order rejected by the dealer

2: otClose – a market order to close a position

3: otRejClose – an order to close a position rejected by the dealer

4: otEStop – an Entry Stop type of order

5: otELimit – an Entry Limit type order

6: otStop – a stop order on a position

7: otLimit – a limit order on a position

8: otMargin – a margin call order

9: otMinEquity –  an order to close the position due to the Equity declining below the Minimal Equity level

10: otInitFailed –  failed market order due to unsufficient usable margin

11: otEFailed – failed entry order due to unsufficient margin or margin call

12: otStopFailed – failed stop order on a position due to margin call

13: otLimitFailed – failed limit order on a position due to margin call

 

Please note that the Instrument property holds the data type TInstrument, and the Account property holds the data type TAccount. There are two ways to use this:

 

Example:

Let's assume that the object Ordr holds the order placed on the instrument EURUSD. EURUSD is the first on the instrument list, the current rate is 1.4223/1.4228), the account number is 32234 (with a $2000 balance, and a $2250 equity), the order tag is 'a123', and the order ticket is 988898.

 

Method 1:

The script includes the following lines:

 

Var

 Acc : TAccount;

 Ordr : TOrdr;

 Instr : TInstrument;

 Ticket, Tag : String;

 Bid, Ask, Balance : Double;

 

// The ways how an order can be assigned to the object will be described in the following chapters

...

Ticket := Ordr.Id;

Tag := Ordr.Tag;

Instr := Ordr.Instrument;

Acc := Ordr.Account;

Ask := Instr.Buy;

Bid := Instr.Sell;

Balance := Acc.Balance;

 

As a result we will get:

Ticket = 988898

Tag = a123

Bid = 1.4223

Ask = 1.4228

Balance =  2000

 

As you can see, in order to get the current rate of the instrument on which the order is placed, we had to create a Tinstrument type object Instr and attach it to the Instrument property of the object Ordr. We had to do the same thing with the Account.

 

Method 2:

There is another way to use the information. In this case we do not need to create additional objects. For instance, if we need to get the Ask rate of the Instrument on which the order is placed, we can type the following line:

 

Ask := Ordr.Instrument.Buy;

 

In this case we need the following script:

 

Var

 Ordr : TOrdr;

 Ticket, Tag : string;

 Ask, Bid, Balance : double;

 

// The ways how an order can be assigned to the object will be described in the following chapters

...

Ticket := Ordr.Id;

Tag := Ordr.Tag;

Instr := Ordr.Instrument;

Acc := Ordr.Account;

Ask := Ordr.Instrument.Buy;

Bid := Ordr.Instrument.Sell;

Balance := Ordr.Account.Balance;

 

We will get the same result as in the previous case:

Ticket = 988898

Tag = a123

Bid = 1.4223

Ask = 1.4228

Balance =  2000

 

hmtoggle_plus1TTrade

TTrade is a class which can be used to store an open position along with all of its properties.

In order to use an object from this class, you must declare it:

 

Var

 OpenPos: TTrade;

 

The objects belonging to this class have 12 properties:

a) Id: String – the open position ticket

b) Instrument: TInstrument– the instrument on which the position is opened

c) Account: TAccount – the account on which the position is opened

d) Amount: Double – the number of lots

e) OpenRate: Double – the open rate

f) CloseRate: Double — the current close rate

g) Tag: String — the position tag

h) NetPL: Double — the NetP/L of the open position

i) LimitOrder: TOrder —  the limit on this position (if there is one)

j) StopOrder: TOrder — the stop on this position (if there is one)

k) BuySell: TBuySell – bsBuy or bsSell

l) StrategyId: String - the Id number of the strategy which opened the position.

 

Below is an example of using an object OpenPos from the class TTrade.

 

Example:

Let's assume that the object OpenPos holds a position with the following parameters:

1)Ticket = 12221
2)Instrument

 a) Id = 1

 b) Name = EURUSD

 c) Buy = 1.4223

d) Sell = 1.4228

3)Account

a) Id = 433334

b) Balance = 2000

c) Equity = 2200

4)Number of lots = 2
5)The open rate = 1.4225
6)The current close rate = 1.4228
6)Tag = ‘a123’
7)Predefined stop = 1.4200
8)Predefined Limit = 1.4300

 

The script includes the following lines:

 

Var

 OpenPos : TTrade;

 PosTicket, InstNum, InstName, AccNum, PosTag: String;

 Ask, Bid, Balance, Equity, PosAmount, Open, Close, Stop, Limit: double;

 

// The ways how a position can be assigned to the object will be described in the following chapters

...

PosTicket := OpenPos.Id;

InstNum := OpenPos.Instrument.Id;

InstName := OpenPos.Instrument.Name;

Ask := OpenPos.Instrument.Buy;

Bid := OpenPos.Instrument.Sell;

AccNum := OpenPos.Account.Id;

Balance := OpenPos.Account.Balance;

Equity := OpenPos.Account.Equity;

PosAmount := OpenPos.Amount;

Open := OpenPos.OpenRate;

Close := OpenPos.CloseRate;

PosTag := OpenPos.Tag;

NetPL := OpenPos.NetPL;

Limit:=OpenPos.LimitOrder.Rate;

Stop:=OpenPos.StopOrder.Rate;

 

As a result we will get:

 

PosTicket = 12221

InstNum = 1

InstName = EURUSD

Bid = 1.4223

Ask = 1.4228

AccNum = 433334

Balance = 2000

Equity = 2200

PosAmount = 2

Open = 1.4225

Close = 1.4228

PosTag = a123

Limit = 1.4300

Stop = 1.4200

 

hmtoggle_plus1TClosedTrade

TClosedTrade is a class which can be used to store closed position along with all of its properties.

In order to use an object from this class, you must declare it:

 

Var

 ClosedPos: TClosedTrade;

 

The objects belonging to this class have 14 properties:

a) Id: String – the closed position ticket

b) Instrument: TInstrument – the instrument on which the position was opened

c) Account: TAccount – the account on which the position was opened

d) Amount: Double – the number of lots

e) OpenRate: Double – the open rate

f) CloseRate: Double — the close rate

g) CloseTag: String — the position close tag

h) NetPL: Double — the NetP/L of the closed position

i) BuySell: TBuySell – Buy or Sell

j) OpenStrategyId: String - the Id number of the strategy which opened the position

k) CloseStrategyId: String - the Id number of the strategy which closed the position

l) OpenTime: TDateTime - the date and time of position openning

m) CloseTime: TDateTime - the date and time of position closing

n) Comment: String - the tickets comment

 

Example:

procedure OnStart;

var

BuySellvar : TBuySell;    

begin

 ClosedTradeList.LoadData;

 Log('Id : ' + ClosedTradeList.Get(0).Id);

 Log('Instrument : ' + ClosedTradeList.Get(0).Instrument.Name);  

 Log('Account : ' + ClosedTradeList.Get(0).Account.Id);

 Log('Amount : ' + FloatToStr(ClosedTradeList.Get(0).Amount));

 Log('OpenRate : ' + FloatToStr(ClosedTradeList.Get(0).OpenRate));

 Log('CloseRate : ' + FloatToStr(ClosedTradeList.Get(0).CloseRate));

 Log('CloseTag : ' + ClosedTradeList.Get(0).CloseTag);

 Log('NetPL : ' + FloatToStr(ClosedTradeList.Get(0).NetPL));

If ClosedTradeList.Get(0).BuySell = bsSell then

   Log('BuySell : Sell')

else if ClosedTradeList.Get(0).BuySell = bsBuy then

   Log('BuySell : Buy');    

 Log('OpenStrategyId : ' + ClosedTradeList.Get(0).OpenStrategyId);

 Log('CloseStrategyId : ' + ClosedTradeList.Get(0).CloseStrategyId);

 Log('OpenTime : ' + DateTimeToStr(ClosedTradeList.Get(0).OpenTime));  

 Log('CloseTime : ' + DateTimeToStr(ClosedTradeList.Get(0).CloseTime));

 Log('Comment : ' + ClosedTradeList.Get(0).Comment);

end;

 

Logged:

Id : 1843

Instrument : EURUSD

Account : 10

Amount : 425

OpenRate : 3.2319

CloseRate : 3.1319

CloseTag : YZoA7fKz*3

NetPL : -1357966.62

BuySell : Buy

OpenStrategyId :                                 // position was opened manually

CloseStrategyId :                               // position was closed manually

OpenTime : 07.11.2012 9:14:43

CloseTime : 07.11.2012 9:15:18

Comment :                                       // there was no comment for trade

 

hmtoggle_plus1TTick

TTick is a class which can be used to store an individual tick from the chart along with all of its properties.

In order to use an object from this class, you must declare it:

 

Var

 Tick : TTick;

 

The objects belonging to this class have 2 properties:

a) Time: TDateTime – Date and time of the tick

b) Rate: Double – the Bid rate

 

Below is an example of using an object Tick from the class TTick.

 

Example:

Let's assume that the object Tick holds a tick received on January 21, 2007 at 12:10:00. The tick rate was 1.4234, and the script includes the following lines:

 

Var

 Tick : TTick;

 TickTime : TDateTime;

 Rate : double;

 

// The ways how a Tick can be assigned to the object will be described in the following chapters

...

TickTime := Tick.Time;

Rate := Tick.Rate;

 

As a result we will get:

 

TickTime = 12.01.2007 12:10:00

Rate = 1.4234

 

hmtoggle_plus1TCandle

TCandle is a class which can be used to store a candle from the chart along with all of its properties.

In order to use an object from this class, you must declare it:

 

Var

 Candle : TCandle;

 

The objects belonging to this class have 9 properties:

a) Time: TDateTime – Date and time when the candle was opened

b) Open: Double – the candle's open rate

c) Close: Double – the candle's close rate

d) High: Double – the candle's maximum value

e) Low: Double – the candle's minimum value

f) Median: Double – the candle's median value = (High+Low)/2

g) Typical: Double – the candle's typical value = (High+Low+Close)/3

h) Weighted: Double – the candle's weighted value = (High+Low+2*Close)/4

i) TickVolume: Integer – number of the ticks contained in the candle with given index*

 

  * Number of ticks (prices) arrived in the system, on current instrument, in period between begin and end of the candle with given index.

    Indirectly it may show the market activity level.

 

 

 

 

clip0704

 

 

Below is an example of using an object Candle from the class TCandle.

 

Example:

Let's assume that the object Candle holds a candle which was opened on January 21, 2007 at 12:10:00.  Open = 1.4230, Close = 1.4240, High = 1.4250, Low = 1.4210, and the program includes the following lines:

 

Var

 History : TCandleHistory;

 Candle : TCandle;

 CandTime : TDateTime;

 Open, Close, High, Low: Double;

 Volume : Integer;

 

// The ways how a candle can be assigned to the object will be described in the following chapters

Candle := History.Last(1);

...

CandTime := Candle.Time;

Open := Candle.Open;

Close := Candle.Close;

High := Candle.High;

Low := Candle.Low;

Volume := Candle.TickVolume;

 

As a result we will get:

 

CandTime = 12.01.2011 12:10:00

Open = 1.4230

Close = 1.4240

High = 1.4250

Low = 1.4210

Volume = 457

 

hmtoggle_plus1TChartInterval

Type

Description

CI_Tick

The tick chart interval.

CI_1_Minute

1 minute chart interval.

CI_5_Minutes

5 minute chart interval.

CI_15_Minutes

15 minute chart interval.

CI_30_Minutes

30 minute chart interval.

CI_1_Hour

1 hour chart interval.

CI_2_Hours

2 hour chart interval.

CI_4_Hours

4 hour chart interval.

CI_1_Day

1 day chart interval.

CI_1_Week

1 week chart interval.

CI_1_Month

1 month chart interval.

 

hmtoggle_plus1TStrategy

TStrategy is a class which can be used to store a user strategy along with its properties.

We can use only one object from this class inside the strategy (Strategy: TStrategy),

and we do not need to declare it.

The objects belonging to this class have 2 properties:

a) Caption: String;

b) Id: String;

 

Example:

Let's assume that the strategy id is 4665, and the the script is as follows:

 

const

 StrategyName = 'MyStrategy';

 

var

 Capt: String;

 IdNum: String;

 

...

Capt := Strategy.Caption;

IdNum := Strategy.Id;

 

As a result we will get:

 

Capt = 'MyStrategy'

IdNum = 4665

 

 

 

 

Show/Hide Hidden Text