The great and terrible MT4 forever (or how to strategise a transition) - page 18

 
PapaYozh:
No.
The result is not guaranteed.

If there are enough pennies, it is guaranteed

 
fxsaber:

I need to write a script on an MT5 that opens 100 positions on an empty account.


On MT4 solved it this way.


Who has a solution on MT5?

Is partial performance possible?
 
SanAlex:

If there are enough pennies, it's guaranteed.

You have not accounted for partial performance, and when you do, you will also have to account for double-counting

 
Alexey Viktorov:
Is partial execution possible?

Let's assume there is no partial execution. However, while the script is running, someone may accidentally click on the cross in the position table, closing one/few of the positions. However, there should still be exactly 100 positions at the end of the script execution.


The MT4 version is insanely simple. That's why I wrote in this thread.

 
fxsaber:

Who has a solution on MT5?

There is no way without a synchroniser.

There could be elementary requotes or loss of connectivity in the process, 100 ordersands will not always yield 100 trades.

 
Andrey Khatimlianskii:

There is no way without a synchroniser.

There may be elementary requotes or loss of communication in the process, 100 ordersands will not always result in 100 trades.

The synchronizer will only ensure that the PositionsTotal and OrdersTotal values do not lie. It is precisely because they lie in time that we get the double counts.

In principle, the synchronizer is a single line. And if you don't look into its mechanism, the implementation is simple.


However, even with the synchronizer, everything is extremely complicated. You may use such a condition:

while (OrdersTotal() + PositionsTotal < 100)

However, this condition will be a total bummer if someone does the following.

fxsaber:

Let's assume that there is no partial execution. However, while the script is running, someone may accidentally click on a cross in the position table, closing one or more of them. However, at the end of the script execution there should still be exactly 100 positions.


I.e. an elementary task, which is solved in two lines in MT4, is not easily solved in MT5. That is why MT4-style+Synchronizer rules in MT5. Because of this I do not quite understand how other EAs can be written in MT5, of which there are so many in the Market.

 
fxsaber:

The synchroniser will only ensure that the PositionsTotal and OrdersTotal values do not lie. It is precisely because they are temporarily false that they result in double entries.

In principle, the synchronizer is a single line. And if you don't look into its mechanism, the implementation is simple.


However, even with the synchronizer, everything is extremely complicated. You may use such a condition:

However, this condition will be a total bummer if someone does the following.


I.e., an elementary problem, which is solved in two lines in MT4, is not easily solved in MT5. That is why MT4-style+Synchronizer rules in MT5. Because of this I do not understand how other EAs can be written in MT5, of which there are so many in the Market.

In MT5 everything is solved in the same way as in MT4 and is often much easier, because the language and API are much richer. More precisely, the languages are almost the same, here Metacquotes has done a great job for compatibility, but the APIs are quite different. Renat (director of Metakvotes) once said on forums that MT4 is dead and will not be developed. But apparently commercial interests were more important and nevertheless updates are coming out. But mostly they are fixes of bugs and new features of MKL 5. So the developers well done, I take off my hat, which I do not.))

And in general, I do not understand the moans of some comrades, as difficult to switch to MKL5. There are no complications, well another API, so there are detailed sources, I prefer to learn from them. Who don't have enough knowledge yet, welcome to help, it's brief but clear. In any case fifth is faster than fourth at least 10 times, and in optimization mode in general uses all cores of CPU you allowed and with modern videocard beats fourth in hundreds of times. So no need to write sad songs. ))

 
Andrei Trukhanovich:

you haven't taken partial performance into account, and when you do, you have to take into account the overrun as well

and that's not right either? - Although I don't understand what anyone wants from this function - but it does its job 100 per cent!!!

//+------------------------------------------------------------------+
//|                                                    maxLimits.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property script_show_inputs
#include <Trade\Trade.mqh>
//---
CTrade m_trade; // trading object
//---
sinput uint   maxLimits = 3;    // Кол-во Позиции Открыть в одну сторону
sinput double InpLots   = 0.01; // Lots
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   const string symbol=NULL;
   double price=0.0;
   const double sl=0.0;
   const double tp=0.0;
   const string comment="";
//--- check symbol
   string symbol_name=(symbol==NULL) ? Symbol() : symbol;
//--- check price
   if(price==0.0)
      price=SymbolInfoDouble(symbol_name,SYMBOL_ASK);
//---
   for(uint i=0; i<maxLimits; i++)
     {
      //--- open position
      if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,InpLots,price,sl,tp))
         printf("Position by %s to be opened",Symbol());
      else
        {
         printf("Error opening BUY position by %s : '%s'",Symbol(),m_trade.ResultComment());
         printf("Open parameters : price=%f,SL=%f,TP=%f",price,sl,tp);
        }
     }
  }
//+------------------------------------------------------------------+
//---
   for(uint i=0; i<maxLimits; i++)
     {
      //--- open position
      if(m_trade.Buy(InpLots,symbol_name,price,sl,tp,comment))
      //if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,InpLots,price,sl,tp))
         printf("Position by %s to be opened",Symbol());
      else
        {
         printf("Error opening BUY position by %s : '%s'",Symbol(),m_trade.ResultComment());
         printf("Open parameters : price=%f,SL=%f,TP=%f",price,sl,tp);
        }
     }
 
fxsaber:

Let's assume there is no partial execution. However, while the script is running, someone may accidentally click on the cross in the position table, closing one/few of the positions. However, there should still be exactly 100 positions at the end of the script execution.


The MT4 version is insanely simple. That is why I wrote in this thread.

So, for MQL5 you set such conditions that someone can play around, while for MQL4 you do not? What if I connect to the account from another computer and place a couple of pips... what will MQL4 open?

Do you want to mess up without any checks? Are you advocating permissiveness in programming, or are you just trying to slander MQL5 for someone`s selfish interests?

Write the same in mql4 with checks and foolproof.

 
Alexey Viktorov:

So for MQL5 you set such conditions that someone can mess around, but not for MQL4? What if I connect to my account from another computer and place a couple of pips... what will MQL4 open?

The terms and conditions of MT4 and MT5 are the same.

Do you want to mess up without doing any checks? Are you advocating permissiveness in programming, or are you just trying to derogate MQL5 for someone's selfish interests?

If you do not know how to do that, you will have to show the same problems with mql4 with checks and foolproof tools.

I do everything on MT5 only. I'm just saying that MT5 is not more complicated than MT4. It's MUCH more complicated than that! Only this week there is a solution of position reversal, and it's not 100% working.

For so many years everyone knew about the backtesting, coming to... Sleep. Because it's VERY complicated. Many peculiarities of trading API, that were brought up on forum, developers are not aware of, or didn't give their comments.


No one is criticizing MT5. I have shown by examples some problems in solving elementary problems.