made a 2 EMA cross EA, need advice - page 4

 
prupru:

I have a bigger problem now, my broker tends to partially execute orders.

Dear Customer,

Please be hereby advised that your trade has been opened partially (2.32 lots out of 15.84) at the price 587.318.

Should you have any additional questions on this issue, don’t hesitate to contact us.

Kind Regards,

Broker.

here is what support say:

Please be advised, during periods of high volatility or low liquidity, Limit Orders may be partially executed. This means that the position will get filled immediately fully or partially if the price is met. In you case your order was executed partially, that is why you have received notification letter.

I understand how to close all orders despite them being closed partially, I just have to do Close all Orders while OrdersTotal() > 0, but I don't know what to yet when orders open partially.

edit:

Just realized that I have to check proper Symbol and magicnumber orders, it is a bit more difficult

edit: here is the close all orders function that should close orders even with partial closure


//Close all my Orders
void CloseAllOrders()
{
int notMyOrders = 0;

 while (OrdersTotal()>notMyOrders)
 {
 notMyOrders = 0;
 for(int i = OrdersTotal()-1; i >= 0 ; i--)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
   if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) {notMyOrders++; continue;}
   if(OrderType()<= 1)CloseOrder();
         
   }
 }
return;
}  
rewritten
 
deVries:

rewritten


wow!

that's a little bit tricky for me, I have read through it like 4 or 5 times before I got it. Thanks!

and... what happens if OrderSelect returnes false?

How often does orderselect return false? Is it even possible?

 
prupru:


wow!

that's a little bit tricky for me, I have read through it like 4 or 5 times before I got it. Thanks!

and... what happens if OrderSelect returnes false?

How often does orderselect return false? Is it even possible?


for(int i = OrdersTotal()-1; i >= 0 ; i--)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;

i= 0

comes back from loop

i = -1

if(OrderSelect(-1,SELECT_BY_POS,MODE_TRADES)==false) break; // ==> end checking trades we break the loop

next CloseOrder()

//CloseOrder
void CloseOrder()
{double PR=0;
 while(!IsTradeAllowed()) Sleep(10);
 RefreshRates();
 if(OrderType()==OP_BUY)  PR=Bid;
 if(OrderType()==OP_SELL) PR=Ask;
 if(!OrderClose(OrderTicket(),OrderLots(),PR,Slippage,CLR_NONE))
  {
   Print("Close order error: ",GetLastError());
   Print("Type ", OrderType()," PR ",PR, " Ask ", Ask, " Bid ", Bid, " OrderTicket ", OrderTicket(), " OrderLots ", OrderLots());
  }
return;}
//--------------------------- end of close order

what commonerrors can be returned from GetLastError()

if closing fails it might next one is failing also for an error like tradecontext too busy or other error...

so what can you do avoiding a lot of this situations will happen ??

 
deVries:


so what can you do avoiding a lot of this situations will happen ??

don't know yet. I've got to think it over.

I am stuck with another problem right now.

I have put my EA on a windows 2003 VPS and now it is returning "terminated by timeout" error, but I have never seen such a error on my home PC.

And the error pops up not the time my while close and open order cycles running, but when the expert jush checks for crossing and go idle.

I mean, the program checks for new bar opening, trailingstop = 0 so no trailing stop function call, then if new bar opened it checks EMA cross, there is no cross (the times I got timeout errors the EMA lines were far from crossing), so the program returnes(0)

There is no cycles! How can it be terminated by timeout?

 
prupru:

don't know yet. I've got to think it over.

I am stuck with another problem right now.

I have put my EA on a windows 2003 VPS and now it is returning "terminated by timeout" error, but I have never seen such a error on my home PC.

And the error pops up not the time my while close and open order cycles running, but when the expert jush checks for crossing and go idle.

I mean, the program checks for new bar opening, trailingstop = 0 so no trailing stop function call, then if new bar opened it checks EMA cross, there is no cross (the times I got timeout errors the EMA lines were far from crossing), so the program returnes(0)

There is no cycles! How can it be terminated by timeout?


this is not a cycle ??

while(!IsTradeAllowed()) Sleep(10);
 
deVries:


this is not a cycle ??


I mean during the time when the EA was terminated EMA lines were far from crossing so a NewOrder function wasn't called, so the cycle you are talking about (which is inside the NewOrder function) wasn't run.

added IsStopped condition

while( (!IsTradeAllowed()) && (!IsStopped()) ) Sleep(10);
while ( (LotRemains>0) && (!IsStopped()) )
while ( (OrdersTotal()>0) && (!IsStopped()) ) 
 
maybe the timeout error pops out because I run out of VPS processor resources. I have switched to a more expencive plan and I am not seeing them until I run something heavy like windows uodate
Reason: