Download MetaTrader 5
To add comments, please log in or register
Download documentation as one file. It is easy!
bah12ram
76
bah12ram 2016.05.06 16:36 

how to put a function inside start() that detect when OrdersTotal() change.

Thanks in Advance.

Alain Verleyen
Moderator
30299
Alain Verleyen 2016.05.06 17:51  
bah12ram:

how to put a function inside start() that detect when OrdersTotal() change.

Thanks in Advance.

What have you tried ?
bah12ram
76
bah12ram 2016.05.07 11:13  
Alain Verleyen:
What have you tried ?

thanks. I want run it in an EA or indicator.

void OnStart()
  {
//---
    int handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
  if(handle<0) return;
  // write header
  FileWrite(handle,"Ticket","open price","open time");
  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());

FileClose(handle);
   if(OrderSelect(2, SELECT_BY_TICKET)==true)
    OrderPrint();
  else
    Print("OrderSelect failed error code is",GetLastError());
  }

Marco vd Heijden
Moderator
4507
Marco vd Heijden 2016.05.07 22:40  
bah12ram:

thanks. I want run it in an EA or indicator.

void OnStart()
  {
//---
    int handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
  if(handle<0) return;
  // write header
  FileWrite(handle,"Ticket","open price","open time");
  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());

FileClose(handle);
   if(OrderSelect(2, SELECT_BY_TICKET)==true)
    OrderPrint();
  else
    Print("OrderSelect failed error code is",GetLastError());
  }

int orders=OrdersTotal();

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(orders!=OrderTotal())
    {
     orders=OrdersTotal();
     Alert(orders); 
    }
  }
//+------------------------------------------------------------------+
bah12ram
76
bah12ram 2016.05.09 16:49  
Marco vd Heijden:

thanks Sir,

I can get the Alert immediately, but it is not detected in

void OnStart() section, so that it does not rewrite my OrdersReport.csv.

how can I fix it? I don't know how to put this function inside OnStart().

Trinh Dat
36695
Trinh Dat 2016.05.10 11:44  
int orders =-1;

void start()
  {
//---
  int handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
  if(handle<0) return;
  
  if(OrdersTotal()== orders) return;
  orders=OrdersTotal();
  
  // write header
  FileWrite(handle,"Ticket","open price","open time");
  int total=OrdersTotal();
  // write open orders
  for(int pos=0;pos<total;pos++)  {
     if(OrderSelect(pos,SELECT_BY_POS))
     FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime());
  }
  FileClose(handle);
  
  }
//+------------------------------------------------------------------+
/
To add comments, please log in or register