Features of the mql4 language, subtleties and techniques - page 10

 
Alexey Viktorov:

I cannot understand what the surprise is. There is an int value of the order type in the documentation.

OP_BUY

0

Buy

OP_SELL

1

Sell

OP_BUYLIMIT

2

BUY LIMIT pending order

OP_SELLLIMIT

3

Pending SELL LIMIT order

OP_BUYSTOP

4

Pending BUY STOP order

OP_SELLSTOP

5

Pending SELL STOP order


#define OP_BALANCE 6
#define OP_CREDIT 7

So, with an array of 6 cells, you can sometimes go overboard.

 

Forum on trading, automated trading systems and testing trading strategies

I want to move the EA comment from left to right corner ?

fxsaber, 2018.07.10 15:13

// Вывод комментария по примерным координатам
void CommentXY( string Str, const uint X = 0, const uint Y = 0 )
{
  string Shift = NULL;
  
  StringInit(Shift, X >> 2, ' ');
  
  if (StringLen(Shift))
  {
    StringReplace(Str, "\n", "\n" + Shift);
    
    Str = Shift + Str;
  }
  
  if (Y)
  {
    StringInit(Shift, Y / 14, '\n');
    
    Str = Shift + Str;
  }
  
  Comment(Str);  
}


Application

void OnStart()
{
  const uint Height = 200;
  const uint Width = 200;
  
  while (!IsStopped())
  {
    CommentXY("Hello World!\nCommentXY", MathRand() * Width / SHORT_MAX, MathRand() * Height / SHORT_MAX); // Вывод комментария со сдвигом (ноль - левый-верхний угол).
    
    Sleep(200);
  }
}
 
fxsaber:

Do you have an official response from the developers? So far I can only see that you have searched, thought about it and decided.

 
Artyom Trishkin:

Do you have an official response from the developers? So far I can only see that you have searched, thought and decided on your own.

My conclusion on the level of "self-sufficiency" is no better than this one at the beginning of this thread

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql4, tips and tricks

the order type and the price that corresponds to it. It is sufficient to write OrderClosePrice()


No need to suffer from nonsense/paranoia.

 
fxsaber:

My conclusion on the level of "self-reliance" is no greater than this one at the beginning of this thread


There is no need to suffer from nonsense/paranoia.

You must have missed the time when most of those not suffering from "paranoia" urgently rewrote their codes as EAs collapsed overnight. Because of the reliance on triage. It's a long time ago, but people still have memories. Those who got into trouble started to write sorting-independent codes. I didn't get into trouble - I just read about it on the forum and took it to heart.

 
Artyom Trishkin:

You must have missed the time when most of those not suffering from "paranoia" were urgently rewriting their codes as EAs collapsed overnight. Because of the reliance on triage. It's a long time ago, but people still have memories. Those who got into trouble started to write sorting-independent codes. I didn't get into trouble - I just read it on the forum and took it to heart.

Unfortunately, this myth finds no support in the history of the forum. Moreover, the developers have consistently made clear their position that such changes cannot be made as a matter of principle.


For example, you can feel free to write

if (OrderType() <= OP_SELL)
  ReverseType = 1 - OrderType();


instead of

if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
  ReverseType = (OrderType() == OP_BUY) ? OP_SELL : OP_BUY;


You may feel free to write

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql4 language, tips and tricks

fxsaber, 2018.04.03 16:15

double Lots[] = {0, 0, 0, 0, 0, 0, 0, 0};

for (int i = OrdersTotal() - 1; i >= 0; i--)
  if (OrderSelect(i, SELECT_BY_POS))
    Lots[OrderType()] += OrderLots();

etc.

 
fxsaber:

Unfortunately, this myth finds no support in the history of the forum. Moreover, the developers have consistently made clear their position that such changes cannot be made as a matter of principle.

For example, you can feel free to write as follows


Why all these pseudo-optimizations, the nuances of which we have to constantly keep in mind? Is it really so difficult to write code that does not depend on such assumptions (meaning of a named constant)? What is the point of such constructs at all, apart from showing some knowledge of the nuances of the compiler, but not at all that they are easier to understand?

 
Ihor Herasko:

Why all these pseudo-optimisations, the nuances of which have to be constantly kept in mind? Is it really so hard to write code that doesn't depend on such assumptions (what is the meaning of this or that named constant)? What is the point of such constructs anyway, apart from showing some knowledge of the nuances of the compiler, but not at all that they are easier to understand?

It's strange, I don't have any problems with reading such code. Moreover, its reading and understanding is faster than that of "canonical" code.

Well, the example above with Lots[] is a treasure showing how the code can be super-laconic and clear at the same time. And mind you, it's not "canonical" at all.

Probably, if you look at the source code of many Market/Freelance jobs, you won't just come across tatters of "canonical" code, but you'll also encounter terrible inefficiency of performance and no less important factor - code comprehension while reading.


The same inextinguishable love of continue is a total disrespect for the possibilities of the language. Code on 100 lines is much better perceived than code on 200 lines doing the same thing. This is the reason why people initially complained about MQL5. Look at the redesign of MT4 code in QB for MT5 - it is very difficult to understand the logic of TC (the code is many times larger). It's easier to go to the MT4 original and look at the code.

 
fxsaber:

Strangely, I have no problem with reading such code. Moreover, its reading and understanding is faster than that of "canonical" code.

In many software companies such code would get their fingers beaten off. The first thing you must always and everywhere is to avoid "unnecessary reading". For instance, if you use a condition when entering a function:

if (<условие>)
{
}

it is recommended to write:

if (!<условие>)
   return;

This approach really bails out the attachment of conditions.

Well, the example above with Lots[] is a real treasure trove, showing how code can be both super-laconic and totally understandable. And mind you, it's not at all "canonical".

Once again it's a pain in the ass. After all, nobody checked what the OrderType() function returned. Or maybe it returned -1 or 6? This is an example of laying upon compiler's properties which you should always stay away from. You yourself cite many examples of cross-platform code. So why are you moving away from it in this case? A new MQ compiler will come out and this code will no longer work correctly.

The same inextinguishable love of continue is a total disregard for the possibilities of the language. A 100-line code is much better comprehended than a 200-line code doing the same thing. This is the reason why people initially complained about MQL5. Look at the redesign of MT4 code in QB for MT5 - it is very difficult to understand the logic of TC (the code is many times larger). It's easier to go to the MT4 original and look at the code.

With continue it's the same situation. Code like:

if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == m_nMagicNumber)
{
}

is harder to read than:

if (!OrderSelect(i, SELECT_BY_POS))
   continue;

if (OrderSymbol() != Symbol())
   continue;

if (OrderMagicNumber() != m_nMagicNumber)
   continue;
And yet the efficiency of execution is the same in both cases.