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

This procedure runs when a position is opened, closed or modified.

The procedure OnTradeChange has 2 parameters:

1)Action: TDataModificationType – the type of change:

a) dmtInsert – a position is opened

b) dmtDelete – a position is closed

c) dmtUpdate – a position is modified

2)Trade: TTrade – the object from the TTrade class  that was affected by the change.

 

The objects Action and Trade can be accessed within the procedure.

 

Example:

Let us write a strategy that will output all the changes occuring in the Open Positions Window into the log.

The script will be as follows:

 

const

   StrategyName='My Strategy';

 

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

begin

 Log('Some Changes were made in  open positions table');

 Log('Action: ' + IntToStr(Action));

 Log('Trade: ' + Trade.Id);

 Log('Instrument: ' + Trade.Instrument.Name);

 Log('Account: ' + Trade.Account.Id);

 Log('Lots count: ' + FloatToStr(Trade.Amount));

 Log('Close Rate: ' + FloatToStr(Trade.CloseRate));

 Log('Position Tag: ' + Trade.Tag);

end;

 

As a result, the procedure OnTradeChange will run every time some changes occur in the Open Positions Window, and the information about the modified/opened/closed position will appear in the log.

As a result, the output may look something like this:

 

ribbonactfx102