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

 
Slava:

When you get a message about a memory leak, it means that there was no explicit command to free that memory.

When the program terminates (which is when you get these messages), it frees up all memory, including leaked memory, anyway.

I may have used the term 'leak' too loosely. The point is that a resource is left hanging in memory, whose name is not even recognisable if the object is deleted. And if you do know its name, you cannot delete it anywhere but from the program that created the resource.


Now it is very easy to write a script for Market which will suspend (not necessarily premeditated) the Terminal on VPS, filling up all memory with resources which are not deleted after script execution.

 

Some trading servers can hold more than one type of account at a time. For example, ECN and standard. In this case symbols may have no prefixes, i.e. the names are the same.

In this case, the bar history (including the current value of bid/ask/last on the chart) and tick history always correspond with only one account type.

And the Market Watch data corresponds to the one that is connected to.


Because of this, it is easy to observe that the Market Watch is completely inconsistent with the charts and tick history.

 

Several times I have encountered an accidental (manual) change of the chart symbol where a combat councillor stands.

Protection against symbol change.

int OnInit()
{
  static const string Symb = _Symbol;  
  const bool Res = (_Symbol != Symb);
  
  if (Res)
    Alert("Symbol is change!");
  
  return(Res); // Защита от смены символа.
}
 
When starting an EA, you often need to decide on the time from which the price history should be obtained. To avoid having to enter it manually every time, I did it this way.
#define  WEEK (7 * 24 * 3600)
input datetime temp = __DATE__ - WEEK;

Accordingly, I take the story a week before compilation. It's convenient.

 
fxsaber:
When starting an EA, you often need to decide on the time from which the price history should be obtained. To avoid having to enter it manually every time, I did it this way.

Accordingly, I take the story a week before compilation. Convenient.

Why should you rely too much on the optimizer? It's better:

#define WEEK 604800

 

Emergency interrupt function, seems to work fine

#define  EXIT (STD_CExit(__LINE__,__FUNCTION__)).Exit

class STD_CExit{
   string function;
   int line;
public:
   STD_CExit(int _line,string _func):line(_line),function(_func){}
   void Exit(string reason=NULL);
};
//--------------------------------------------------------------------------
void STD_CExit::Exit(string reason=NULL){
   Alert(StringFormat("Abort in line %i, function %s.\nReason: %s.",line,function,reason==NULL||reason==""?"Unknow":reason));
   int a=0;
   int b=1/a;}

void OnStart()
{
   Test();
}

void Test(){
   EXIT("Some reason");
}
 
Vladimir Simakov:

Emergency interrupt function, seems to be working out fine

it's the right thing to do - I was happy to see it happen... we solved this problem with@Victhttps://www.mql5.com/ru/forum/318246/page10#comment_12651569

but this:

- notExit http://www.delphibasics.ru/Exit.php

- notAbort http://www.delphibasics.ru/Abort.php

it'sHalt http://www.delphibasics.ru/Halt.php

UPD: such a script is badly needed

void OnTick()
{
   if(!getData()) EXIT("No data");
}
bool getData()
{
   return(false);
}
 
Igor Makanu:

the thing is needed - I was happy to see it happen..., here is the problem we solved with@Victhttps://www.mql5.com/ru/forum/318246/page10#comment_12651569

but this:

- notExit http://www.delphibasics.ru/Exit.php

- notAbort http://www.delphibasics.ru/Abort.php

it'sHalt http://www.delphibasics.ru/Halt.php

UPD: such a script is badly needed

There's no way that's working out yet(((
 
Vladimir Simakov:
This one has not worked out yet(((.

i.e., it is exactly what i need!

If developers had given exit / abort as standard, then it would be possible to correctly terminate data processing, if, for example, TF is not ready - OHLC data, it would also be useful for processing order sending to server... it would be convenient to interrupt the code at any place and exit before the next tick without endless return() to exit from OnTick()

 
Igor Makanu:

i can't see why i need it!

If developers had given exit / abort as standard, then it would be possible to correctly terminate data processing, if, for example, TF is not ready - OHLC data, it would also be useful for processing order sending to server... it would be convenient to interrupt the code at any place and exit before the next tick without endless return() to exit from OnTick()

Well, couldn't, not yet...

Reason: