Write orders in csv file

 
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);

  }

 
I have moved this post from a reply to an unrelated and old thread
 
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.

 

You can try,

   ENUM_ORDER_TYPE type=OrderType();
   FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots()),EnumToString(type));
 
 ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE) OrderType();
 
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());
  }
//+------------------------------------------------------------------+
 
   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

 
GumRai:

you forgot the {} in the loop

thank you very much you helped me to undrestand better.
 
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();

  }


 
beh12zad: so that I get the output in my OrdersReport.csv and not in Expert Tab
You already know how.
 
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.