Questions from Beginners MQL5 MT5 MetaTrader 5 - page 477

 
#include <Trade/Trade.mqh>

void DeletePendingOrders(const string sSymbol, const ulong nMagic)
{
   CTrade oTrade;

   for(int i = OrdersTotal() - 1; i >= 0; i--)
   {
      ulong nOrderTicket = OrderGetTicket(i);
      
      if(nOrderTicket > 0)
      {
         if(OrderGetString(ORDER_SYMBOL) == sSymbol && OrderGetInteger(ORDER_MAGIC) == nMagic)
         {
            // удаляем только отложенники
            ENUM_ORDER_TYPE eType = (ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);
            
            if(eType == ORDER_TYPE_BUY_STOP  || eType == ORDER_TYPE_SELL_STOP ||
               eType == ORDER_TYPE_BUY_LIMIT || eType == ORDER_TYPE_SELL_LIMIT ||
               eType == ORDER_TYPE_BUY_STOP_LIMIT || eType == ORDER_TYPE_SELL_STOP_LIMIT)
            {
               oTrade.OrderDelete(nOrderTicket);
            }
         }
      }
   }
}

The script for MT4 will not work on Five, it has very different trading functions.

 
Sergei Vladimirov:

The script for MT4 will not work on Five, it has very different trading functions.

Thank you, I was just about to deal with trade.mqh.
 
Could you please tell me something? How can I find out programmatically, not logically, how a market order was closed - by TP, SL or by market?
 
-Aleks-:
Could you please tell me something? How can I know programmatically, not logically, how a market order was closed - by TP, SL or by market?
Compare the closing price with the TP, SL. If they almost coincide - the answer is there. If they do not coincide, the answer is also there
 
Victor Nikolaev:
Compare the closing price with TP, SL. If they almost match - the answer is there. If they don't coincide, then the answer is also there.

That's what I asked, how not by comparison? In the terminal the orders are tinted, it means they have a flag about how they were closed.

It's not quite clear to me how to arrange "almost" - slippage can be too much to compare.

 
-Aleks-:

That's what I asked, how not by comparison? In the terminal the orders are tinted, so they have a flag about how they were closed.

It's not quite clear to me how to organise "almost" - slippage can be too much for comparison.

With "almost" it is decided individually on a case by case basis. In a slow market it's one thing, in a fast market it's another
 
-Aleks-:
Could you please tell me something? How can I know programmatically, not logically, how a market order was closed - by TP, SL or by market?
The comment of the order closed by stoploss is attributed [sl], closed by takeprofit is attributed [tp].
 
Artyom Trishkin:
In the commentary of a closed on stoploss, attributed to [sl], closed on takeprofit, attributed to [tp].
Are you awake?
 
Victor Nikolaev:
Are you awake?
I was writing on my mobile phone... in my sleep... snoring... sniffling... purring...
 
Victor Nikolaev:
With "almost" is solved individually in each case in its own way. This is one thing in a slow market and another thing in a fast one.

Yeah, that's why I'm looking for a universal solution - if the information is needed on the next bar after the order has been closed, then it is not so difficult to evaluate the volatility, but if it is after a day, then I have to count the number of bars that have passed and the volatility that was there.

Artyom Trishkin:
In the comment of a closed by stoploss we attribute [sl], of a closed by takeprofit we attribute [tp].

Thanks - I will try to read it now!

And there is no such comment in the tester, right?

Reason: