Write orders in csv file

Back to topics list To post a new topic, please log in or register
avatar
Moderator
3418
GumRai 2016.04.17 10: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);

  }


avatar
Moderator
3418
GumRai 2016.04.17 10:09 #
 
I have moved this post from a reply to an unrelated and old thread
avatar
6
beh12zad 2016.04.17 13: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.


avatar
Moderator
3418
GumRai 2016.04.17 13:48 #
 

You can try,

   ENUM_ORDER_TYPE type=OrderType();
   FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots()),EnumToString(type));
avatar
13000
WHRoeder 2016.04.17 13:55 #
 
 ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE) OrderType();

avatar
6
beh12zad 2016.04.17 14: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());
  }
//+------------------------------------------------------------------+



avatar
Moderator
3418
GumRai 2016.04.17 15: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

avatar
6
beh12zad 2016.04.17 15:10 #
 
GumRai:

you forgot the {} in the loop

thank you very much you helped me to undrestand better.
avatar
6
beh12zad 2016.05.03 12: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();

  }


avatar
13000
WHRoeder 2016.05.03 13:47 #
 
beh12zad: so that I get the output in my OrdersReport.csv and not in Expert Tab
You already know how.
avatar
6
beh12zad 2016.05.03 14: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.
Back to topics list  

To add comments, please log in or register