Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1374

 
Alexey Viktorov #:

Somebody taught you badly. The _LastError variable will store the value until the next error occurs.


Well, look, at the beginning of the main code the following error occurs

ERR_INVALID_DATETIME

4010

Incorrect date and/or time value


And then an object is created by the code and _LastError is rewritten to

ERR_OBJECT_NOT_FOUND

4202

Graphic object not found


If the _LastError check is at the end of the code, as I usually do, I will get 4202 and just ignore it. That is, error 4010 will remain unnoticed. Where am I wrong?

Alexey Viktorov #:


It is a requirement of the marketplace that no execution errors are received from the broker's server\dc.

Thanks, didn't know that, thought all errors were forbidden.

 
leon_17 #:

Well, look, at the beginning of the main code, for example, the following error occurs:

ERR_INVALID_DATETIME

4010

Incorrect date and/or time value


And then an object is created by the code and _LastError is rewritten to

ERR_OBJECT_NOT_FOUND

4202

Graphic object not found


If the _LastError check is at the end of the code, as I usually do, I will get 4202 and just ignore it. That is, error 4010 will remain unnoticed. Where am I going wrong?

Thanks, didn't know that, thought all errors are forbidden.

Exactly. You're not wrong...

 

Hello, can anyone give me a hint.

I'm writing the time values of each bar specifically into an array. There is a limit of 3000 bars on the chart.

The task:

- To shift the array of values at each new bar.

void CNewBar::PriceHL2()
  {
   int start= 0;
   ArrayResize(this.m_tim_pr_hl2,this.m_rt);
  
   if(this.m_pc!=0)
     {
      start= this.m_pc;
      ArrayCopy(this.m_tim_pr_hl2, this.m_tim_pr_hl2, 0, this.m_rt-this.m_pc);
     }  
   for(int b= start; b < this.m_rt; b++)
     {
      this.m_tim_pr_hl2[b]= iTime(this.m_symbol, this.m_timeframe, this.m_rt-b);
     }
  }

I cannot adjust it to work properly.

Am I correctly shifting the array on a new bar if (this.m_rt-this.m_pc)=1?

ArrayCopy(this.m_tim_pr_hl2, this.m_tim_pr_hl2, 0, this.m_rt-this.m_pc); // this.m_rt-this.m_pc=1
 
Mikhail Toptunov #:

Hello, can anyone give me a hint.

I'm writing the time values of each bar specifically into an array. There is a limit of 3000 bars on the chart.

The task:

- To shift the array of values at each new bar.

I cannot adjust it to work properly.

Am I right to shift the array on a new bar if (this.m_rt-this.m_pc)=1?

I.e. the size of array must be exactly 3000 and at formation of a new bar the zero index should be overwritten first ......... and in the end write new value?

If I understood correctly, what's the point of the loop? Just copy the array itself into the null index starting from the first one, and then write the new value into the last index.

 
Alexey Viktorov #:

If no object is found, this is the object search error...

ERR_OBJECT_NOT_FOUND

4202

Graphic object not found


No need to alerter it...

Did a couple of tests... Here's what happens. In MQL5, it is not necessary to use ObjectFind() when creating objects.
The object may be created without any preliminary check of its existence (just using ObjectCreate). Even inside the OnTick such code will not cause any _LastError errors.

I do not know how it is implemented in the depths of MQL5 system code, perhaps there is some check already uploaded there that the object will be created only if it is not yet present. But it turns out that at least when creating an object inside MQL5, ObjectFind() is not needed. And all its properties are invariably updated at every tick.

This cannot be said about MQL4. The creation of an object over an existing one will cause a 4200 ("The object already exists")error. It means that the use ofObjectFind() is obligatory for its creation.This leaves me with a simple possibility to close its properties from constant updates without generating _LastError errors.

Please confirm my conclusions.

 
Alexey Viktorov #:

I.e. the size of the array should be exactly 3000 and when a new bar is formed, the zero index should be overwritten first ......... and the new value should be added to the end?

If I understood correctly, why do I need a loop? Simply, the array itself should be copied into the null index starting from the first one, and then the new value should be appended to the last index.

Well, yes, it's clear, but if there is a break, for example, a delay, two bars appeared, I'm writing them down.

Thanks a lot, I understand, I will try through CopyTime.

 
leon_17 #:

Did a couple of tests... Here's what happens. In MQL5, it is not necessary to use ObjectFind() when creating objects.
The object can be created without any preliminary check of its existence (just using ObjectCreate). Even inside the OnTick code this code will not cause any _LastError errors.

I do not know how it is implemented in the depths of MQL5 system code, perhaps there is some check already uploaded there that the object will be created only if it is not yet present. But it turns out that at least when creating an object inside MQL5, ObjectFind() is not needed. And all its properties are invariably updated at every tick.

This cannot be said about MQL4. The creation of an object over an existing one will cause a 4200 ("The object already exists")error. It means that the use ofObjectFind() is obligatory for its creation.This leaves me with a simple possibility to close its properties from constant updates without generating _LastError errors.

Please confirm my conclusions.

It is not about errors at all. The point is that when an object is created, certain properties are assigned to it and why waste machine time and resources on redefining properties without making changes. It's much cheaper to check if the object exists and then assign new properties only to those that need to be changed. For example a text label or Lable, often only text in these objects should be changed. All other properties remain as they are...
 
Mikhail Toptunov #:

Well yes it seems clear, but if there is a break, e.g. delay, two bars appeared, I write them down.

Thank you, I understand, I'll try through CopyTime.

Well, if you do it via CopyTime, there's no problem at all. Just copy from the current 3000 bars and that's it.

 

How do I set the level of the regular trailing stop in the program code when placing a pending order or opening a position from the market?

How this is done manually is clear. Programs for non-standard trailing stops are not interesting.

Thank you in advance.

 
   for (int symbols; symbols < SymbolsTotal(true); symbols++) 
      {
        Print(SymbolName(symbols ,true));
      }

Why doesn't such a design work? Where is the error... (the log is empty)


And the log is empty.

enum c_mode
  {
   Auto,
   Manual,    
  };

input c_mode MODE         = Auto;

if (MODE==Auto) 
      {
      Print("MODE=Auto");
      } 
Reason: