Features of the mql5 language, subtleties and tricks - page 155

 
Nikolai Semko:

Found an interesting study from two years ago comparing the effectiveness of different languages

https://greenlab.di.uminho.pt/wp-content/uploads/2017/09/paperSLE.pdf



Oh my!

Is Ada really alive and growing! If I'm not mistaken, the first OOP. I studied it in the early 80's. Haven't heard anything about it until now, thought the language was as dead as Modula. Both are deep upgrades of Pascal. I didn't have an Ada compiler, and I had Modula - a seven-pass on DWK, if anyone remembers.

 

To avoid execution errors in the tester, send appropriate market orders in case a pending or SL/TP should be placed atthe current price:

  • Place a pending order at the current price - add it after the OrderSend market order.
  • Place SL/TP position at the current price - add after OrderClose position.
 
fxsaber:

To avoid execution errors in the tester, send appropriate market orders in case a pending order or SL/TP should be placed at the current price:

  • Place a pending order at the current price - add it after the OrderSend market order.
  • Place SL/TP position at the current price - add it after OrderClose position.

Can we discuss this in more detail? It's not very clear:

  • to place a pending order at the current price, something must be added after sending a request to open a position (?????????)
  • to place a stop order (to what?) at the current price, something must be added after sending a request to close a position (?????????)
These are the questions that come up after trying to decipher what you have written ...
 
Artyom Trishkin:

Could you be more specific? It's not really clear:

  • to place a pending order at the current price, something must be added after sending a request to open a position (?????????)
  • to place a stop order (to what?) at the current price, something must be added after sending a request to close a position (?????????)
Such questions appear after trying to decipher what you have written ...

The problem is shown here. Solution.

// Делает более точными MT4/5-тестеры.
TICKET_TYPE MyOrderSend( const string Symb, int Type, const double dVolume, const double Price, const int SlipPage, const double SL, const double TP,
                         const string comment = NULL, const MAGIC_TYPE magic = 0, const datetime dExpiration = 0, color arrow_color = clrNONE )
{
  static const bool IsTester = MQLInfoInteger(MQL_TESTER);
  MqlTick Tick = {0};  
  
  bool Res = IsTester && SymbolInfoTick(Symb, Tick);
  
  if (Res && (Type > OP_SELL))
  {
    if ((Type == OP_BUYLIMIT) || (Type == OP_BUYSTOP))
    {
      if (Price == Tick.ask)
        Type = OP_BUY;
    }
    else if (Price == Tick.bid)
      Type = OP_SELL;
  }
  
  const TICKET_TYPE Ticket = OrderSend(Symb, Type, dVolume, Price, SlipPage, SL, TP, comment, magic, dExpiration, arrow_color);
  
  Res = Res && (Type <= OP_SELL) && (Ticket != -1) &&
        (Type ? (SL == Tick.ask) || (TP == Tick.ask) : (SL == Tick.bid) || (TP == Tick.bid)) &&
        OrderClose(Ticket, dVolume, Type ? Tick.ask : Tick.bid, SlipPage, arrow_color);
  
  return(Ticket);
}

// Делает более точными MT4/5-тестеры.
bool MyOrderModify( const long Ticket, const double Price, const double SL, const double TP, const datetime Expiration, const color Arrow_Color = clrNONE )
{
  static const bool IsTester = MQLInfoInteger(MQL_TESTER);
  
  bool Res = false;
  
  if (IsTester && OrderSelect(Ticket, SELECT_BY_TICKET) && !OrderCloseTime())
  {
    if (OrderType() <= OP_SELL)
    {
      Res = (OrderClosePrice() == SL) || (OrderClosePrice() == TP);
      Res = OrderModify(Ticket, Price, SL, TP, Expiration, Arrow_Color) && (!Res || OrderClose(Ticket, OrderLots(), OrderClosePrice(), 0, Arrow_Color));
    }
    else if (OrderClosePrice())    
      Res = ((OrderClosePrice() == Price) &&
             (MyOrderSend(OrderSymbol(), OrderType() & 1, OrderLots(), Price, 0, SL, TP,
                          OrderComment(), OrderMagicNumber(), OrderExpiration(), Arrow_Color) != -1) && OrderDelete(Ticket)) ||
            OrderModify(Ticket, Price, SL, TP, Expiration, Arrow_Color);
    else
    {
      MqlTick Tick = {0};
      
      if (SymbolInfoTick(OrderSymbol(), Tick))
        Res = (((bool)(OrderType() & 1) ? (Price == Tick.bid) : (Price == Tick.ask)) &&
               (MyOrderSend(OrderSymbol(), OrderType() & 1, OrderLots(), Price, 0, SL, TP,
                            OrderComment(), OrderMagicNumber(), OrderExpiration(), Arrow_Color) != -1) && OrderDelete(Ticket)) ||
               OrderModify(Ticket, Price, SL, TP, Expiration, Arrow_Color);
      else
        Res = OrderModify(Ticket, Price, SL, TP, Expiration, Arrow_Color);                     
    }
  }
  else
    Res = OrderModify(Ticket, Price, SL, TP, Expiration, Arrow_Color); 
  
  return(Res);
}

#define OrderSend MyOrderSend
#define  OrderModify MyOrderModify
 
fxsaber:

The problem is shown here. Solution.

This doesn't make it any clearer what it's for or what to do. After all, many people need to understand what is written about the reason for writing a solution before they start reading the code to make their own or use a ready-made one.

I asked for a more detailed explanation of this:

The forum on trading, automated trading systems and testing of trading strategies

Features of mql5 language, intricacies and techniques

fxsaber, 2019.12.18 12:45

To avoid execution errors in the Tester, send appropriate market orders in case you need to place a pending or SL/TP at the current price:

  • Place a pending order at the current price - add after OrderSend market order.
  • Place SL/TP position at the current price - add it after OrderClose position.

And showed an example of how it is perceived by me, or maybe by someone else:

Forum on trading, automated trading systems and strategy testing

Peculiarities of mql5, tips and tricks

Artyom Trishkin, 2019.12.18 12:53 pm

Is it possible to explain it in more details? I do not understand anything:

  • to place a pending order at the current price, you need to add something after sending a request to open a position (?????????)
  • to place a stop order (to what?) at the current price, something must be added after sending a request to close a position (?????????)
These are the questions that appear after trying to decipher what you've written ...

Anyway...

 
Artyom Trishkin:

I asked you to be more specific

Placing a pending order and SL/TP at the current price does not accept execution on the current tick in the MT5-Tester.

 

Hi all.

Can you advise pls what tools are available in MT5 to display tick charts ?

In MT4 there was an option "open offline". It was convenient to work with ticks by creating my own hst-files of history.

In MT5 there is no "open stand-alone" option. But the software tools to work with ticks are excellent.

It cannot be impossible that there is no possibility to show them on a chart

 
fxsaber:

The problem is shown here. Solution.

  const TICKET_TYPE Ticket = OrderSend();
  ...
  OrderClose(Ticket, dVolume, Type ? Tick.ask : Tick.bid, SlipPage, arrow_color);

What a load of crap! Why open with SL/TP at the current price?

Well, closing by placing SL/TP at the current price, if at all, is done intentionally. There is no need to emulate a trigger either.

 
Andrey Khatimlianskii:

What a load of crap! Why open with SL/TP at the current price?

Well, closing by placing SL/TP at the current price, if anything, is done intentionally. There is also no need to emulate triggering.

That way you can easily get a trigger in tens of minutes or hours.

Imagine that you need to close by TP that is somehow calculated. And now it is equal to the current price.

 
fxsaber:

need to close at the TP, which is somehow calculated. And now it has become equal to the current price.

In this case, I always check whether this TP should not have already triggered (the price has crossed it), and close according to the market.

Or, if it is necessary to exit with a limit, I pull it behind the price, until it fills.

Reason: