Which design is correct? - page 6

 
valenok2003:
In the while code, only to delay while the thread is busy.

Then you need to refresh rates: RefreshRates(). Otherwise you will use old asc and bid values. Or ask for asc\bid by MarketInfo.
 
VladislavVG:

Then you need to refresh rates: RefreshRates(). Otherwise you will use old Ask and Bid values. Or ask on MarketInfo.

So that's where the dog is at work.

This design worked:

//+------------------------------------------------------------------+
//|                                           CloseThisSymbolAll.mq4 |
//+------------------------------------------------------------------+
int start()
{
//----
  for (int trade = OrdersTotal()-1; trade >= 0; trade--) 
  {
    OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
    if (OrderSymbol() == Symbol()) 
    { 
      while (!IsTradeAllowed()) Sleep(1000);
      RefreshRates();
      if(OrderType() == OP_BUY ) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid,Digits), 5, CLR_NONE);
      if(OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask,Digits), 5, CLR_NONE);
    }
  }
//----
   return(0);
}
//+------------------------------------------------------------------+

At least it worked right the first time.

Thank you!

 
VladislavVG:

Then you need to refresh rates: RefreshRates(). Otherwise you will use old asc and bid values. Or ask for asc\bid on MarketInfo.

Thank you!

I'll fix it in my EA as well.

 
valenok2003:



So that's where the dog is at.

This is the design that makes it work.

At least it worked right the first time.


Almost - one more condition needs to be corrected :


  for (int trade = OrdersTotal()-1; trade >= 0; trade--) 
  {
    if(!OrderSelect(trade, SELECT_BY_POS, MODE_TRADES)) break;
    ...........................
If the order did not get out, there is nothing to do.

Good luck with that.

 
VladislavVG:


Almost - one more condition needs to be corrected :

If the warrant does not get out, there is nothing to do.

Yes, that makes sense. This is an oversight from the loop
while(OrdersTotal()>0)
 
valenok2003:
five
There you had slippage = 5, and that's not enough for five-digit quotes.
 

So in summary:


//+------------------------------------------------------------------+
//|                                           CloseThisSymbolAll.mq4 |
//+------------------------------------------------------------------+
int start()
{
//----
  for (int trade = OrdersTotal()-1; trade >= 0; trade--) 
  {
    if(!OrderSelect(trade, SELECT_BY_POS, MODE_TRADES)) break;
    if (OrderSymbol() == Symbol()) 
    { 
      while (!IsTradeAllowed()) Sleep(1000);
      RefreshRates();
      if(OrderType() == OP_BUY ) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid,Digits), slippage, CLR_NONE);
      if(OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask,Digits), slippage, CLR_NONE);
    }
  }
//----
   return(0);
}
//+------------------------------------------------------------------+

or will there be any other comments?

 
khorosh:
There you had slippage = 5, and that's not enough for five-digit quotes.
In a relatively calm market, 5 is quite enough IMHO.
 
At one time, the codebase published its own set to close different types.
Files:
 
https://www.mql5.com/ru/code/mt4
Reason: