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

 
To work with RAM files you can use the following construction
const int handleRAM = FileOpen("\\\\.\\pipe\\RAM", FILE_READ | FILE_WRITE | FILE_BIN);

By creating an appropriate file in advance.

With this implementation it is convenient/fast, for example, to copy arrays of any size (and different) into each other - without raping HDD/SDD.

// Копирование массивов любых размерностей (и разных) друг в друга
#define ARRAYCOPY(Dest, Source) \
  if (ArraySize(Source) > 0)                                                                  \
  {                                                                                           \
    const int handleRAM = FileOpen("\\\\REN\\pipe\\RAM", FILE_READ | FILE_WRITE | FILE_BIN);  \
                                                                                              \
    if (handleRAM != INVALID_HANDLE)                                                          \
    {                                                                                         \
      if (FileWriteArray(handleRAM, Source) > 0)                                              \
        FileReadArray(handleRAM, Dest);                                                       \
                                                                                              \
      FileClose(handleRAM);                                                                   \
    }                                                                                         \
  }
It is a universal solution. The classic example of such copying looks like this
// Копирует двумерный массив в одномерный
#define MATRIX_TO_VECTOR(Matrix, Vector)      \
  if (ArraySize(Matrix) > 0)                  \
  {                                           \
    const int Range1 = ArrayRange(Matrix, 0); \
    const int Range2 = ArrayRange(Matrix, 1); \
                                              \
    ArrayResize(Vector, Range1 * Range2);     \
                                              \
    int k = 0;                                \
                                              \
    for (int i = 0; i < Range1; i++)          \
      for (int j = 0; j < Range2; j++)        \
      {                                       \
        Vector[k] = Matrix[i][j];             \
                                              \
        k++;                                  \
      }                                       \
  }

// Копирует одномерный массив в двумерный
#define VECTOR_TO_MATRIX(Vector, Matrix)                               \
  if (ArraySize(Vector) > 0)                                           \
  {                                                                    \
    const int Size = ArraySize(Vector);                                \
    const int Range = ArrayRange(Matrix, 1);                           \
                                                                       \
    ArrayResize(Matrix, Size / Range + ((Size % Range == 0) ? 0 : 1)); \
                                                                       \
    for (int i = 0; i < Size; i++)                                     \
      Matrix[i / Range][i % Range] = Vector[i];                        \
  }
Macros are used instead of functions, because it is impossible to pass a universally sized array to functions.
 
Dmitry Fedoseev:

The point is that OnTradeTransaction() is not triggered immediately after OrderSend.

In short, there's just a bunch of people who like to argue without getting into the subject of the argument.

There are two variants of the algorithm, if after OrderSend() something must be done immediately:

1. We can start a loop waiting for updates of the lists of orders and deals.

2. Finish OnTick() and wait for OnTradeTransaction() to take effect.

3. Check by tick to see if a new order or trade appears in the list.

Choice of 2 and 3)
 
What can replace the quadruple MODE_MARGINREQUIRED in mql5 ?
 
Artyom Trishkin:
How can I replace the quadruple MODE_MARGINREQUIRED in mql5?

This is something you need to ask the developers, because none of the forum members do not know. I asked this question 4 times in different threads, once even got the answer: "use the search", but the search has more than 100 questions, and there is not a single answer. The developer does not answer the question, probably because there is no way to get the margin for pairs other than the deposit currency .

All is still raw in Five and looks like it will stay this way, but there is an OpenGL for everybody =)

 
Artyom Trishkin:
What can replace quadruple MODE_MARGINREQUIRED in mql5?
OrderCalcMargin() try https://www.mql5.com/ru/docs/trading/ordercalcmargin
 
Andrey Barinov:
OrderCalcMargin() try

This is understandable, but it does not work with the indicator

  double One_Lot=0.0;
  OrderCalcMargin(ORDER_TYPE_BUY,Symbol(),1.0,SymbolInfoDouble(Symbol(),SYMBOL_ASK),One_Lot);
  Comment(One_Lot); // залог на 1 лот
 
Vitaly Muzichenko:

This is understandable, but it does not work with the indicator

  double One_Lot=0.0;
  OrderCalcMargin(ORDER_TYPE_BUY,Symbol(),1.0,SymbolInfoDouble(Symbol(),SYMBOL_ASK),One_Lot);
  Comment(One_Lot);
It is written directly in the help that it does not work from the indicator https://www.mql5.com/ru/docs/runtime/running
 
Andrey Barinov:
It is written directly in the help that does not work from the indicator https://www.mql5.com/ru/docs/runtime/running.
I would like a calculation that does not depend on the program type.
 
Artyom Trishkin:
I would like a calculation that does not depend on the type of program.
Ooh, I'd like a lot of things too :)
 
Andrey Barinov:
Ooh, I would also like a lot :)
Well... this is not an answer...
And this question is just on the topic of the branch.

Reason: