Hi, Rodorush!
You can use this script to find the reasons of closing positions.
// this procedure runs when some changes occur in the Orders list
procedure OnOrderChange(const Action: TDataModificationType; const Order: TOrder);
begin
// if a new Order appeared
if Action=dmtInsert then
begin
// output the information into the log corresponding to the type of order
if Order.OrderType = otInit then log('Market order placed');
if Order.OrderType = otClose then log('Order to close a position placed');
if Order.OrderType = otEStop then log('Entry Stop order placed');
if Order.OrderType = otELimit then log('Entry Limit order placed');
if Order.OrderType in [otELimit,otEStop] then
begin
log ('Instrument: ' +Order.Instrument.Name);
log ('Account: ' +Order.Account.Id);
log ('Rate: ' +FloatToStr(Order.Rate));
end;
if Order.OrderType = otMargin then log('Margin call');
if Order.OrderType = otMinEquity then log('Equity reached the minimum level');
end;
end;