break or stop when open trades

 

hello

can i get some help about the code to stop expert from open new trades if there is open trades 

thank you

 

Hi

Check OrdersTotal() and don't look to place a trade if >0. If you have pending orders you will have to filter those out.

 

thanks for replay Ruptor

i used this code 

       
 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());
    }
  FileClose(handle);
and nothing happen, should i change any text in it??
 

Hi

The code you posted writes to a file it doesn't place orders. It won't write to the file if there are no oirders so that looks ok if that's what you want.

 

i think that i need another,

my problem is any expert i write for example it open orders by candle close, every candle the expert will open an order, i want to prevent the expert to open more than the first order

i wish that i can find the solution

thank you again

 

Hi

Use this


if(TotalOrders()==0){


Place decsion to trade here -----


}

 

Hi Ruptor

it works, thank you 

can we improve this code to work for each symbol and for daily ? for example : open one order only for each pair, open one order per day

thank you very much

 
Ruptor:

Hi

The code you posted writes to a file it doesn't place orders. It won't write to the file if there are no oirders so that looks ok if that's what you want.


Hi Ruptor,


Thanks for your codes, it's working well.


-

Manoj

Reason: