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

 

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

Thanks in Advance.

 
bah12ram:

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

Thanks in Advance.

What have you tried ?
 
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());
  }

 
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); 
    }
  }
//+------------------------------------------------------------------+
 
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().

 
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);
  
  }
//+------------------------------------------------------------------+