Download MetaTrader 5

Write orders in csv file

To add comments, please log in or register
Unable to find the answer to your question? Use the search!
Keith Watford
Moderator
9619
Keith Watford 2016.04.17 08:07 
beh12zad:

Hallo Sir,

I want to write my total Order in .csv File, but this code writes thevalue of OrderType() and not the Order operation type like OP_SELLSTOPor OP_BUYSTOP.

How can I change it? thanks in advance.

#    open price    open time    symbol    lots
24497874    1.1288    2016.03.29 18:20:58    EURUSD    0.01    1

24975577    1.14605    2016.04.12 11:24:41    EURUSD    0.01    3

void OnStart()
  {
//---
    int handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
  if(handle<0) return(0);
  // write header
  FileWrite(handle,"#","open price","open time","symbol","lots");
  int total=OrdersTotal();
  // write open orders
  for(int pos=0;pos<total;pos++)
    {
     if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
     FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots()),OrderType());
    }
  FileClose(handle);

  }

Keith Watford
Moderator
9619
Keith Watford 2016.04.17 08:09  
I have moved this post from a reply to an unrelated and old thread
beh12zad
30
beh12zad 2016.04.17 11:19  
GumRai:
I have moved this post from a reply to an unrelated and old thread

Hallo Sir ,

Sorry for that. I thought it was the same Problem.

I will appriciate if you can help me to change the Code to get Order operation type llike OP_SELLLIMIT or  sell limit pending order and not the value.

thanks in advance.

Keith Watford
Moderator
9619
Keith Watford 2016.04.17 11:48  

You can try,

   ENUM_ORDER_TYPE type=OrderType();
   FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots()),EnumToString(type));
whroeder1
14489
whroeder1 2016.04.17 11:55  
 ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE) OrderType();
beh12zad
30
beh12zad 2016.04.17 12:43  
WHRoeder:

thanks a lot, very kind of you.

I have 5 opened Orders and 1 pending Order, but I got only the fifth opend order and nothing else:

this is CSV File:

#    open price    open time    symbol    lots

131631018    113.8    2016.03.04 10:40:51    USDJPY    0.01    ORDER_TYPE_SELL

this is my new code:

#property copyright "test"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
    int handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
  if(handle<0) return;
  // write header
  FileWrite(handle,"#","open price","open time","symbol","lots");
  int total=OrdersTotal();
  // write open orders
  for(int pos=0;pos<total;pos++)
 
     if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
    ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE) OrderType();
FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots(),EnumToString(type));



  FileClose(handle);
   if(OrderSelect(2, SELECT_BY_TICKET)==true)
    OrderPrint();
  else
    Print("OrderSelect failed error code is",GetLastError());
  }
//+------------------------------------------------------------------+
Keith Watford
Moderator
9619
Keith Watford 2016.04.17 13:07  
   for(int pos=0;pos<total;pos++)
     {
      if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
      ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE) OrderType();
      FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots(),EnumToString(type));
     }

   FileClose(handle);

you forgot the {} in the loop

beh12zad
30
beh12zad 2016.04.17 13:10  
GumRai:

you forgot the {} in the loop

thank you very much you helped me to undrestand better.
beh12zad
30
beh12zad 2016.05.03 10:05  
WHRoeder:

Hallo Sir,

I want to modify my code with OrderPrint(),  so that I get the output in my OrdersReport.csv and not in Expert Tab,

because I get all the Information, that I need in my OrdersReport.csv about my Orders with this code:

How can I do it?thanks in Advance.

 {
  int total=OrdersTotal();
  for (int i =0; i < OrdersTotal(); i++)
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        OrderPrint();

  }


whroeder1
14489
whroeder1 2016.05.03 11:47  
beh12zad: so that I get the output in my OrdersReport.csv and not in Expert Tab
You already know how.
beh12zad
30
beh12zad 2016.05.03 12:14  
WHRoeder:
beh12zad: so that I get the output in my OrdersReport.csv and not in Expert Tab
You already know how.
I am trying to undrestand the Coding and your Tip can help me.
12
To add comments, please log in or register