Jean
Jean

Reputation: 137

Write transactions to text file

I would like to write all my transactions to a text file. The ones I control with OrderSend() is easy. I do not know how to get the transactions to write if they are stopped out with a stoploss or with a takeprofit where the system terminates the transaction. Is it possible to catch these transactions and write them to CSV?

Upvotes: 0

Views: 398

Answers (1)

J_P
J_P

Reputation: 781

All the information about past orders is available in the history of orders.

You need to select the order you want first with OrderSelect(), this is the syntax:

  bool  OrderSelect(
    int     index,            // index or order ticket
    int     select,           // flag
    int     pool=MODE_TRADES  // mode
    );

And then you can receive any information of that order using OrderClosePrice() OrderCloseTime(); OrderProfit(); etc.

This example returns the open time, close time and profit (it'll be negative if it's a loss) of the order in position 12.

if(OrderSelect(12,SELECT_BY_POS,MODE_HISTORY)==true)
{
      datetime ctm=OrderOpenTime();
      if(ctm>0) Print("Open time for the order 12 ", ctm);
      ctm=OrderCloseTime();
      if(ctm>0) Print("Close time for the order 12 ", ctm);
      Print("Profit for the order 12 ",OrderProfit());
}
else
     Print("OrderSelect failed error code is",GetLastError());

OrderSelect allows you to select the order by ticketnumber also, which you have when you open the order.

If you look at the reference documentation for mql4 you'll find in detail the syntax of these type of commands.

Upvotes: 1

Related Questions